yaffs Working on timothy_tests and have updated yaffs_importer.py
[yaffs2.git] / direct / python / yaffs_importer.py
index dc72785cd46a4670ec7a4542921647bf473e9d48..84760a6b4a0e844a0e1c90d5961a05efdb51a123 100644 (file)
@@ -4,11 +4,11 @@ import sys
 import ctypes
 
 
-#dir_in_snapshot=[]
-#files_in_snapshot=[]
-#symlinks_in_snapshot=[]
-#unknown_in_snapshot=[]
-#is_mount_in_snapshot=[]
+dir_in_snapshot=[]
+files_in_snapshot=[]
+symlinks_in_snapshot=[]
+unknown_in_snapshot=[]
+is_mount_in_snapshot=[]
 def check_for_yaffs_errors(output):
     if output<0:
         ##error has happened
@@ -18,7 +18,7 @@ def check_for_yaffs_errors(output):
         debug_message(("error code", error),  0)
 
 def debug_message(message, debug_level):
-    """notew that debug level 0 will always be printed"""
+    """note: that debug level 0 will always be printed unless debug_level is set to -1"""
     """level 0 error messages"""
     """level 1 basic tasks are shown(creating, deleating,ect)"""
     """level 2 all process are shown"""
@@ -98,10 +98,10 @@ def create_file(file):
     
     
     length_of_file=len(data_to_be_written)
-    debug_message (("length of data to be written",length_of_file), 2
+    debug_message (("length of data to be written",length_of_file), 3
     output=yaffs_write(current_handle,data_to_be_written , length_of_file)
     if output>=0:
-        debug_message(( "writing file:", output), 2)
+        debug_message(( "writing to ", file_path," ",  output), 1)
     else :
         debug_message(( "error writing file:", output), 0)
         check_for_yaffs_errors(output)
@@ -133,25 +133,31 @@ def create_dir(dir, scanned_path, yaffs_path):
     debug_message( ("creating dir:", absolute_dir_path), 2)
     debug_message (("mode(in octal", oct(dir["mode"])), 2)
 
-
-    ##if there is already a dir in yaffs then remove the dir . this is to clean the yaffs folder if it already exists.
-    if yaffs_access(absolute_dir_path, 0)==0:##the 0 means does it exist. 
-        debug_message ("folder already exists in yaffs", 2)
-        output=yaffs_unlink(absolute_dir_path)
-        debug_message(("unlinking", absolute_dir_path, output), 2)
-        check_for_yaffs_errors(output)
-        
-    ##shis is a bug in yaffs which will not make a dir if there is a slash on the end
+       ##this is a bug in yaffs which will not make a dir if there is a slash on the end
     if absolute_dir_path[len(absolute_dir_path)-1]=="/":
         absolute_dir_path=absolute_dir_path[0:len(absolute_dir_path)-1]
         debug_message (("path has slash on the end. removing slash new path is:",absolute_dir_path) , 4)
         
+        
+    ##if there is already a dir in yaffs then remove the dir . this is to clean the yaffs folder if it already exists.
+    ##in yaffs all of the files in the dir to be removed must be empty.
+    ##need to create a reverse ls to delete all of the files first.
+#    if yaffs_access(absolute_dir_path, 0)==0:##the 0 means does it exist. 
+#        debug_message ("folder already exists in yaffs", 2)
+#        output=yaffs_rmdir(absolute_dir_path)
+#        debug_message(("unlinking", absolute_dir_path, output), 2)
+#        check_for_yaffs_errors(output)
+        
+        
     output=yaffs_mkdir(absolute_dir_path, dir["mode"] )
     if output>=0:
-        debug_message(( "creating dir:", output), 2)
+        debug_message(( "created dir:", absolute_dir_path," ", output), 1)
     else :
-        debug_message(( "error creating dir:", output), 0)
+        debug_message(( "error creating dir ", absolute_dir_path, " ", output), 0)
         check_for_yaffs_errors(output)
+        if output==17:
+            printf("the directory already exists")
     
     
 
@@ -179,11 +185,16 @@ def is_dir_hidden(dir):
     
 def scan_dir(path, search_hidden_directories=True, ):
     """this function scans all of the files and directories in a directory. The function then calls its self on any of the directories that it found. this causes it to build up a tree of all the files and directories """
-    files_in_snapshot=[]
-    symlinks_in_snapshot=[]
-    dir_in_snapshot=[]
+    global files_in_snapshot
+    global symlinks_in_snapshot
+    global dir_in_snapshot
     dir_in_current_dir=[]
-    unknown_in_snapshot=[]
+    global unknown_in_snapshot
+#    files_in_snapshot=[]
+#    symlinks_in_snapshot=[]
+#    dir_in_snapshot=[]
+#    dir_in_current_dir=[]
+#    unknown_in_snapshot=[]
     if os.path.exists(path)==False:
         debug_message ("error#############################",0)
         debug_message (("path:", path, "  doesnot exist"), 0)
@@ -192,7 +203,7 @@ def scan_dir(path, search_hidden_directories=True, ):
     for i in range(0, len(dir_snapshot)):
 
         current_snapshot=os.path.join(path, dir_snapshot[i])
-        debug_message (("current snapshot:", current_snapshot), 2)
+        ##debug_message (("current snapshot:", current_snapshot), 2)
         isDir=os.path.isdir(current_snapshot)
         isFile=os.path.isfile(current_snapshot)
         isLink=os.path.islink(current_snapshot)
@@ -228,7 +239,15 @@ def scan_dir(path, search_hidden_directories=True, ):
             unknown_in_snapshot.append(current_snapshot)
             
     for i in range(0, len(dir_in_current_dir)):
-        scan_dir(dir_in_current_dir[i])
+        debug_message(("scanning dir", dir_in_current_dir[i]) , 2)
+        scan_dir(dir_in_current_dir[i], search_hidden_directories)
+        
+#        #debug_message(("data 0", data[0][0]), 2)
+#        if len(files)
+#        files_in_snapshot.append(data[0][0])
+#        dir_in_snapshot.append(data[1][0])
+#        symlinks_in_snapshot.append(data[2][0])
+#        unknown_in_snapshot.append(data[3][0])
     return (files_in_snapshot, dir_in_snapshot, symlinks_in_snapshot, unknown_in_snapshot)
 ##
 ##def print_scanned_dir_list():
@@ -334,7 +353,7 @@ def copy_scanned_files_into_yaffs(files_in_snapshot, dir_in_snapshot,  symlinks_
         debug_message( ("unknown object in snapshot:", unknown_in_snapshot[i]), 0)
     
     
-def import_into_yaffs(file_path, yaffs_path="/yaffs2/", debug_level=1,  copy_hidden_dir=True ,new_yaffs_trace_val=0 ):
+def import_into_yaffs(file_path, yaffs_path="/yaffs2/", debug_level=1,  copy_hidden_dir=True ,new_yaffs_trace_val=-1 ):
 #    global current_debug_level
 #    global search_hidden_directories
 #    global yaffs_root_dir_path
@@ -345,7 +364,8 @@ def import_into_yaffs(file_path, yaffs_path="/yaffs2/", debug_level=1,  copy_hid
 #    yaffs_root_dir_path=yaffs_path
 #    path=file_path
     old_yaffs_trace_val=yaffs_get_trace()
-    yaffs_set_trace(new_yaffs_trace_val)
+    if new_yaffs_trace_val!=-1:
+        yaffs_set_trace(new_yaffs_trace_val)
     
     data=scan_dir(file_path, copy_hidden_dir)
     copy_scanned_files_into_yaffs(data[0], data[1], data[2], data[3],file_path,  yaffs_path)
@@ -354,14 +374,15 @@ def import_into_yaffs(file_path, yaffs_path="/yaffs2/", debug_level=1,  copy_hid
     
     
 if __name__=="__main__":
-    yaffs_StartUp()
+    yaffs_start_up()
     yaffs_mount("/yaffs2/")
-    yaffs_set_trace(0)
+    #yaffs_set_trace(0)
 #    absolute_path = os.path.abspath(os.path.curdir)
     #print "absolute path:", absolute_path
     current_debug_level=1
     search_hidden_directories=True
-    yaffs_root_dir_path="/yaffs2/scanning/"
+    yaffs_root_dir_path="/yaffs2/"
+    yaffs_trace=-1
     #print sys.argv
     path=sys.argv[1]
     for i in range(2, len(sys.argv)):
@@ -369,13 +390,17 @@ if __name__=="__main__":
             current_debug_level=int( sys.argv[i+1])
         if sys.argv[i]=="-ignore_hidden_directories":
             search_hidden_directories=False
+        if sys.argv[i]=="-o":
+            yaffs_root_dir_path=sys.argv[i+1]
+        if sys.argv[i]=="-yaffs_trace":
+            yaffs_trace=int(sys.argv[i+1])
 #
 #
 #    path="/home/timothy/work/yaffs/git/yaffs2"
 #    path="/home/timothy/my_stuff/old_laptop/timothy/programming_lejos/"
 
 
-    import_into_yaffs(path, yaffs_root_dir_path, current_debug_level,  search_hidden_directories, 0 )
+    import_into_yaffs(path, yaffs_root_dir_path, current_debug_level,  search_hidden_directories, yaffs_trace )
 #    scan_dir(path)
 #    copy_scanned_files_into_yaffs()
     #print_scanned_dir_list()