]> git.lyx.org Git - features.git/commitdiff
Fix encoding of filenames in python scripts
authorEnrico Forestieri <forenr@lyx.org>
Wed, 10 Jan 2007 03:42:06 +0000 (03:42 +0000)
committerEnrico Forestieri <forenr@lyx.org>
Wed, 10 Jan 2007 03:42:06 +0000 (03:42 +0000)
* lib/scripts/fig2pstex.py
* lib/scripts/fig2pdftex.py
* lib/scripts/fig_copy.py
* lib/scripts/fen2ascii.py:
convert filenames from utf8 to the default locale encoding.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16635 a592a061-630c-0410-9148-cb99ea01b6c8

lib/scripts/fen2ascii.py
lib/scripts/fig2pdftex.py
lib/scripts/fig2pstex.py
lib/scripts/fig_copy.py

index 96bd6e0e1c93424e242ae33aabcd3e99e993740e..6a60964a9776f97cc6df4a14551a6b44d6d295c6 100644 (file)
@@ -1,4 +1,5 @@
 #! /usr/bin/env python
+# -*- coding: utf-8 -*-
 
 # file fen2ascii.py
 # This file is part of LyX, the document processor.
 # This script will convert a chess position in the FEN
 # format to an ascii representation of the position.
 
-import sys,string,os
+import sys, string, os, locale
+
+# We expect two args, the names of the input and output files.
+if len(sys.argv) != 3:
+    sys.exit(1)
+
+language, output_encoding = locale.getdefaultlocale()
+if output_encoding == None:
+    output_encoding = 'latin1'
+
+input = unicode(sys.argv[1], 'utf8').encode(output_encoding)
+output = unicode(sys.argv[2], 'utf8').encode(output_encoding)
 
 os.close(0)
 os.close(1)
-sys.stdin = open(sys.argv[1],"r")
-sys.stdout = open(sys.argv[2],"w")
+sys.stdin = open(input, "r")
+sys.stdout = open(output, "w")
 
 line = sys.stdin.readline()
 if line[-1] == '\n':
index 6f711bffbce6f2e26595b8e3ca840ef46000a718..19207d107baefe5e64ef280b3d3042045022361a 100644 (file)
@@ -28,7 +28,7 @@
 #
 
 
-import os, sys, re
+import os, sys, re, locale
 
 
 def runCommand(cmd):
@@ -44,7 +44,12 @@ def runCommand(cmd):
 if len(sys.argv) != 3:
     sys.exit(1)
 
-input, output = sys.argv[1:]
+language, output_encoding = locale.getdefaultlocale()
+if output_encoding == None:
+    output_encoding = 'latin1'
+
+input = unicode(sys.argv[1], 'utf8').encode(output_encoding)
+output = unicode(sys.argv[2], 'utf8').encode(output_encoding)
 
 # Fail silently if the file doesn't exist
 if not os.path.isfile(input):
index 1a559821a753649e1a0c0fb31ad967fef0cc6578..c474d1b09d780325f5cf469f46c1e43cff2ce35c 100644 (file)
 #   the real eps file will be overwritten by a tex file named file.eps.
 #
 
-import os, sys
+import os, sys, locale
 
 # We expect two args, the names of the input and output files.
 if len(sys.argv) != 3:
     sys.exit(1)
 
-input, output = sys.argv[1:]
+language, output_encoding = locale.getdefaultlocale()
+if output_encoding == None:
+    output_encoding = 'latin1'
+
+input = unicode(sys.argv[1], 'utf8').encode(output_encoding)
+output = unicode(sys.argv[2], 'utf8').encode(output_encoding)
 
 # Fail silently if the file doesn't exist
 if not os.path.isfile(input):
index 16ae154a4ea1c3403b86be8fa67638d35deedc8a..ac2948b5f7f3e542d1503f229bf9e167e3784f29 100644 (file)
 # picture files that are stored as relative paths are replaced
 # with the absolute path.
 
-import os, sys
+import os, sys, locale
 
 if len(sys.argv) != 3:
     print >> sys.stderr, "Usage: fig_copy.py <from file> <to file>"
     sys.exit(1)
 
-if not os.path.isfile(sys.argv[1]):
-    print >> sys.stderr, "Unable to read", sys.argv[1]
+language, output_encoding = locale.getdefaultlocale()
+if output_encoding == None:
+    output_encoding = 'latin1'
+
+from_file = unicode(sys.argv[1], 'utf8').encode(output_encoding)
+to_file = unicode(sys.argv[2], 'utf8').encode(output_encoding)
+
+if not os.path.isfile(from_file):
+    print >> sys.stderr, "Unable to read", from_file
     sys.exit(1)
 
-from_dir = os.path.split(os.path.realpath(sys.argv[1]))[0]
-to_dir = os.path.split(os.path.realpath(sys.argv[2]))[0]
+from_dir = os.path.split(os.path.realpath(from_file))[0]
+to_dir = os.path.split(os.path.realpath(to_file))[0]
 
 # The work is trivial if "to" and "from" are in the same directory.
 if from_dir == to_dir:
     import shutil
     try:
-        shutil.copy(sys.argv[1], sys.argv[2])
+        shutil.copy(from_file, to_file)
     except:
         sys.exit(1)
     sys.exit(0)
@@ -52,8 +59,8 @@ commentline = re.compile(r'^\s*#.*$')
 # we allow space in path name
 figureline  = re.compile(r'^(\s*[01]\s*)(\S[\S ]*)(\s*)$')
 
-input = open(sys.argv[1], 'r')
-output = open(sys.argv[2], 'w')
+input = open(from_file, 'r')
+output = open(to_file, 'w')
 
 # path in the fig is relative to this path
 os.chdir(from_dir)