Little bugs and status output.

This commit is contained in:
Jason A. Donenfeld 2011-05-05 09:17:21 -04:00
parent 7ce3c03225
commit ff5aac5bad
2 changed files with 12 additions and 2 deletions

View File

@ -140,6 +140,7 @@ class Photo(object):
else: else:
suffix = str(size) suffix = str(size)
thumb_path = os.path.join(thumb_path, image_cache(self._path, suffix)) 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"]: if os.path.exists(thumb_path) and datetime.fromtimestamp(os.path.getmtime(thumb_path)) >= self._attributes["DateTimeFile"]:
return return
image = image.copy() image = image.copy()
@ -159,7 +160,10 @@ class Photo(object):
image.save(thumb_path, "JPEG") image.save(thumb_path, "JPEG")
def _thumbnails(self, image, thumb_path): def _thumbnails(self, image, thumb_path):
if "Orientation" in self._attributes:
orientation = self._attributes["Orientation"] orientation = self._attributes["Orientation"]
else:
orientation = 1
mirror = image mirror = image
if orientation == 2: if orientation == 2:
# Vertical Mirror # Vertical Mirror
@ -214,7 +218,7 @@ class Photo(object):
dictionary[key] = datetime.strptime(dictionary[key], "%a %b %d %H:%M:%S %Y") dictionary[key] = datetime.strptime(dictionary[key], "%a %b %d %H:%M:%S %Y")
except: except:
pass pass
return Photo(path, dictionary) return Photo(path, None, dictionary)
def to_dict(self): def to_dict(self):
photo = { "name": self.name, "date": self.date } photo = { "name": self.name, "date": self.date }
photo.update(self.attributes) photo.update(self.attributes)

View File

@ -13,12 +13,15 @@ class TreeWalker:
self.walk(album_path) self.walk(album_path)
self.remove_stale() self.remove_stale()
def walk(self, path): def walk(self, path):
print "Walking %s" % path
cache = os.path.join(self.cache_path, json_cache(path)) cache = os.path.join(self.cache_path, json_cache(path))
cached = False cached = False
cached_album = None cached_album = None
if os.path.exists(cache): if os.path.exists(cache):
print "Has cache %s" % path
cached_album = Album.from_cache(cache) cached_album = Album.from_cache(cache)
if os.path.getmtime(path) <= os.path.getmtime(cache): if os.path.getmtime(path) <= os.path.getmtime(cache):
print "Album is fully cached"
cached = True cached = True
album = cached_album album = cached_album
if not cached: if not cached:
@ -32,13 +35,16 @@ class TreeWalker:
if cached_album: if cached_album:
cached_photo = cached_album.photo_from_path(entry) cached_photo = cached_album.photo_from_path(entry)
if cached_photo and datetime.fromtimestamp(os.path.getmtime(entry)) <= cached_photo.attributes["DateTimeFile"]: if cached_photo and datetime.fromtimestamp(os.path.getmtime(entry)) <= cached_photo.attributes["DateTimeFile"]:
print "Photo cache hit %s" % entry
cache_hit = True cache_hit = True
photo = cached_photo photo = cached_photo
if not cache_hit: if not cache_hit:
print "No cache - scanning %s" % entry
photo = Photo(entry, self.cache_path) photo = Photo(entry, self.cache_path)
if photo.is_valid: if photo.is_valid:
self.all_photos.append(photo) self.all_photos.append(photo)
album.add_photo(photo) album.add_photo(photo)
print "Writing cache of %s" % album.cache_path
album.cache(self.cache_path) album.cache(self.cache_path)
self.all_albums.append(album) self.all_albums.append(album)
return album return album