degal.py
changeset 11 27dac27d1a58
parent 10 e8143d784b77
child 12 c2d8e9a754a1
--- a/degal.py	Tue Nov 20 23:47:00 2007 +0000
+++ b/degal.py	Thu Dec 20 17:42:04 2007 +0000
@@ -41,13 +41,13 @@
 
 logging.basicConfig(
     level=logging.INFO,
-    format="%(name)8s %(levelname)8s   %(lineno)3d %(message)s",
+    format="%(message)s",
+#    format="%(name)8s %(levelname)8s   %(lineno)3d %(message)s",
 
 )
 
 tpl = logging.getLogger('tpl')
 index = logging.getLogger('index')
-prepare = logging.getLogger('prepare')
 render = logging.getLogger('render')
 
 tpl.setLevel(logging.WARNING)
@@ -239,7 +239,9 @@
             if os.path.isdir(fpath) and fname not in (THUMB_DIR, PREVIEW_DIR) :
                 index.debug("Found subdir %s", fpath)
                 f = self.subdirs[fname] = Folder(fname, self)
-                f.index(next_filter)   # recursion
+                if f.index(next_filter) :   # recursion
+                    # if a subdir is alive, we are alive as well
+                    self.alive = True
 
             # handle images
             elif os.path.isfile(fpath) and isImage(fname) :
@@ -249,45 +251,21 @@
             # ignore everything else
             else :
                 index.debug("Ignoring file %s", fname)
-
-    def prepare (self) :
-        """
-            Prepare the dir, i.e. sort+prepare the images, as well as recurse
-            into subdirs
-        """
-
-        prepare.info("Preparing dir %s", self.path)
         
-        # is this folder non-empty?
-        alive = False
+        # sort and link the images
+        if self.images :
+            self.alive = True
 
-        # only create thumbs/previews dirs if we have images in here
-        if self.images :
-            # folder is non-empty
-            alive = True
-            prepare.info("Have %d images", len(self.images))
-            
-            # create the thumb/preview dirs if needed
-            for dir in (THUMB_DIR, PREVIEW_DIR) :
-                prepare.debug("Checking for existance of %s dir", dir)
-                path = self.pathFor(dir)
-
-                if not os.path.isdir(path) :
-                    prepare.info("Creating dir %s", path)
-                    os.mkdir(path)
-            
             # sort the images
             fnames = self.images.keys()
             fnames.sort()
-            
+
             prev = None
-            
-            # link them together and prepare them
+
+            # link
             for fname in fnames :
                 img = self.images[fname]
 
-                prepare.debug("Linking %s <-> %s", prev, img)
-
                 img.prev = prev
 
                 if prev :
@@ -295,47 +273,10 @@
 
                 prev = img
                 
-                img.prepare()
-                
                 # add to the sorted images list
                 self.sorted_images.append(img)
-        
-        # prepare subdirs
-        if self.subdirs :
-            prepare.info("Have %d subdirs", len(self.subdirs))
-            
-            # just recurse into them, we're alive if one of them is
-            for dir in self.subdirs.itervalues() :
-                if dir.prepare() :
-                    alive = True
-
-        # figure out our title
-        title_path = self.pathFor(TITLE_FILE)
-        
-        title, descr = readTitleDescr(title_path)
 
-        if title :
-            prepare.info("Found title/descr")
-            self.title = title
-            self.descr = descr
-            alive = True
-        
-        # default title for the root dir
-        elif self.name == '.' :
-            self.title = 'Index'
-
-        else :
-            self.title = self.name
-
-        prepare.debug("Our title is '%s'", self.title)
-        
-        # lol ded
-        if not alive :
-            prepare.info("Dir %s is not alive", self.path)
-
-        self.alive = alive
-
-        return alive
+        return self.alive
 
     def getObjInfo (self) :
         """
@@ -398,7 +339,31 @@
         if self.filtered :
             render.warning("Dir `%s' contents were filtered, so we won't render the gallery index again", self.path)
 
-        else :
+        else :  
+            # create the thumb/preview dirs if needed
+            for dir in (THUMB_DIR, PREVIEW_DIR) :
+                path = self.pathFor(dir)
+
+                if not os.path.isdir(path) :
+                    render.info("Creating dir %s", path)
+                    os.mkdir(path)
+
+            # figure out our title
+            title_path = self.pathFor(TITLE_FILE)
+            
+            title, descr = readTitleDescr(title_path)
+
+            if title :
+                self.title = title
+                self.descr = descr
+            
+            # default title for the root dir
+            elif self.name == '.' :
+                self.title = 'Index'
+
+            else :
+                self.title = self.name
+
             # sort the subdirs
             subdirs = self.subdirs.items()
             subdirs.sort()
@@ -522,46 +487,6 @@
         self.series_act = "add"
         self.series_verb = "Add to"
     
-    def prepare (self) :
-        """
-            Generate the thumbnail/preview views if needed, get the image info, and look for the title
-        """
-
-        prepare.info("Preparing image %s", self.path)
-        
-        # stat the image file to get the filesize and mtime
-        st = os.stat(self.path)
-
-        self.filesize = st.st_size
-        self.timestamp = st.st_mtime
-        
-        # open the image in PIL to get image attributes + generate thumbnails
-        img = PIL.Image.open(self.path)
-
-        self.img_size = img.size
-
-        for out_path, geom in ((self.thumb_path, THUMB_GEOM), (self.preview_path, PREVIEW_GEOM)) :
-            # if it doesn't exist, or it's older than the image itself, generate
-            if not (os.path.exists(out_path) and os.stat(out_path).st_mtime > self.timestamp) :
-                prepare.info("Create thumbnailed image at %s with geom %s", out_path, geom)
-                
-                # XXX: is this the most efficient way to do this?
-                out_img = img.copy()
-                out_img.thumbnail(geom, resample=True)
-                out_img.save(out_path)
-        
-        # look for the metadata file
-        title_path = self.dir.pathFor(self.base_name + '.txt')
-        prepare.debug("Looking for title at %s", title_path)
-        
-        title, descr = readTitleDescr(title_path)
-
-        if title :
-            self.title = title
-            self.descr = descr
-
-            prepare.info("Found title `%s'", self.title)
-    
     def getObjInfo (self) :
         """
             Metadata for shorturl2.db
@@ -607,6 +532,36 @@
         """
             Write out the .html file
         """
+        
+        # stat the image file to get the filesize and mtime
+        st = os.stat(self.path)
+
+        self.filesize = st.st_size
+        self.timestamp = st.st_mtime
+        
+        # open the image in PIL to get image attributes + generate thumbnails
+        img = PIL.Image.open(self.path)
+
+        self.img_size = img.size
+
+        for out_path, geom in ((self.thumb_path, THUMB_GEOM), (self.preview_path, PREVIEW_GEOM)) :
+            # if it doesn't exist, or it's older than the image itself, generate
+            if not (os.path.exists(out_path) and os.stat(out_path).st_mtime > self.timestamp) :
+                render.info("Create thumbnailed image at %s with geom %s", out_path, geom)
+                
+                # XXX: is this the most efficient way to do this?
+                out_img = img.copy()
+                out_img.thumbnail(geom, resample=True)
+                out_img.save(out_path)
+        
+        # look for the metadata file
+        title_path = self.dir.pathFor(self.base_name + '.txt')
+        
+        title, descr = readTitleDescr(title_path)
+
+        if title :
+            self.title = title
+            self.descr = descr
 
         render.info("Rendering image %s", self.path)
 
@@ -721,7 +676,6 @@
 
     root = Folder()
     root.index(root_filter)
-    root.prepare()
     updateShorturlDb(root)
     root.render()