From ff5aac5badcfbe93ce86bbb60c3d45c575acd4fd Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 5 May 2011 09:17:21 -0400 Subject: [PATCH] Little bugs and status output. --- PhotoAlbum.py | 8 ++++++-- TreeWalker.py | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/PhotoAlbum.py b/PhotoAlbum.py index 547ad61..ec91b8a 100644 --- a/PhotoAlbum.py +++ b/PhotoAlbum.py @@ -140,6 +140,7 @@ class Photo(object): else: suffix = str(size) thumb_path = os.path.join(thumb_path, image_cache(self._path, suffix)) + print "Thumbing %s" % thumb_path if os.path.exists(thumb_path) and datetime.fromtimestamp(os.path.getmtime(thumb_path)) >= self._attributes["DateTimeFile"]: return image = image.copy() @@ -159,7 +160,10 @@ class Photo(object): image.save(thumb_path, "JPEG") def _thumbnails(self, image, thumb_path): - orientation = self._attributes["Orientation"] + if "Orientation" in self._attributes: + orientation = self._attributes["Orientation"] + else: + orientation = 1 mirror = image if orientation == 2: # Vertical Mirror @@ -214,7 +218,7 @@ class Photo(object): dictionary[key] = datetime.strptime(dictionary[key], "%a %b %d %H:%M:%S %Y") except: pass - return Photo(path, dictionary) + return Photo(path, None, dictionary) def to_dict(self): photo = { "name": self.name, "date": self.date } photo.update(self.attributes) diff --git a/TreeWalker.py b/TreeWalker.py index e8b9e76..11ce7de 100644 --- a/TreeWalker.py +++ b/TreeWalker.py @@ -13,12 +13,15 @@ class TreeWalker: self.walk(album_path) self.remove_stale() def walk(self, path): + print "Walking %s" % path cache = os.path.join(self.cache_path, json_cache(path)) cached = False cached_album = None if os.path.exists(cache): + print "Has cache %s" % path cached_album = Album.from_cache(cache) if os.path.getmtime(path) <= os.path.getmtime(cache): + print "Album is fully cached" cached = True album = cached_album if not cached: @@ -32,13 +35,16 @@ class TreeWalker: if cached_album: cached_photo = cached_album.photo_from_path(entry) if cached_photo and datetime.fromtimestamp(os.path.getmtime(entry)) <= cached_photo.attributes["DateTimeFile"]: + print "Photo cache hit %s" % entry cache_hit = True photo = cached_photo if not cache_hit: + print "No cache - scanning %s" % entry photo = Photo(entry, self.cache_path) if photo.is_valid: self.all_photos.append(photo) album.add_photo(photo) + print "Writing cache of %s" % album.cache_path album.cache(self.cache_path) self.all_albums.append(album) return album