aboutsummaryrefslogtreecommitdiffstats
path: root/TreeWalker.py
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2011-05-05 07:04:40 -0400
committerJason A. Donenfeld <Jason@zx2c4.com>2011-05-05 07:04:40 -0400
commitb195f769661d4178c964d7f9ac6abb8ed4bad101 (patch)
treeb496ad95503750fffc5ad1bca48740a492e031e8 /TreeWalker.py
downloadPhotoFloat-b195f769661d4178c964d7f9ac6abb8ed4bad101.tar.xz
PhotoFloat-b195f769661d4178c964d7f9ac6abb8ed4bad101.zip
Initial import.
Diffstat (limited to 'TreeWalker.py')
-rw-r--r--TreeWalker.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/TreeWalker.py b/TreeWalker.py
new file mode 100644
index 0000000..e894944
--- /dev/null
+++ b/TreeWalker.py
@@ -0,0 +1,35 @@
+import os
+import os.path
+from PhotoAlbum import Photo, Album, json_cache, set_cache_path_base
+
+class TreeWalker:
+ def __init__(self, album_path, cache_path):
+ self.album_path = album_path
+ self.cache_path = cache_path
+ set_cache_path_base(self.album_path)
+ self.all_albums = list()
+ self.all_photos = list()
+ self.walk(album_path)
+ self.remove_stale()
+ def walk(self, path):
+ cache = os.path.join(self.cache_path, json_cache(path))
+ cached = False
+ if os.path.exists(cache) and os.path.getmtime(path) <= os.path.getmtime(cache):
+ album = Album.from_cache(cache)
+ cached = True
+ else:
+ album = Album(path)
+ for entry in os.listdir(path):
+ 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):
+ photo = Photo(entry)
+ if photo.is_valid:
+ self.all_photos.append(photo)
+ album.add_photo(photo)
+ album.cache(self.cache_path)
+ self.all_albums.append(album)
+ return album
+ def remove_stale(self):
+ pass \ No newline at end of file