aboutsummaryrefslogtreecommitdiffstats
path: root/TreeWalker.py
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2011-05-05 18:37:15 -0400
committerJason A. Donenfeld <Jason@zx2c4.com>2011-05-05 18:37:15 -0400
commit4e02abb7a303ad96fb406b61108e2261a81c81de (patch)
tree3fe45f258dbe44efe4761012719082fea8826f5d /TreeWalker.py
parentLittle bugs and status output. (diff)
downloadPhotoFloat-4e02abb7a303ad96fb406b61108e2261a81c81de.tar.xz
PhotoFloat-4e02abb7a303ad96fb406b61108e2261a81c81de.zip
Fix caching errors.
Diffstat (limited to 'TreeWalker.py')
-rw-r--r--TreeWalker.py33
1 files changed, 25 insertions, 8 deletions
diff --git a/TreeWalker.py b/TreeWalker.py
index 11ce7de..17b9b54 100644
--- a/TreeWalker.py
+++ b/TreeWalker.py
@@ -1,16 +1,17 @@
import os
import os.path
from datetime import datetime
-from PhotoAlbum import Photo, Album, json_cache, set_cache_path_base
+from PhotoAlbum import Photo, Album
+from CachePath import json_cache, set_cache_path_base, file_mtime
class TreeWalker:
def __init__(self, album_path, cache_path):
- self.album_path = album_path
- self.cache_path = cache_path
+ self.album_path = os.path.abspath(album_path)
+ self.cache_path = os.path.abspath(cache_path)
set_cache_path_base(self.album_path)
self.all_albums = list()
self.all_photos = list()
- self.walk(album_path)
+ self.walk(self.album_path)
self.remove_stale()
def walk(self, path):
print "Walking %s" % path
@@ -20,10 +21,12 @@ class TreeWalker:
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):
+ if file_mtime(path) <= file_mtime(cache):
print "Album is fully cached"
cached = True
album = cached_album
+ for photo in album.photos:
+ self.all_photos.append(photo)
if not cached:
album = Album(path)
for entry in os.listdir(path):
@@ -34,12 +37,12 @@ class TreeWalker:
cache_hit = False
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"]:
+ if cached_photo and file_mtime(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
+ print "No cache, scanning %s" % entry
photo = Photo(entry, self.cache_path)
if photo.is_valid:
self.all_photos.append(photo)
@@ -49,4 +52,18 @@ class TreeWalker:
self.all_albums.append(album)
return album
def remove_stale(self):
- pass #TODO: remove left over caches \ No newline at end of file
+ for cache in os.listdir(self.cache_path):
+ match = False
+ for album in self.all_albums:
+ if cache == album.cache_path:
+ match = True
+ break
+ if match:
+ continue
+ for photo in self.all_photos:
+ if cache in photo.image_caches:
+ match = True
+ break
+ if not match:
+ print "Removing stale cache %s" % cache
+ os.unlink(os.path.join(self.cache_path, cache)) \ No newline at end of file