summaryrefslogtreecommitdiffstats
path: root/scanner/TreeWalker.py
diff options
context:
space:
mode:
Diffstat (limited to 'scanner/TreeWalker.py')
-rw-r--r--scanner/TreeWalker.py42
1 files changed, 28 insertions, 14 deletions
diff --git a/scanner/TreeWalker.py b/scanner/TreeWalker.py
index e9df64e..4855d20 100644
--- a/scanner/TreeWalker.py
+++ b/scanner/TreeWalker.py
@@ -3,7 +3,7 @@ import os.path
import sys
from datetime import datetime
from PhotoAlbum import Photo, Album, PhotoAlbumEncoder
-from CachePath import json_cache, set_cache_path_base, file_mtime
+from CachePath import *
import json
class TreeWalker:
@@ -16,23 +16,28 @@ class TreeWalker:
self.walk(self.album_path)
self.big_lists()
self.remove_stale()
+ message("complete", "")
def walk(self, path):
- print "Walking %s" % path
+ next_level()
+ message("walking", os.path.basename(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
try:
cached_album = Album.from_cache(cache)
if file_mtime(path) <= file_mtime(cache):
- print "Album is fully cached"
+ message("full cache", os.path.basename(path))
cached = True
album = cached_album
for photo in album.photos:
self.all_photos.append(photo)
+ else:
+ message("partial cache", os.path.basename(path))
+ except KeyboardInterrupt:
+ raise
except:
- print "Cache is corrupted. Rescanning album."
+ message("corrupt cache", os.path.basename(path))
cached_album = None
if not cached:
album = Album(path)
@@ -41,61 +46,70 @@ class TreeWalker:
continue
try:
entry = entry.decode(sys.getfilesystemencoding())
+ except KeyboardInterrupt:
+ raise
except:
pass
entry = os.path.join(path, entry)
if os.path.isdir(entry):
album.add_album(self.walk(entry))
elif not cached and os.path.isfile(entry):
+ next_level()
cache_hit = False
if cached_album:
cached_photo = cached_album.photo_from_path(entry)
if cached_photo and file_mtime(entry) <= cached_photo.attributes["dateTimeFile"]:
- print "Photo cache hit %s" % entry
+ message("cache hit", os.path.basename(entry))
cache_hit = True
photo = cached_photo
if not cache_hit:
- print "No cache, scanning %s" % entry
+ message("metainfo", os.path.basename(entry))
photo = Photo(entry, self.cache_path)
if photo.is_valid:
self.all_photos.append(photo)
album.add_photo(photo)
+ else:
+ message("unreadable", os.path.basename(entry))
+ back_level()
if not album.empty:
- print "Writing cache of %s" % album.cache_path
+ message("caching", os.path.basename(path))
album.cache(self.cache_path)
self.all_albums.append(album)
else:
- print "Not writing cache of %s because it's empty" % album.cache_path
+ message("empty", os.path.basename(path))
+ back_level()
return album
def big_lists(self):
photo_list = []
self.all_photos.sort()
for photo in self.all_photos:
photo_list.append(photo.path)
- print "Writing all photos list."
+ message("caching", "all photos path list")
fp = open(os.path.join(self.cache_path, "all_photos.json"), 'w')
json.dump(photo_list, fp, cls=PhotoAlbumEncoder)
fp.close()
photo_list.reverse()
- print "Writing latest photos list."
+ message("caching", "latest photos path list")
fp = open(os.path.join(self.cache_path, "latest_photos.json"), 'w')
json.dump(photo_list[0:27], fp, cls=PhotoAlbumEncoder)
fp.close()
def remove_stale(self):
- print "Building list of all cache entries."
+ message("cleanup", "building stale list")
all_cache_entries = { "all_photos.json": True, "latest_photos.json": True }
for album in self.all_albums:
all_cache_entries[album.cache_path] = True
for photo in self.all_photos:
for entry in photo.image_caches:
all_cache_entries[entry] = True
- print "Searching stale cache entries."
+ message("cleanup", "searching for stale cache entries")
for cache in os.listdir(self.cache_path):
try:
cache = cache.decode(sys.getfilesystemencoding())
+ except KeyboardInterrupt:
+ raise
except:
pass
if cache not in all_cache_entries:
- print "Removing stale cache %s" % cache
+ message("cleanup", os.path.basename(cache))
os.unlink(os.path.join(self.cache_path, cache))