conduit r1636 - in trunk: . conduit/dataproviders conduit/datatypes



Author: jstowers
Date: Sun Aug  3 02:49:10 2008
New Revision: 1636
URL: http://svn.gnome.org/viewvc/conduit?rev=1636&view=rev

Log:
	* conduit/dataproviders/Image.py:
	* conduit/datatypes/Photo.py: Implementation for Phoro.compare()
	and ImageTwoWay.put. Fixes #543366 (Manuel J. Garrido)


Modified:
   trunk/   (props changed)
   trunk/ChangeLog
   trunk/conduit/dataproviders/Image.py
   trunk/conduit/datatypes/Photo.py

Modified: trunk/conduit/dataproviders/Image.py
==============================================================================
--- trunk/conduit/dataproviders/Image.py	(original)
+++ trunk/conduit/dataproviders/Image.py	Sun Aug  3 02:49:10 2008
@@ -5,6 +5,7 @@
 import conduit.Exceptions as Exceptions
 import conduit.datatypes.File as File
 import conduit.dataproviders.DataProvider as DataProvider
+from conduit.datatypes import Rid
 
 class UploadInfo:
     """
@@ -86,7 +87,7 @@
         """
         Replace a photo with a new version
         """
-        return id
+        return Rid(uid=id)
         
     def _get_photo_formats (self):
         """
@@ -172,4 +173,45 @@
         DataProvider.DataSource.__init__(self)
         ImageSink.__init__(self)
 
+    def put(self, photo, overwrite, LUID=None):
+        """
+        Accepts a vfs file. Must be made local.
+        I also store a md5 of the photos uri to check for duplicates
+        """
+        DataProvider.DataSink.put(self, photo, overwrite, LUID)
+
+        originalName = photo.get_filename()
+        #Gets the local URI (/foo/bar). If this is a remote file then
+        #it is first transferred to the local filesystem
+        photoURI = photo.get_local_uri()
+        mimeType = photo.get_mimetype()
+        tags = photo.get_tags ()
+        caption = photo.get_caption()
+
+        uploadInfo = UploadInfo(photoURI, mimeType, originalName, tags, caption)
+
+        if overwrite and LUID:
+            rid = self._replace_photo(LUID, uploadInfo)
+        else:
+            if LUID and self._get_photo_info(LUID):
+                remotePhoto = self.get(LUID)
+                comp = photo.compare(remotePhoto, False)
+                log.debug("Compared %s with %s. Result = %s" % 
+                          (photo.get_filename(),remotePhoto.get_filename(),comp))
+
+                if LUID != None and comp == conduit.datatypes.COMPARISON_NEWER:
+                    rid = self._replace_photo(LUID, uploadInfo)
+                elif comp == conduit.datatypes.COMPARISON_EQUAL:                    
+                    rid = remotePhoto.get_rid()
+                else:
+                    raise Exceptions.SynchronizeConflictError(comp, photo, remotePhoto)
+            else:
+                log.debug("Uploading Photo URI = %s, Mimetype = %s, Original Name = %s" %
+                          (photoURI, mimeType, originalName))
+                rid = self._upload_photo (uploadInfo)
+
+        if not rid:
+            raise Exceptions.SyncronizeError("Error putting/updating photo")
+        else:
+            return rid
 

Modified: trunk/conduit/datatypes/Photo.py
==============================================================================
--- trunk/conduit/datatypes/Photo.py	(original)
+++ trunk/conduit/datatypes/Photo.py	Sun Aug  3 02:49:10 2008
@@ -2,6 +2,8 @@
 
 import conduit.datatypes.File as File
 import conduit.utils as Utils
+import logging
+log = logging.getLogger("datatypes.Photo")
 
 PRESET_ENCODINGS = {
     "jpeg":{'formats':'image/jpeg','default-format':'image/jpeg'},
@@ -29,6 +31,27 @@
         self.pb = None
         self._caption = None
 
+    def compare(self, B, sizeOnly=False):
+        if sizeOnly:
+            return File.File.compare(self, B, True)
+
+        meTime = self.get_mtime()
+        bTime = B.get_mtime()
+        log.debug("Comparing %s (MTIME: %s) with %s (MTIME: %s)" % (self.URI, meTime, B.URI, bTime))
+        if meTime and bTime and (meTime != bTime):
+            if meTime > bTime:    #Am I newer than B
+                return conduit.datatypes.COMPARISON_NEWER        
+            else:
+                return conduit.datatypes.COMPARISON_OLDER
+
+        meHash = self.get_hash()
+        bHash = B.get_hash()
+        log.debug("Comparing %s (HASH: %s) with %s (HASH: %s)" % (self.URI, meHash, B.URI, bHash))
+        if (meHash == bHash):
+            return conduit.datatypes.COMPARISON_EQUAL
+        else:
+            return conduit.datatypes.COMPARISON_UNKNOWN
+
     def get_photo_pixbuf(self):
         """
         Defer actually getting the pixbuf till as



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