From 1cde9ae6d35de67eabded947b7e0bbf148574931 Mon Sep 17 00:00:00 2001 From: Valentin Villenave Date: Wed, 3 Mar 2010 12:02:09 +0100 Subject: [PATCH] convert-ly: fix bug with accented filenames converty-ly couldn't cope with accented filenames (reported by Nick Payne on Jan 4, 2010). This seems to do the trick (albeit in a probably non-orthodox way). Tested on MS Windows (Python 2.4) and GNU/Linux (Python 2.6). --- python/lilylib.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/python/lilylib.py b/python/lilylib.py index 3bdfa1c35c..9915cd7229 100644 --- a/python/lilylib.py +++ b/python/lilylib.py @@ -23,6 +23,7 @@ import re import shutil import sys import optparse +import locale ################################################################ # Users of python modules should include this snippet @@ -48,7 +49,9 @@ underscore = _ # Maybe guess encoding from LANG/LC_ALL/LC_CTYPE? def encoded_write(f, s): - f.write (s.encode (f.encoding or 'utf_8')) + f.write (s + .decode (sys.stderr.encoding or locale.getdefaultlocale()[1]) + .encode (f.encoding or 'utf_8')) # ugh, Python 2.5 optparse requires Unicode strings in some argument # functions, and refuse them in some other places @@ -68,7 +71,7 @@ please read 'Setup for MacOS X' in Application Usage.") os.system ("open http://python.org/download/") sys.exit (2) -# Modified version of the commands.mkarg(x), which always uses +# Modified version of the commands.mkarg(x), which always uses # double quotes (since Windows can't handle the single quotes: def mkarg(x): s = ' "' @@ -92,7 +95,7 @@ def subprocess_system (cmd, log_file=None): import subprocess - show_progress= progress_p + show_progress= progress_p name = command_name (cmd) error_log_file = '' @@ -171,7 +174,7 @@ def ossystem_system (cmd, system = subprocess_system if sys.platform == 'mingw32': - + ## subprocess x-compile doesn't work. system = ossystem_system @@ -194,7 +197,7 @@ def search_exe_path (name): def print_environment (): for (k,v) in os.environ.items (): - sys.stderr.write ("%s=\"%s\"\n" % (k, v)) + sys.stderr.write ("%s=\"%s\"\n" % (k, v)) class NonDentedHeadingFormatter (optparse.IndentedHelpFormatter): def format_heading(self, heading): @@ -221,7 +224,7 @@ class NonDentedHeadingFormatter (optparse.IndentedHelpFormatter): def format_description(self, description): return description -def get_option_parser (*args, **kwargs): +def get_option_parser (*args, **kwargs): p = optparse.OptionParser (*args, **kwargs) - p.formatter = NonDentedHeadingFormatter () + p.formatter = NonDentedHeadingFormatter () return p -- 2.39.2