# HG changeset patch # User terom # Date 1201802283 0 # Node ID 301d738b1181c4dbc7d433caecd2e7ea2326a322 # Parent 81d6679d50d08992177a01e92ba439e507df6671 fix some unicode issues, and not-alive-dirs-in-subdirs-list issues diff -r 81d6679d50d0 -r 301d738b1181 degal.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('/') : diff -r 81d6679d50d0 -r 301d738b1181 lib/folder.py --- 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 diff -r 81d6679d50d0 -r 301d738b1181 lib/image.py --- 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 = '' diff -r 81d6679d50d0 -r 301d738b1181 lib/log.py --- 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", diff -r 81d6679d50d0 -r 301d738b1181 lib/utils.py --- 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 .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)