mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 10:00:33 +00:00
Make configure.py python3 compatible
This was done using 2to3 and manual tweaking afterwards to ensure that it works with python2 as well.
This commit is contained in:
parent
7328cc0cc0
commit
73a5e423bd
@ -8,6 +8,7 @@
|
|||||||
# \author Bo Peng
|
# \author Bo Peng
|
||||||
# Full author contact details are available in file CREDITS.
|
# Full author contact details are available in file CREDITS.
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
import glob, logging, os, re, shutil, subprocess, sys, stat
|
import glob, logging, os, re, shutil, subprocess, sys, stat
|
||||||
|
|
||||||
# set up logging
|
# set up logging
|
||||||
@ -65,7 +66,10 @@ def cmdOutput(cmd, async = False):
|
|||||||
'''
|
'''
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
b = False
|
b = False
|
||||||
cmd = 'cmd /d /c pushd ' + shortPath(os.getcwdu()) + '&' + cmd
|
if sys.version_info[0] < 3:
|
||||||
|
cmd = 'cmd /d /c pushd ' + shortPath(os.getcwdu()) + '&' + cmd
|
||||||
|
else:
|
||||||
|
cmd = 'cmd /d /c pushd ' + shortPath(os.getcwd()) + '&' + cmd
|
||||||
else:
|
else:
|
||||||
b = True
|
b = True
|
||||||
pipe = subprocess.Popen(cmd, shell=b, close_fds=b, stdin=subprocess.PIPE, \
|
pipe = subprocess.Popen(cmd, shell=b, close_fds=b, stdin=subprocess.PIPE, \
|
||||||
@ -117,13 +121,12 @@ def copy_tree(src, dst, preserve_symlinks=False, level=0):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
if not os.path.isdir(src):
|
if not os.path.isdir(src):
|
||||||
raise FileError, \
|
raise FileError("cannot copy tree '%s': not a directory" % src)
|
||||||
"cannot copy tree '%s': not a directory" % src
|
|
||||||
try:
|
try:
|
||||||
names = os.listdir(src)
|
names = os.listdir(src)
|
||||||
except os.error, (errno, errstr):
|
except os.error as oserror:
|
||||||
raise FileError, \
|
(errno, errstr) = oserror.args
|
||||||
"error listing files in '%s': %s" % (src, errstr)
|
raise FileError("error listing files in '%s': %s" % (src, errstr))
|
||||||
|
|
||||||
if not os.path.isdir(dst):
|
if not os.path.isdir(dst):
|
||||||
os.makedirs(dst)
|
os.makedirs(dst)
|
||||||
@ -197,7 +200,10 @@ def checkTeXPaths():
|
|||||||
language, encoding = getdefaultlocale()
|
language, encoding = getdefaultlocale()
|
||||||
if encoding == None:
|
if encoding == None:
|
||||||
encoding = 'latin1'
|
encoding = 'latin1'
|
||||||
inpname = shortPath(unicode(tmpfname, encoding)).replace('\\', '/')
|
if sys.version_info[0] < 3:
|
||||||
|
inpname = shortPath(unicode(tmpfname, encoding)).replace('\\', '/')
|
||||||
|
else:
|
||||||
|
inpname = shortPath(str(tmpfname, encoding)).replace('\\', '/')
|
||||||
else:
|
else:
|
||||||
inpname = cmdOutput('cygpath -m ' + tmpfname)
|
inpname = cmdOutput('cygpath -m ' + tmpfname)
|
||||||
logname = os.path.basename(re.sub("(?i).ltx", ".log", inpname))
|
logname = os.path.basename(re.sub("(?i).ltx", ".log", inpname))
|
||||||
@ -393,7 +399,7 @@ def addAlternatives(rcs, alt_type):
|
|||||||
if isinstance(alt_type, str):
|
if isinstance(alt_type, str):
|
||||||
alt_tokens = [alt_token % alt_type]
|
alt_tokens = [alt_token % alt_type]
|
||||||
else:
|
else:
|
||||||
alt_tokens = map(lambda s: alt_token % s, alt_type)
|
alt_tokens = [alt_token % s for s in alt_type]
|
||||||
for idxx in range(len(rcs)):
|
for idxx in range(len(rcs)):
|
||||||
if len(rcs) == 1:
|
if len(rcs) == 1:
|
||||||
m = r.match(rcs[0])
|
m = r.match(rcs[0])
|
||||||
@ -476,16 +482,19 @@ def checkInkscape():
|
|||||||
''' Check whether Inkscape is available and return the full path (Windows only) '''
|
''' Check whether Inkscape is available and return the full path (Windows only) '''
|
||||||
if os.name != 'nt':
|
if os.name != 'nt':
|
||||||
return 'inkscape'
|
return 'inkscape'
|
||||||
import _winreg
|
if sys.version_info[0] < 3:
|
||||||
aReg = _winreg.ConnectRegistry(None, _winreg.HKEY_CLASSES_ROOT)
|
import _winreg as winreg
|
||||||
|
else:
|
||||||
|
import winreg
|
||||||
|
aReg = winreg.ConnectRegistry(None, winreg.HKEY_CLASSES_ROOT)
|
||||||
try:
|
try:
|
||||||
aKey = _winreg.OpenKey(aReg, r"inkscape.svg\DefaultIcon")
|
aKey = winreg.OpenKey(aReg, r"inkscape.svg\DefaultIcon")
|
||||||
val = _winreg.QueryValueEx(aKey, "")
|
val = winreg.QueryValueEx(aKey, "")
|
||||||
return str(val[0]).split('"')[1].replace('.exe', '')
|
return str(val[0]).split('"')[1].replace('.exe', '')
|
||||||
except EnvironmentError:
|
except EnvironmentError:
|
||||||
try:
|
try:
|
||||||
aKey = _winreg.OpenKey(aReg, r"Applications\inkscape.exe\shell\open\command")
|
aKey = winreg.OpenKey(aReg, r"Applications\inkscape.exe\shell\open\command")
|
||||||
val = _winreg.QueryValueEx(aKey, "")
|
val = winreg.QueryValueEx(aKey, "")
|
||||||
return str(val[0]).split('"')[1].replace('.exe', '')
|
return str(val[0]).split('"')[1].replace('.exe', '')
|
||||||
except EnvironmentError:
|
except EnvironmentError:
|
||||||
return 'inkscape'
|
return 'inkscape'
|
||||||
@ -1201,7 +1210,7 @@ def processLayoutFile(file, bool_docbook):
|
|||||||
prereq_latex = checkForClassExtension(classname)
|
prereq_latex = checkForClassExtension(classname)
|
||||||
else:
|
else:
|
||||||
prereq_list = optAll[1:-1].split(',')
|
prereq_list = optAll[1:-1].split(',')
|
||||||
prereq_list = map(checkForClassExtension, prereq_list)
|
prereq_list = list(map(checkForClassExtension, prereq_list))
|
||||||
prereq_latex = ','.join(prereq_list)
|
prereq_latex = ','.join(prereq_list)
|
||||||
prereq_docbook = {'true':'', 'false':'docbook'}[bool_docbook]
|
prereq_docbook = {'true':'', 'false':'docbook'}[bool_docbook]
|
||||||
prereq = {'LaTeX':prereq_latex, 'DocBook':prereq_docbook}[classtype]
|
prereq = {'LaTeX':prereq_latex, 'DocBook':prereq_docbook}[classtype]
|
||||||
@ -1538,7 +1547,7 @@ if __name__ == '__main__':
|
|||||||
## Parse the command line
|
## Parse the command line
|
||||||
for op in sys.argv[1:]: # default shell/for list is $*, the options
|
for op in sys.argv[1:]: # default shell/for list is $*, the options
|
||||||
if op in [ '-help', '--help', '-h' ]:
|
if op in [ '-help', '--help', '-h' ]:
|
||||||
print '''Usage: configure [options]
|
print('''Usage: configure [options]
|
||||||
Options:
|
Options:
|
||||||
--help show this help lines
|
--help show this help lines
|
||||||
--keep-temps keep temporary files (for debug. purposes)
|
--keep-temps keep temporary files (for debug. purposes)
|
||||||
@ -1546,7 +1555,7 @@ Options:
|
|||||||
--without-latex-config do not run LaTeX to determine configuration
|
--without-latex-config do not run LaTeX to determine configuration
|
||||||
--with-version-suffix=suffix suffix of binary installed files
|
--with-version-suffix=suffix suffix of binary installed files
|
||||||
--binary-dir=directory directory of binary installed files
|
--binary-dir=directory directory of binary installed files
|
||||||
'''
|
''')
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
elif op == '--without-kpsewhich':
|
elif op == '--without-kpsewhich':
|
||||||
lyx_kpsewhich = False
|
lyx_kpsewhich = False
|
||||||
@ -1559,7 +1568,7 @@ Options:
|
|||||||
elif op[0:13] == '--binary-dir=':
|
elif op[0:13] == '--binary-dir=':
|
||||||
lyx_binary_dir = op[13:]
|
lyx_binary_dir = op[13:]
|
||||||
else:
|
else:
|
||||||
print "Unknown option", op
|
print("Unknown option %s" % op)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
#
|
#
|
||||||
# check if we run from the right directory
|
# check if we run from the right directory
|
||||||
|
Loading…
Reference in New Issue
Block a user