lib/folder.py
changeset 28 70b6c13d084f
parent 27 301d738b1181
child 30 b1d5c32ab771
--- a/lib/folder.py	Thu Jan 31 17:58:03 2008 +0000
+++ b/lib/folder.py	Thu Jan 31 19:13:00 2008 +0000
@@ -20,8 +20,7 @@
 
 import os, os.path
 
-import settings, image, utils, helpers
-from log import index, render
+import settings, image, utils, helpers, log
 from template import gallery as gallery_tpl
 from helpers import url_for_page
 
@@ -91,8 +90,6 @@
             method.
         """
 
-        index.info("Indexing %s", self.path)
-
         if filters :
             self.filtered = True
         
@@ -103,7 +100,7 @@
             
             # ignore dotfiles
             if fname.startswith('.') :
-                index.debug("Skipping dotfile %s", fname)
+                log.debug("Skipping dotfile %s", fname)
                 continue
             
             # apply filters
@@ -111,7 +108,7 @@
                 if fname in filters :
                     next_filter = filters[fname]
                 else :
-                    index.debug("Skip `%s' as we have a filter", fname)
+                    log.debug("Skip `%s' as we have a filter", fname)
                     continue
             else :
                 next_filter = None
@@ -121,21 +118,25 @@
                 and (fname not in (settings.THUMB_DIR, settings.PREVIEW_DIR))
                 and (self.parent or fname not in settings.ROOT_IGNORE)
             ) :
-                index.debug("Found subdir %s", fpath)
+                log.down(fname)
+
                 f = Folder(fname, self)
+
                 if f.index(next_filter) :   # recursion
                     # if a subdir is alive, we are alive as well
                     self.subdirs[fname] = f
                     self.alive = True
 
+                log.up()
+
             # handle images
             elif os.path.isfile(fpath) and utils.isImage(fname) :
-                index.debug("Found image %s", fname)
+                log.next(fname)
                 self.images[fname] = image.Image(self, fname)
 
             # ignore everything else
             else :
-                index.debug("Ignoring file %s", fname)
+                log.debug("Ignoring file %s", fname)
         
         # sort and link the images
         if self.images :
@@ -178,7 +179,7 @@
             self.title = self.name
         
         if not self.alive :
-            index.debug("Dir %s isn't alive" % self.path)
+            log.debug("Dir %s isn't alive" % self.path)
 
         return self.alive
 
@@ -240,12 +241,19 @@
         
         # ded folders are skipped
         if not self.alive :
-            render.info("Skipping dir %s (no images)", self.path)
+            # dead, skip, no output
             return
         
+        index_mtime = utils.mtime(self.pathFor("index.html"))
+        dir_mtime = utils.mtime(self.path)
+
         # if this dir's contents were filtered out, then we can't render the index.html, as we aren't aware of all the images in here
         if self.filtered :
-            render.warning("Dir `%s' contents were filtered, so we won't render the gallery index again", self.path)
+            log.warning("Dir `%s' contents were filtered, so we won't render the gallery index again", self.path)
+
+        elif index_mtime > dir_mtime :
+            # no changes, pass, ignored
+            pass
 
         else :  
             # create the thumb/preview dirs if needed
@@ -253,15 +261,13 @@
                 path = self.pathFor(dir)
 
                 if not os.path.isdir(path) :
-                    render.info("Creating dir %s", path)
+                    log.info("mkdir %s", dir)
                     os.mkdir(path)
 
             # sort the subdirs
             subdirs = self.subdirs.values()
             subdirs.sort(key=lambda d: d.name)
             
-            render.info("Rendering %s", self.path)
-
             # paginate!
             images = self.sorted_images
             image_count = len(images)
@@ -274,9 +280,9 @@
             pagination_required = len(pages) > 1
 
             if pagination_required :
-                render.info("Index split into %d pages of %d images each", len(pages), settings.IMAGE_COUNT)
+                log.info("%d pages @ %d images", len(pages), settings.IMAGE_COUNT)
             elif not pages :
-                render.info("Dir with no images, render for subdirs")
+                log.info("no images, render for subdirs")
                 pages = [[]]
 
             for cur_page, images in enumerate(pages) :
@@ -302,12 +308,19 @@
                     shorturl                     = self.inRoot('s', shorturl),
                     shorturl_code                = shorturl,
                 )
-        
+
         # render images
-        for img in self.images.itervalues() :
+        image_count = len(self.sorted_images)
+        for i, img in enumerate(self.images.itervalues()) :
+            log.next("[%-4d/%4d] %s", i, image_count, img.name)
+
             img.render()
         
         # recurse into subdirs
         for dir in self.subdirs.itervalues() :
+            log.down(dir.name)
+
             dir.render()
-                
+
+            log.up()
+