conduit r1568 - in trunk: . conduit/datatypes conduit/modules/GoogleModule conduit/modules/ZotoModule



Author: jstowers
Date: Thu Jul 17 03:49:29 2008
New Revision: 1568
URL: http://svn.gnome.org/viewvc/conduit?rev=1568&view=rev

Log:
	* conduit/datatypes/File.py: Include tags in the hash of the object.
	* conduit/datatypes/Photo.py: Include underlying file hash plus photo
	metadata (size, caption) in the hash of the object.
	* conduit/modules/GoogleModule/GoogleModule.py:
	* conduit/modules/ZotoModule/ZotoModule.py: Implement more efficient
	_replace_photo(). Fixes #521196 (Matt Brown, Manuel J. Garrido)


Modified:
   trunk/   (props changed)
   trunk/ChangeLog
   trunk/conduit/datatypes/File.py
   trunk/conduit/datatypes/Photo.py
   trunk/conduit/modules/GoogleModule/GoogleModule.py
   trunk/conduit/modules/ZotoModule/ZotoModule.py

Modified: trunk/conduit/datatypes/File.py
==============================================================================
--- trunk/conduit/datatypes/File.py	(original)
+++ trunk/conduit/datatypes/File.py	Thu Jul 17 03:49:29 2008
@@ -389,8 +389,11 @@
                 return None
 
     def get_hash(self):
+        # Join the tags into a string to be hashed so the object is updated if
+        # they change.
+        tagstr = "".join(self.get_tags())
         #FIXME: self.get_size() does not seem reliable
-        return hash(None)
+        return hash(tagstr)
                        
     def get_filename(self):
         """

Modified: trunk/conduit/datatypes/Photo.py
==============================================================================
--- trunk/conduit/datatypes/Photo.py	(original)
+++ trunk/conduit/datatypes/Photo.py	Thu Jul 17 03:49:29 2008
@@ -55,6 +55,13 @@
 
     def set_caption(self, caption):
         self._caption = caption
+
+    def get_hash(self):
+        # Combine the file hash with other photo metadata.
+        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)
         
     def __getstate__(self):
         data = File.File.__getstate__(self)

Modified: trunk/conduit/modules/GoogleModule/GoogleModule.py
==============================================================================
--- trunk/conduit/modules/GoogleModule/GoogleModule.py	(original)
+++ trunk/conduit/modules/GoogleModule/GoogleModule.py	Thu Jul 17 03:49:29 2008
@@ -589,6 +589,26 @@
         except Exception, e:
             raise Exceptions.SyncronizeError("Picasa Upload Error.")
 
+    def _replace_photo(self, id, uploadInfo):
+        try:
+            gphoto = self.gphoto_dict[id]
+
+            gphoto.title = atom.Title(text=uploadInfo.name)
+            gphoto.summary = atom.Summary(text=uploadInfo.caption)
+            gphoto.media = gdata.media.Group()
+            gphoto.media.keywords = gdata.media.Keywords()
+            if uploadInfo.tags:
+                gphoto.media.keywords.text = ",".join("%s" % (str(t)) for t in uploadInfo.tags)
+        
+            gphoto = self.service.UpdatePhotoMetadata(gphoto)
+        
+            # This should be done just only the photo itself has changed
+            gphoto = self.service.UpdatePhotoBlob(gphoto, uploadInfo.url)
+
+            return Rid(uid=gphoto.gphoto_id.text)
+        except Exception, e:
+            raise Exceptions.SyncronizeError("Picasa Update Error.")
+
     def _get_album(self):
         for name,album in self._get_albums():
             if name == self.albumName:

Modified: trunk/conduit/modules/ZotoModule/ZotoModule.py
==============================================================================
--- trunk/conduit/modules/ZotoModule/ZotoModule.py	(original)
+++ trunk/conduit/modules/ZotoModule/ZotoModule.py	Thu Jul 17 03:49:29 2008
@@ -102,6 +102,39 @@
 
         return fotoId
 
+    def removeAllTags(self, photoId):
+        tags= self.server.tags.get_image_tags(self.zapiKey, self.zotoAuth,
+                                             self.username, photoId, 'owner')
+        if tags:
+            tag_list = []
+            for tag in tags:
+                tag_list.append(tag['tag_name'])
+
+            self.server.tags.multi_untag_image(self.zapiKey, self.zotoAuth,
+                                               self.username, [photoId], tag_list)
+
+    def update_photo(self, photoId, uploadInfo):
+        if not uploadInfo.caption:
+            uploadInfo.caption=''
+        
+        self.server.images.multi_set_attr(self.zapiKey, self.zotoAuth, [photoId],
+                                          {'title' : uploadInfo.name,
+                                           'description' : uploadInfo.caption})
+        tags = []
+        for tag in uploadInfo.tags:
+            tags.append(tag)
+
+        self.removeAllTags(photoId);
+        if len(tags) > 0:
+            self.server.tags.multi_tag_image(self.zapiKey, self.zotoAuth,
+                                             self.username, [photoId], tags)
+
+        f = open(uploadInfo.url,'r')
+        buf=f.read()                
+        f.close()
+        return self.server.images.store_modified(self.zapiKey, self.zotoAuth,
+                                                 xmlrpclib.Binary(buf), photoId)
+
     def delete_from_album(self, photoId, albumId):
         self.server.albums.multi_del_image(self.zapiKey, self.zotoAuth,
                                            albumId, [photoId])
@@ -193,6 +226,17 @@
         
         return Rid(uid=fotoId)
 
+    def _replace_photo(self, id, uploadInfo):
+        """
+        Updates a photo (binary and metadata)
+        """
+        try:
+            fotoId = self.zapi.update_photo(id, uploadInfo)
+        except Exception, e:
+            raise Exceptions.SyncronizeError("Zoto Update Error.")
+        
+        return Rid(uid=fotoId)
+
     def configure(self, window):
         """
         Configures the ZotoSink



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