Browse Source

Filenames and dirnames should always be unicode (ref #16).

pull/17/merge
Simon Conseil 13 years ago
parent
commit
fea6a98cb0
  1. 15
      sigal/gallery.py
  2. 4
      sigal/image.py

15
sigal/gallery.py

@ -23,6 +23,7 @@
from __future__ import absolute_import
import codecs
import locale
import logging
import markdown
import os
@ -49,10 +50,18 @@ class PathsDb(object):
"""
def __init__(self, path, ext_list):
self.basepath = path
self.ext_list = ext_list
self.logger = logging.getLogger(__name__)
# basepath must to be a unicode string so that os.walk will return
# unicode dirnames and filenames. If basepath is a str, we must
# convert it to unicode.
if isinstance(path, str):
enc = locale.getpreferredencoding()
self.basepath = path.decode(enc)
else:
self.basepath = path
def get_subdirs(self, path):
"""Return the list of all sub-directories of path."""
@ -78,8 +87,8 @@ class PathsDb(object):
relpath = os.path.relpath(path, self.basepath)
# sort images and sub-albums by name
filenames.sort(key=str.lower)
dirnames.sort(key=str.lower)
filenames.sort(cmp=locale.strcoll)
dirnames.sort(cmp=locale.strcoll)
self.db['paths_list'].append(relpath)
self.db[relpath] = {

4
sigal/image.py

@ -64,7 +64,7 @@ def generate_image(source, outname, size, format, options=None,
add_copyright(img, copyright_text)
format = format or img.format or original_format or 'JPEG'
logger.debug('Save resized image to {0} ({1})'.format(outname, format))
logger.debug(u'Save resized image to {0} ({1})'.format(outname, format))
save_image(img, outname, format, options=options, autoconvert=autoconvert)
@ -81,7 +81,7 @@ def generate_thumbnail(source, outname, box, format, fit=True, options=None):
img.thumbnail(box, PILImage.ANTIALIAS)
format = format or img.format or original_format or 'JPEG'
logger.debug('Save thumnail image to {0} ({1})'.format(outname, format))
logger.debug(u'Save thumnail image to {0} ({1})'.format(outname, format))
save_image(img, outname, format, options=options, autoconvert=True)

Loading…
Cancel
Save