fix some unicode issues, and not-alive-dirs-in-subdirs-list issues
authorterom
Thu, 31 Jan 2008 17:58:03 +0000
changeset 27 301d738b1181
parent 26 81d6679d50d0
child 28 70b6c13d084f
fix some unicode issues, and not-alive-dirs-in-subdirs-list issues
degal.py
lib/folder.py
lib/image.py
lib/log.py
lib/utils.py
--- a/degal.py	Thu Jan 31 17:28:02 2008 +0000
+++ b/degal.py	Thu Jan 31 17:58:03 2008 +0000
@@ -27,7 +27,7 @@
 
 def main (dir='.', targets=()) :
     root_filter = {}
-
+    
     for target in targets :
         f = root_filter
         for path_part in target.split('/') :
--- a/lib/folder.py	Thu Jan 31 17:28:02 2008 +0000
+++ b/lib/folder.py	Thu Jan 31 17:58:03 2008 +0000
@@ -38,7 +38,7 @@
 class Folder (object) :
     def __init__ (self, name='.', parent=None) :
         # the directory name, no trailing /
-        self.name = name.rstrip(os.sep)
+        self.name = unicode(name.rstrip(os.sep))
 
         # our parent Folder, or None
         self.parent = parent
@@ -122,9 +122,10 @@
                 and (self.parent or fname not in settings.ROOT_IGNORE)
             ) :
                 index.debug("Found subdir %s", fpath)
-                f = self.subdirs[fname] = Folder(fname, self)
+                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
 
             # handle images
@@ -166,7 +167,7 @@
         self.title, self.descr = utils.readTitleDescr(title_path)
         
         # default title for the root dir
-        if self.title :
+        if self.title or self.descr :
             self.alive = True
             pass # use what was in the title file
             
@@ -176,8 +177,8 @@
         else :
             self.title = self.name
         
-        if self.descr :
-            self.alive = True
+        if not self.alive :
+            index.debug("Dir %s isn't alive" % self.path)
 
         return self.alive
 
--- a/lib/image.py	Thu Jan 31 17:28:02 2008 +0000
+++ b/lib/image.py	Thu Jan 31 17:58:03 2008 +0000
@@ -29,19 +29,19 @@
 class Image (object) :
     def __init__ (self, dir, name) :
         # the image filename, e.g. DSC3948.JPG
-        self.name = name
+        self.name = unicode(name)
 
         # the Folder object that we are in
         self.dir = dir
         
         # the relative path from the root to us
-        self.path = dir.pathFor(name)
+        self.path = dir.pathFor(self.name)
 
         # the basename+ext, e.g. DSCR3948, .JPG
-        self.base_name, self.ext = os.path.splitext(name)
+        self.base_name, self.ext = os.path.splitext(self.name)
         
         # our user-friendly title
-        self.title = name
+        self.title = self.name
 
         # our long-winded description
         self.descr = ''
--- a/lib/log.py	Thu Jan 31 17:28:02 2008 +0000
+++ b/lib/log.py	Thu Jan 31 17:58:03 2008 +0000
@@ -21,7 +21,7 @@
 import logging
 
 logging.basicConfig(
-    level=logging.DEBUG,
+    level=logging.INFO,
     format="%(message)s",
 #    format="%(name)8s %(levelname)8s   %(lineno)3d %(message)s",
 
--- a/lib/utils.py	Thu Jan 31 17:28:02 2008 +0000
+++ b/lib/utils.py	Thu Jan 31 17:58:03 2008 +0000
@@ -40,6 +40,12 @@
 
     return data
 
+def fuzzyDecode (bytes) :
+    try :
+        return bytes.decode('utf8')
+    except UnicodeDecodeError :
+        return bytes.decode('latin1', 'replace')
+
 def readTitleDescr (path) :
     """
         Read a title.txt or <imgname>.txt file
@@ -52,10 +58,12 @@
             title, descr = content.split('---', 1)
         else :
             title, descr = content, ''
+        
+        title, descr = fuzzyDecode(title), fuzzyDecode(descr)
 
         return title.strip(), descr.strip()
 
-    return "", ""
+    return u"", u""
 
 def url (*parts, **kwargs) :
     abs = kwargs.pop('abs', False)