From 67545d8a1396e5bf1db1918788ee537a4a13a901 Mon Sep 17 00:00:00 2001 From: "beville@gmail.com" Date: Sun, 24 Feb 2013 18:56:29 +0000 Subject: [PATCH] Fixed issue where month_name creation was failing by not decoding date string from system git-svn-id: http://comictagger.googlecode.com/svn/trunk@527 6c5673fe-1810-88d6-992b-cd32ca31540c --- comictaggerlib/filerenamer.py | 4 +++- comictaggerlib/utils.py | 17 +++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/comictaggerlib/filerenamer.py b/comictaggerlib/filerenamer.py index 4ca2953..3b5bee3 100644 --- a/comictaggerlib/filerenamer.py +++ b/comictaggerlib/filerenamer.py @@ -21,6 +21,7 @@ limitations under the License. import os import re import datetime +import utils from issuestring import IssueString class FileRenamer: @@ -71,6 +72,7 @@ class FileRenamer: md = self.metdata new_name = self.template + preferred_encoding = utils.get_actual_preferred_encoding() #print u"{0}".format(md) @@ -93,7 +95,7 @@ class FileRenamer: if (type(md.month) == str and md.month.isdigit()) or type(md.month) == int: if int(md.month) in range(1,13): dt = datetime.datetime( 1970, int(md.month), 1, 0, 0) - month_name = dt.strftime("%B") + month_name = dt.strftime(u"%B".encode(preferred_encoding)).decode(preferred_encoding) new_name = self.replaceToken( new_name, month_name, '%month_name%') new_name = self.replaceToken( new_name, md.genre, '%genre%') diff --git a/comictaggerlib/utils.py b/comictaggerlib/utils.py index 0323115..75d960a 100644 --- a/comictaggerlib/utils.py +++ b/comictaggerlib/utils.py @@ -29,20 +29,21 @@ import codecs class UtilsVars: already_fixed_encoding = False +def get_actual_preferred_encoding(): + preferred_encoding = locale.getpreferredencoding() + if getattr(sys, 'frozen', None) and platform.system() == "Darwin": + preferred_encoding = "utf-8" + return preferred_encoding + def fix_output_encoding( ): if not UtilsVars.already_fixed_encoding: # this reads the environment and inits the right locale locale.setlocale(locale.LC_ALL, "") # try to make stdout/stderr encodings happy for unicode printing - preferred_encoding = locale.getpreferredencoding() - if getattr(sys, 'frozen', None) and platform.system() == "Darwin": - preferred_encoding = "utf-8" - sys.stdout = codecs.getwriter(preferred_encoding)(sys.stdout) - sys.stderr = codecs.getwriter(preferred_encoding)(sys.stderr) - elif platform.system() == "Windows": - sys.stdout = codecs.getwriter(preferred_encoding)(sys.stdout) - sys.stderr = codecs.getwriter(preferred_encoding)(sys.stderr) + preferred_encoding = get_actual_preferred_encoding() + sys.stdout = codecs.getwriter(preferred_encoding)(sys.stdout) + sys.stderr = codecs.getwriter(preferred_encoding)(sys.stderr) UtilsVars.already_fixed_encoding = True def get_recursive_filelist( pathlist ):