]> git.donarmstrong.com Git - lilypond.git/commitdiff
convert-ly: fix bug with accented filenames
authorValentin Villenave <valentin@villenave.net>
Wed, 3 Mar 2010 11:02:09 +0000 (12:02 +0100)
committerValentin Villenave <valentin@villenave.net>
Wed, 3 Mar 2010 11:02:09 +0000 (12:02 +0100)
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

index 3bdfa1c35cb48a1b5b6c84ca96dac767f821d86e..9915cd72298f280370361a2ccc8c9fb02f582db3 100644 (file)
@@ -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