conduit r1742 - in trunk: . conduit conduit/datatypes conduit/modules/EvolutionModule



Author: jstowers
Date: Sun Oct  5 13:25:56 2008
New Revision: 1742
URL: http://svn.gnome.org/viewvc/conduit?rev=1742&view=rev

Log:
2008-09-26  Matt Colyer <matt colyer name>

	* conduit/MappingDB.py: Added a way to find a row based on two
	objects and the sink.
	* conduit/datatypes/*.py: Forced get_hash to string values and
	changed compare to use the hashes (when no mtimes present).
	* conduit/modules/EvolutionModule/EvolutionModule.py: Changed
	compare to use new hash functionality. Fixed Note not return a proper
	rid.



Modified:
   trunk/ChangeLog
   trunk/conduit/MappingDB.py
   trunk/conduit/datatypes/Bookmark.py
   trunk/conduit/datatypes/Contact.py
   trunk/conduit/datatypes/DataType.py
   trunk/conduit/datatypes/Email.py
   trunk/conduit/datatypes/Event.py
   trunk/conduit/datatypes/File.py
   trunk/conduit/datatypes/Note.py
   trunk/conduit/datatypes/Photo.py
   trunk/conduit/datatypes/Setting.py
   trunk/conduit/datatypes/Text.py
   trunk/conduit/modules/EvolutionModule/EvolutionModule.py

Modified: trunk/conduit/MappingDB.py
==============================================================================
--- trunk/conduit/MappingDB.py	(original)
+++ trunk/conduit/MappingDB.py	Sun Oct  5 13:25:56 2008
@@ -94,6 +94,32 @@
             os.unlink(filename)
             self._open_db_and_check_structure(filename)
 
+    def get_mapping_from_objects(self, sourceDataLUID, sinkDataLUID, sinkUID):
+        
+        sql = "SELECT * FROM mappings WHERE sourceDataLUID = ? AND sinkDataLUID = ? AND sinkUID = ?"
+        res = self._db.select_one(sql, (sourceDataLUID, sinkDataLUID, sinkUID))
+        
+        #a mapping is always returned relative to the source -> sink
+        #order in which it was called.
+        if (res[5] == sinkUID):
+            m = Mapping(
+                    res[0],
+                    sourceUID=res[1],
+                    sourceRid=conduit.datatypes.Rid(res[2],res[3],res[4]),
+                    sinkUID=res[5],
+                    sinkRid=conduit.datatypes.Rid(res[6],res[7],res[8])
+                    )
+        else:
+            m = Mapping(
+                    res[0],
+                    sourceUID=res[5],
+                    sourceRid=conduit.datatypes.Rid(res[6],res[7],res[8]),
+                    sinkUID=res[1],
+                    sinkRid=conduit.datatypes.Rid(res[2],res[3],res[4])
+                    )
+
+        return m
+
     def get_mapping(self, sourceUID, dataLUID, sinkUID):
         """
         pass

Modified: trunk/conduit/datatypes/Bookmark.py
==============================================================================
--- trunk/conduit/datatypes/Bookmark.py	(original)
+++ trunk/conduit/datatypes/Bookmark.py	Sun Oct  5 13:25:56 2008
@@ -23,7 +23,7 @@
         return self.uri
         
     def get_hash(self):
-        return hash( (self.get_title(), self.get_uri()) )
+        return str(hash( (self.get_title(), self.get_uri()) ))
 
     def get_bookmark_string(self):
         return self.__str__()

Modified: trunk/conduit/datatypes/Contact.py
==============================================================================
--- trunk/conduit/datatypes/Contact.py	(original)
+++ trunk/conduit/datatypes/Contact.py	Sun Oct  5 13:25:56 2008
@@ -86,6 +86,6 @@
         return "Name: %s" % self.get_name()
         
     def get_hash(self):
-        return hash(self.get_vcard_string())
+        return str(hash(self.get_vcard_string()))
     
 

Modified: trunk/conduit/datatypes/DataType.py
==============================================================================
--- trunk/conduit/datatypes/DataType.py	(original)
+++ trunk/conduit/datatypes/DataType.py	Sun Oct  5 13:25:56 2008
@@ -39,7 +39,7 @@
         """
         return self._name_
 
-    def compare(self, B):
+    def compare(self, B, sinkUID=None):
         """
         Comparison function to be overridden by datatypes who support two
         way synchronisation. 
@@ -55,13 +55,20 @@
         """
         log.debug("COMPARE: %s <----> %s " % (self.get_UID(), B.get_UID()))
 
+        m = None
+        if sinkUID:
+            m = conduit.GLOBALS.mappingDB.get_mapping_from_objects(self.get_UID(), B.get_UID(), sinkUID)
+
         if self.get_rid() == B.get_rid():
             return conduit.datatypes.COMPARISON_EQUAL
 
         mtime1 = self.get_mtime()
         mtime2 = B.get_mtime()
 
-        if mtime1 == None or mtime2 == None:
+        # resolve conflicts with hashes if only one side has changed and mtimes are not useful
+        if (mtime1 == None or mtime2 == None) and m and m.get_sink_rid().get_hash() == B.get_hash():
+            return conduit.datatypes.COMPARISON_NEWER
+        elif mtime1 == None or mtime2 == None:
             return conduit.datatypes.COMPARISON_UNKNOWN
 
         if mtime1 > mtime2:

Modified: trunk/conduit/datatypes/Email.py
==============================================================================
--- trunk/conduit/datatypes/Email.py	(original)
+++ trunk/conduit/datatypes/Email.py	Sun Oct  5 13:25:56 2008
@@ -93,5 +93,5 @@
         DataType.DataType.__setstate__(self, data)
 
     def get_hash(self):
-        return hash( self.get_email_string() )
+        return str(hash( self.get_email_string() ))
         

Modified: trunk/conduit/datatypes/Event.py
==============================================================================
--- trunk/conduit/datatypes/Event.py	(original)
+++ trunk/conduit/datatypes/Event.py	Sun Oct  5 13:25:56 2008
@@ -26,4 +26,4 @@
         DataType.DataType.__setstate__(self, data)
         
     def get_hash(self):
-        return hash(self.get_ical_string())
+        return str(hash(self.get_ical_string()))

Modified: trunk/conduit/datatypes/File.py
==============================================================================
--- trunk/conduit/datatypes/File.py	(original)
+++ trunk/conduit/datatypes/File.py	Sun Oct  5 13:25:56 2008
@@ -314,7 +314,7 @@
         # they change.
         tagstr = "".join(self.get_tags())
         #FIXME: self.get_size() does not seem reliable
-        return hash(tagstr)
+        return str(hash(tagstr))
                        
     def get_filename(self):
         """

Modified: trunk/conduit/datatypes/Note.py
==============================================================================
--- trunk/conduit/datatypes/Note.py	(original)
+++ trunk/conduit/datatypes/Note.py	Sun Oct  5 13:25:56 2008
@@ -21,7 +21,7 @@
         return self.contents
         
     def get_hash(self):
-        return hash( (self.get_title(), self.get_contents()) )
+        return str(hash( (self.get_title(), self.get_contents()) ))
 
     def get_note_string(self):
         return self.__str__()

Modified: trunk/conduit/datatypes/Photo.py
==============================================================================
--- trunk/conduit/datatypes/Photo.py	(original)
+++ trunk/conduit/datatypes/Photo.py	Sun Oct  5 13:25:56 2008
@@ -84,7 +84,7 @@
         file_hash = File.File.get_hash(self)       
         hash_data = "%s%s%s" % (file_hash, self.get_photo_size(),
                 self.get_caption())
-        return hash(hash_data)
+        return str(hash(hash_data))
         
     def __getstate__(self):
         data = File.File.__getstate__(self)

Modified: trunk/conduit/datatypes/Setting.py
==============================================================================
--- trunk/conduit/datatypes/Setting.py	(original)
+++ trunk/conduit/datatypes/Setting.py	Sun Oct  5 13:25:56 2008
@@ -22,4 +22,4 @@
         DataType.DataType.__setstate__(self, data)
 
     def get_hash(self):
-        return hash( (self.key,self.value) )
+        return str(hash( (self.key,self.value) ))

Modified: trunk/conduit/datatypes/Text.py
==============================================================================
--- trunk/conduit/datatypes/Text.py	(original)
+++ trunk/conduit/datatypes/Text.py	Sun Oct  5 13:25:56 2008
@@ -30,5 +30,5 @@
         DataType.DataType.__setstate__(self, data)
             
     def get_hash(self):
-        return hash(self.text)
+        return str(hash(self.text))
 

Modified: trunk/conduit/modules/EvolutionModule/EvolutionModule.py
==============================================================================
--- trunk/conduit/modules/EvolutionModule/EvolutionModule.py	(original)
+++ trunk/conduit/modules/EvolutionModule/EvolutionModule.py	Sun Oct  5 13:25:56 2008
@@ -72,7 +72,7 @@
                     rid = self._update_object(LUID, obj)
                     return rid
                 else:
-                    comp = obj.compare(existing)
+                    comp = obj.compare(existing, "%s-%s" % (self.__class__.__name__, self.get_UID()))
                     # only update if newer
                     if comp != conduit.datatypes.COMPARISON_NEWER:
                         raise Exceptions.SynchronizeConflictError(comp, obj, existing)
@@ -352,7 +352,8 @@
         
         if uid != None:
             mtime = datetime.datetime.fromtimestamp(obj.get_modified())
-            return conduit.datatypes.Rid(uid=uid, mtime=mtime, hash=mtime)
+            note = self._get_object(uid)
+            return note.get_rid()
         else:
             raise Exceptions.SyncronizeError("Error creating memo")
 



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