[conduit] Update Shotwell support to 0.8.x



commit bfd83c400096bd6e598b9c23dc9ad14b3cb3f277
Author: Nathaniel Harward <nharward gmail com>
Date:   Fri Mar 18 09:50:02 2011 +1300

    Update Shotwell support to 0.8.x

 conduit/modules/ShotwellModule/ShotwellModule.py   |   29 +++++++------
 .../modules/ShotwellModule/shotwell/__init__.py    |   43 +++++++++++++++++---
 2 files changed, 52 insertions(+), 20 deletions(-)
---
diff --git a/conduit/modules/ShotwellModule/ShotwellModule.py b/conduit/modules/ShotwellModule/ShotwellModule.py
index 2387c44..089ba0e 100644
--- a/conduit/modules/ShotwellModule/ShotwellModule.py
+++ b/conduit/modules/ShotwellModule/ShotwellModule.py
@@ -1,3 +1,4 @@
+
 import conduit
 import conduit.dataproviders.DataProvider as DataProvider
 import conduit.datatypes.Photo as Photo
@@ -22,7 +23,6 @@ else:
     MODULES = {}
     log.info("Shotwell not installed")
 
-# Why is this not in the standard library?
 def _flatten(lst):
     for elem in lst:
         if type(elem) in (tuple, list):
@@ -33,7 +33,6 @@ def _flatten(lst):
 
 class ShotwellDataProvider(DataProvider.DataSource):
 
-
     _name_ = _('Shotwell')
     _description_ = _('Sync from your Shotwell photo library')
     _icon_ = 'shotwell'
@@ -54,8 +53,7 @@ class ShotwellDataProvider(DataProvider.DataSource):
             shotwell_db.close()
             self._enabled = True
         except:
-            log.warn('Disabling Shotwell module, open of sqlite3 DB failed')
-            self._enabled = False
+            log.warn(_('Disabling Shotwell module, unable to open sqlite3 data source'))
 
     def initialize(self):
         DataProvider.DataSource.initialize(self)
@@ -63,6 +61,7 @@ class ShotwellDataProvider(DataProvider.DataSource):
 
     def set_tags(self, tags):
         self._selected_tag_names = map(lambda x: str(x), tags)
+        log.debug('Configuring to sync tags: %s', str(self._selected_tag_names))
 
     def get_tags(self):
         return self._selected_tag_names
@@ -71,19 +70,22 @@ class ShotwellDataProvider(DataProvider.DataSource):
         shotwell_db = shotwell.ShotwellDB()
         config.add_section(_('Tags'))
         all_tag_names = map(lambda sTag: sTag.name, shotwell_db.tags())
-        config.add_item(_('Tags'), 'list', config_name = 'tags',
-                        choices = all_tag_names)
+        config.add_item(_('Tags'), 'list', config_name = 'tags', choices = all_tag_names)
         shotwell_db.close()
 
     def refresh(self):
         DataProvider.DataSource.refresh(self)
         shotwell_db = shotwell.ShotwellDB()
-        tags = filter(lambda sTag: sTag.name in self._selected_tag_names,
-                      shotwell_db.tags())
+        tags = filter(lambda sTag: sTag.name in self._selected_tag_names, shotwell_db.tags())
+        log.debug('Tags to sync:')
+        if log.isEnabledFor(logging.DEBUG):
+            for sTag in tags:
+                log.debug('\t%s', str(sTag))
         tagged_photos = list(_flatten(map(lambda sTag: sTag.photoIDs, tags)))
-        self._shotwell_photos = filter(lambda sPhoto: str(sPhoto.id) in \
-                                       tagged_photos, shotwell_db.photos())
-        log.debug('Found %i photos to sync', len(self._shotwell_photos))
+        log.debug('Photo IDs for tags(%s): %s', str(tags), str(tagged_photos))
+        log.debug('All Photo IDs: %s', map(lambda x: str(x.id), shotwell_db.photos()))
+        self._shotwell_photos = filter(lambda sPhoto: str(sPhoto.id) in tagged_photos, shotwell_db.photos())
+        log.debug('%i photos (from %i tags) to sync', len(self._shotwell_photos), len(tags))
         shotwell_db.close()
 
     def get_all(self):
@@ -92,11 +94,10 @@ class ShotwellDataProvider(DataProvider.DataSource):
 
     def get(self, LUID):
         DataProvider.DataSource.get(self, LUID)
-        sPhoto = filter(lambda sPhoto: str(sPhoto.id) == LUID,
-                        self._shotwell_photos)[0]
+        sPhoto = filter(lambda sPhoto: str(sPhoto.id) == LUID, self._shotwell_photos)[0]
         photo = Photo.Photo('file://' + sPhoto.filename)
         photo.set_UID(LUID)
-        photo.set_caption(sPhoto.title)
+        log.debug('Returning photo(%s) for LUID(%s)', sPhoto.filename, LUID)
         return photo
 
     def get_UID(self):
diff --git a/conduit/modules/ShotwellModule/shotwell/__init__.py b/conduit/modules/ShotwellModule/shotwell/__init__.py
index 4ef3434..73b2367 100644
--- a/conduit/modules/ShotwellModule/shotwell/__init__.py
+++ b/conduit/modules/ShotwellModule/shotwell/__init__.py
@@ -1,8 +1,20 @@
 import os.path
+import re
 import sqlite3
 import string
 import sys
 
+# These can be plain photo IDs (legacy), or new "source IDs"
+# which have leading text indicating the type, followed by a
+# hex-encoded ID.  For photos the type is "thumb" (others
+# include "tag", "video" and "event")
+def source_id_to_legacy(sourceID):
+    stringSourceID = str(sourceID)
+    if re.match("^[a-z]+", stringSourceID):
+        return str(int(re.sub("^[a-z]+", "", stringSourceID), 16))
+    else:
+        return stringSourceID
+
 class Version(object):
 
 
@@ -32,7 +44,7 @@ class Event(object):
 
 
     def __init__(self, id, name):
-        self._id = id
+        self._id = source_id_to_legacy(id)
         self._name = name
 
     def __str__(self):
@@ -52,10 +64,10 @@ class Tag(object):
 
 
     def __init__(self, id, name, photo_id_list_csv):
-        self._id = id
+        self._id = source_id_to_legacy(id)
         self._name = name
-        self._photoIDs = filter(lambda x: x != None and len(x) > 0,
-                                string.split(photo_id_list_csv, ','))
+        self._photoIDs = map(source_id_to_legacy, filter(lambda x: x != None and len(x) > 0,
+                                                   string.split(photo_id_list_csv, ',')))
 
     def __str__(self):
         return 'Tag(id=' + str(self.id) + ';name=' + str(self.name) + \
@@ -79,13 +91,13 @@ class Photo(object):
 
     def __init__(self, id, filename, width=None, height=None, filesize=None,
                  timestamp=None, eventID=None, title=''):
-        self._id = id
+        self._id = source_id_to_legacy(id)
         self._filename = filename
         self._width = width
         self._height = height
         self._filesize = filesize
         self._timestamp = timestamp
-        self._eventID = eventID
+        self._eventID = source_id_to_legacy(eventID)
         self._title = title
 
     def __str__(self):
@@ -231,3 +243,22 @@ class ShotwellDB(_ReadOnlySqlite3Database):
         else:
             return self._selectMany(self._PHOTO_SQL_WITH_TITLE,
                                     RowMapper.photo_with_title)
+
+    def dump(self):
+        print "ShotwellDB dump:"
+        print "    Version: " + str(self.version())
+        print "    Tags   : "
+        for tag in self.tags():
+            print "             " + str(tag)
+            for photoID in tag.photoIDs:
+                print "                 PhotoID[" + str(self.photo(photoID)) + "]"
+        for photo in self.photos():
+            print "             " + str(photo)
+
+def main():
+    db = ShotwellDB()
+    db.dump()
+    db.close()
+
+if __name__ == "__main__":
+    main()



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