conduit r1648 - in trunk: . conduit conduit/dataproviders conduit/gtkui test/python-tests



Author: jstowers
Date: Tue Aug  5 12:31:03 2008
New Revision: 1648
URL: http://svn.gnome.org/viewvc/conduit?rev=1648&view=rev

Log:
	* conduit/Vfs.py: Be stricter with argument types, converting
	str to unicode.
	* conduit/gtkui/Database.py: Dont emit signals for rows with
	invalid rowrefs.
	* conduit/dataproviders/File.py:
	* test/python-tests/TestSyncFileFolder.py: Supply the correct
	number of args to make_thread. Add test for this.
	Fixes #546273


Modified:
   trunk/   (props changed)
   trunk/ChangeLog
   trunk/conduit/Vfs.py
   trunk/conduit/dataproviders/File.py
   trunk/conduit/gtkui/Database.py
   trunk/test/python-tests/TestSyncFileFolder.py

Modified: trunk/conduit/Vfs.py
==============================================================================
--- trunk/conduit/Vfs.py	(original)
+++ trunk/conduit/Vfs.py	Tue Aug  5 12:31:03 2008
@@ -39,7 +39,7 @@
     Joins multiple uri components. Performs safely if the first
     argument contains a uri scheme
     """
-    assert type(first) == str
+    first = _ensure_type(first)
     return os.path.join(first,*rest)
     #idx = first.rfind("://")
     #if idx == -1:
@@ -52,8 +52,8 @@
     """
     Returns the relative path fromURI --> toURI
     """
-    assert type(fromURI) == str
-    assert type(toURI) == str
+    fromURI = _ensure_type(fromURI)
+    toURI = _ensure_type(toURI)
     rel = toURI.replace(fromURI,"")
     #strip leading /
     if rel[0] == os.sep:

Modified: trunk/conduit/dataproviders/File.py
==============================================================================
--- trunk/conduit/dataproviders/File.py	(original)
+++ trunk/conduit/dataproviders/File.py	Tue Aug  5 12:31:03 2008
@@ -118,7 +118,8 @@
         for oid,uri,groupname in self.db.select("SELECT oid,URI,GROUP_NAME FROM config WHERE TYPE = ?",(TYPE_FOLDER,)):
             self.make_thread(
                     uri, 
-                    False,  #FIXME: Dont include hidden?
+                    False,  #include hidden
+                    False,  #follow symlinks
                     self._on_scan_folder_progress, 
                     self._on_scan_folder_completed, 
                     oid,

Modified: trunk/conduit/gtkui/Database.py
==============================================================================
--- trunk/conduit/gtkui/Database.py	(original)
+++ trunk/conduit/gtkui/Database.py	Tue Aug  5 12:31:03 2008
@@ -60,23 +60,35 @@
     def _on_inserted(self, db, oid):
         self.oidcache = []
         offset = self._get_offset(oid)
-        rowref = self.get_iter(offset)
-        path = self.get_path(rowref)
-        self.row_inserted(path, rowref)
+        try:
+            rowref = self.get_iter(offset)
+            path = self.get_path(rowref)
+            self.row_inserted(path, rowref)
+        except ValueError:
+            #not a valid rowref
+            pass
                 
     def _on_modified(self, db, oid):
         self.oidcache = []
         offset = self._get_offset(oid)
-        rowref = self.get_iter(offset)
-        path = self.get_path(rowref)
-        self.row_changed(path, rowref)
+        try:
+            rowref = self.get_iter(offset)
+            path = self.get_path(rowref)
+            self.row_changed(path, rowref)
+        except ValueError:
+            #not a valid rowref
+            pass
         
     def _on_deleted(self, db, oid):
         self.oidcache = []
         offset = self._get_offset(oid)
-        rowref = self.get_iter(offset)
-        path = self.get_path(rowref)
-        self.row_deleted(path)
+        try:
+            rowref = self.get_iter(offset)
+            path = self.get_path(rowref)
+            self.row_deleted(path)
+        except ValueError:
+            #not a valid rowref
+            pass
 
     def _get_n_rows(self):
         """

Modified: trunk/test/python-tests/TestSyncFileFolder.py
==============================================================================
--- trunk/test/python-tests/TestSyncFileFolder.py	(original)
+++ trunk/test/python-tests/TestSyncFileFolder.py	Tue Aug  5 12:31:03 2008
@@ -12,12 +12,12 @@
 
 #Repeat syncs a few times to check for duplicate mapping bugs, etc
 SYNC_N_TIMES = 3
-#Num files to start with, should end with 150% of this number
-NUM_FILES = 10
+#Num files to start with
+NUM_FILES = 20
 #Sleep time for file I/O
 SLEEP_TIME = 1
 #Print the mapping DB on the last sync?
-PRINT_MAPPING_DB = True
+PRINT_MAPPING_DB = False
 
 #setup test
 test = SimpleSyncTest()
@@ -28,24 +28,42 @@
 
 #prepare the test data
 sourceDir = os.path.join(os.environ['TEST_DIRECTORY'],"filesource")
+sourceFolder = os.path.join(os.environ['TEST_DIRECTORY'],"filesourcefolder")
 sinkDir = os.path.join(os.environ['TEST_DIRECTORY'],"foldersink")
 if not os.path.exists(sourceDir):
     os.mkdir(sourceDir)
 if not os.path.exists(sinkDir):
     os.mkdir(sinkDir)
+if not os.path.exists(sourceFolder):
+    os.mkdir(sourceFolder)
+
 
 FILES = []
-for i in range(0, NUM_FILES):
+
+#add some plain files to the dp
+for i in range(0, NUM_FILES/2):
     name = Utils.random_string()
     contents = Utils.random_string()
     f = File.TempFile(contents)
     f.force_new_filename(name)
     f.transfer(sourceDir, True)
-    FILES.append((name,contents))
+    FILES.append((name,contents,sourceDir,"",""))
+plainFiles = [os.path.join(sourceDir, name) for name,contents,i,j,k in FILES]
+
+#also add a plain folder, containg some more files
+FOLDER_GRP_NAME = "i-am-a-folder"
+for i in range(0, NUM_FILES/2):
+    name = Utils.random_string()
+    contents = Utils.random_string()
+    f = File.TempFile(contents)
+    f.force_new_filename(name)
+    f.transfer(sourceFolder, True)
+    FILES.append((name,contents,sourceFolder,"",FOLDER_GRP_NAME))
 
 #configure the source
 config = {}
-config["files"] = [os.path.join(sourceDir, name) for name,contents in FILES]
+config["files"] = plainFiles
+config["folders"] = ["file://%s---FIXME---%s" % (sourceFolder,FOLDER_GRP_NAME)]
 test.configure(source=config)
 
 #configure the sink
@@ -70,7 +88,7 @@
 
     mapSource2Sink = conduit.GLOBALS.mappingDB.get_mappings_for_dataproviders(sourceW.get_UID(), sinkW.get_UID())
     mapSink2Source = conduit.GLOBALS.mappingDB.get_mappings_for_dataproviders(sinkW.get_UID(), sourceW.get_UID())
-    ok("Oneway Sync: 10 Mappings source -> sink", len(mapSource2Sink) == 10 and len(mapSink2Source) == 0)
+    ok("Oneway Sync: %s Mappings source -> sink" % NUM_FILES, len(mapSource2Sink) == NUM_FILES and len(mapSink2Source) == 0)
 
 #two way sync
 test.set_two_way_sync(True)
@@ -84,20 +102,24 @@
 
     mapSource2Sink = conduit.GLOBALS.mappingDB.get_mappings_for_dataproviders(sourceW.get_UID(), sinkW.get_UID())
     mapSink2Source = conduit.GLOBALS.mappingDB.get_mappings_for_dataproviders(sinkW.get_UID(), sourceW.get_UID())
-    ok("Sync: 10 Mappings in total", len(mapSource2Sink + mapSink2Source) == 10)
+    ok("Sync: %s Mappings in total", len(mapSource2Sink + mapSink2Source) == NUM_FILES)
 
-for name,contents in FILES:
-    f1 = File.File(os.path.join(sourceDir, name))
-    f2 = File.File(os.path.join(sinkDir, name))
+#check the plain files
+for name,contents,sourceDir,sourceRelPath, sinkRelPath in FILES:
+    f1 = File.File(os.path.join(sourceDir, sourceRelPath, name))
+    f2 = File.File(os.path.join(sinkDir, sinkRelPath, name))
     comp = f1.compare(f2)
-    ok("Sync: checking source/%s == sink/%s" % (name, name),comp == COMPARISON_EQUAL)
+    ok("Sync: checking %s == %s" % (f1._get_text_uri(), f2._get_text_uri()),comp == COMPARISON_EQUAL)
 
 #Now delete half the files
-for i in range(0, NUM_FILES/2):
-    name, contents = FILES[i]
-    path = os.path.join(sourceDir, name)
-    del(FILES[i])
+d = []
+for i in range(0, NUM_FILES, 2):
+    name, contents, sourceDir, sourceRelPath, sinkRelPath = FILES[i]
+    path = os.path.join(sourceDir, sourceRelPath, name)
     os.remove(path)
+    d.append(FILES[i])
+for i in d:
+    FILES.remove(i)
 
 #some IO time
 time.sleep(SLEEP_TIME)
@@ -114,13 +136,12 @@
     ok("Delete: Files were deleted (%s,%s,%s)" % (a,b,len(FILES)), a==len(FILES) and b==len(FILES))
     mapSource2Sink = conduit.GLOBALS.mappingDB.get_mappings_for_dataproviders(sourceW.get_UID(), sinkW.get_UID())
     mapSink2Source = conduit.GLOBALS.mappingDB.get_mappings_for_dataproviders(sinkW.get_UID(), sourceW.get_UID())
-    ok("Delete: 5 Mappings in total", len(mapSource2Sink) == 5 and len(mapSink2Source) == 0)
-
+    ok("Delete: %s Mappings in total" % (NUM_FILES/2), len(mapSource2Sink) == (NUM_FILES/2) and len(mapSink2Source) == 0)
 
-for name,contents in FILES:
-    f1 = File.File(os.path.join(sourceDir, name))
-    f2 = File.File(os.path.join(sinkDir, name))
+for name,contents,sourceDir,sourceRelPath, sinkRelPath in FILES:
+    f1 = File.File(os.path.join(sourceDir, sourceRelPath, name))
+    f2 = File.File(os.path.join(sinkDir, sinkRelPath, name))
     comp = f1.compare(f2)
-    ok("Delete: checking source/%s == sink/%s" % (name, name),comp == COMPARISON_EQUAL)
+    ok("Delete: checking %s == %s" % (f1._get_text_uri(), f2._get_text_uri()),comp == COMPARISON_EQUAL)
 
 finished()



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]