]> git.lyx.org Git - lyx.git/commitdiff
Fix bug #8254: An encoding problem
authorEnrico Forestieri <forenr@lyx.org>
Wed, 18 Jul 2012 20:20:46 +0000 (22:20 +0200)
committerEnrico Forestieri <forenr@lyx.org>
Wed, 18 Jul 2012 20:20:46 +0000 (22:20 +0200)
Use the short version of a path, which is guaranteed to be ascii and
works even if the path is not encodable in the current codepage.

lib/configure.py

index 2379b35ef4bb0e22ccfad13224490eea2717c8e2..168b3796c6f8a4e6ab53c7a4f3537112d7e3802e 100644 (file)
@@ -62,7 +62,7 @@ def cmdOutput(cmd):
     '''
     if os.name == 'nt':
         b = False
-        cmd = 'cmd /d /c pushd ' + os.getcwd() + '&' + cmd
+        cmd = 'cmd /d /c pushd ' + shortPath(os.getcwdu()) + '&' + cmd
     else:
         b = True
     pipe = subprocess.Popen(cmd, shell=b, close_fds=b, stdin=subprocess.PIPE, \
@@ -73,6 +73,18 @@ def cmdOutput(cmd):
     return output.strip()
 
 
+def shortPath(path):
+    ''' On Windows, return the short version of "path" if possible '''
+    if os.name == 'nt':
+        from ctypes import windll, create_unicode_buffer
+        GetShortPathName = windll.kernel32.GetShortPathNameW
+        shortlen = GetShortPathName(path, 0, 0)
+        shortpath = create_unicode_buffer(shortlen)
+        if GetShortPathName(path, shortpath, shortlen):
+            return shortpath.value
+    return path
+
+
 def setEnviron():
     ''' I do not really know why this is useful, but we might as well keep it.
         NLS nuisances.
@@ -110,18 +122,10 @@ def checkTeXPaths():
         fd, tmpfname = mkstemp(suffix='.ltx')
         if os.name == 'nt':
             from locale import getdefaultlocale
-            from ctypes import windll, create_unicode_buffer
-            GetShortPathName = windll.kernel32.GetShortPathNameW
             language, encoding = getdefaultlocale()
             if encoding == None:
                 encoding = 'latin1'
-            longname = unicode(tmpfname, encoding)
-            shortlen = GetShortPathName(longname, 0, 0)
-            shortname = create_unicode_buffer(shortlen)
-            if GetShortPathName(longname, shortname, shortlen):
-                inpname = shortname.value.replace('\\', '/')
-            else:
-                inpname = tmpfname.replace('\\', '/')
+            inpname = shortPath(unicode(tmpfname, encoding)).replace('\\', '/')
         else:
             inpname = cmdOutput('cygpath -m ' + tmpfname)
         logname = os.path.basename(re.sub("(?i).ltx", ".log", inpname))