mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-26 03:11:59 +00:00
Update scripts to support simultaneously python 2 and 3
The fixes are simple and on line with the changes made during the 2.3 development. It was an oversight to leave them out. With this commit all the python scripts should be supported by python 2 and 3.
This commit is contained in:
parent
9b821eb047
commit
1084e30f10
@ -16,8 +16,11 @@
|
|||||||
# replacement in ~/.lyx/scripts
|
# replacement in ~/.lyx/scripts
|
||||||
|
|
||||||
# converts an image $2 (format $1) to $4 (format $3)
|
# converts an image $2 (format $1) to $4 (format $3)
|
||||||
|
from __future__ import print_function
|
||||||
import os, re, sys
|
import os, re, sys
|
||||||
|
|
||||||
|
PY2 = sys.version_info[0] == 2
|
||||||
|
|
||||||
# We may need some extra options only supported by recent convert versions
|
# We may need some extra options only supported by recent convert versions
|
||||||
re_version = re.compile(r'^Version:.*ImageMagick\s*(\d*)\.(\d*)\.(\d*).*$')
|
re_version = re.compile(r'^Version:.*ImageMagick\s*(\d*)\.(\d*)\.(\d*).*$')
|
||||||
# imagemagick 7
|
# imagemagick 7
|
||||||
@ -31,6 +34,9 @@ if fout.close() != None:
|
|||||||
fout = os.popen('convert -version 2>&1')
|
fout = os.popen('convert -version 2>&1')
|
||||||
output = fout.readline()
|
output = fout.readline()
|
||||||
fout.close()
|
fout.close()
|
||||||
|
if not PY2:
|
||||||
|
output = output.decode()
|
||||||
|
|
||||||
version = re_version.match(output)
|
version = re_version.match(output)
|
||||||
|
|
||||||
# Imagemagick by default
|
# Imagemagick by default
|
||||||
@ -63,12 +69,12 @@ if sys.argv[1] == 'pdf' and (version >= 0x060206 or gm):
|
|||||||
if sys.argv[3] == 'ppm' and (im and version >= 0x060305 or gm):
|
if sys.argv[3] == 'ppm' and (im and version >= 0x060305 or gm):
|
||||||
opts = opts + ' -flatten'
|
opts = opts + ' -flatten'
|
||||||
|
|
||||||
# print >> sys.stdout, command, sys.argv[2], sys.argv[4]
|
# print (command, sys.argv[2], sys.argv[4], file= sys.stdout)
|
||||||
if (im or gm) and os.system(r'%s %s "%s" "%s"' % (command, opts, sys.argv[2], sys.argv[3] + ':' + sys.argv[4])) != 0:
|
if (im or gm) and os.system(r'%s %s "%s" "%s"' % (command, opts, sys.argv[2], sys.argv[3] + ':' + sys.argv[4])) != 0:
|
||||||
print >> sys.stderr, sys.argv[0], 'ERROR'
|
print (sys.argv[0], 'ERROR', file= sys.stderr)
|
||||||
print >> sys.stderr, ('Execution of "%s" failed.' % command)
|
print ('Execution of "%s" failed.' % command, file= sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
elif not im and not gm and sys.platform == 'darwin' and os.system(r'%s "%s" "%s"' % (command, sys.argv[2], sys.argv[4])) != 0:
|
elif not im and not gm and sys.platform == 'darwin' and os.system(r'%s "%s" "%s"' % (command, sys.argv[2], sys.argv[4])) != 0:
|
||||||
print >> sys.stderr, sys.argv[0], 'ERROR'
|
print (sys.argv[0], 'ERROR', file= sys.stderr)
|
||||||
print >> sys.stderr, ('Execution of "%s" failed.' % command)
|
print ('Execution of "%s" failed.' % command, file= sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
# This script will convert a chess position in the FEN
|
# This script will convert a chess position in the FEN
|
||||||
# format to an ascii representation of the position.
|
# format to an ascii representation of the position.
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
import sys,string,os
|
import sys,string,os
|
||||||
|
|
||||||
os.close(0)
|
os.close(0)
|
||||||
@ -26,7 +27,7 @@ comp=string.split(line,'/')
|
|||||||
cont=1
|
cont=1
|
||||||
margin= " "*6
|
margin= " "*6
|
||||||
|
|
||||||
print margin+' +'+"-"*15+'+'
|
print (margin+' +'+"-"*15+'+')
|
||||||
for i in range(8):
|
for i in range(8):
|
||||||
cont = cont + 1
|
cont = cont + 1
|
||||||
tmp=""
|
tmp=""
|
||||||
@ -42,7 +43,7 @@ for i in range(8):
|
|||||||
cont = cont + 1
|
cont = cont + 1
|
||||||
|
|
||||||
row = 8 - i
|
row = 8 - i
|
||||||
print margin, row, tmp+"|"
|
print (margin, row, tmp+"|")
|
||||||
|
|
||||||
print margin+' +'+"-"*15+'+'
|
print (margin+' +'+"-"*15+'+')
|
||||||
print margin+' a b c d e f g h '
|
print (margin+' a b c d e f g h ')
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
# the real pdf file will be overwritten by a tex file named file.pdf.
|
# the real pdf file will be overwritten by a tex file named file.pdf.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
import os, sys, re
|
import os, sys, re
|
||||||
|
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ def runCommand(cmd):
|
|||||||
run a command, quit if fails
|
run a command, quit if fails
|
||||||
'''
|
'''
|
||||||
if os.system(cmd) != 0:
|
if os.system(cmd) != 0:
|
||||||
print "Command '%s' fails." % cmd
|
print("Command '%s' fails." % cmd)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
@ -78,15 +78,15 @@ else:
|
|||||||
# with tetex.
|
# with tetex.
|
||||||
epsfile = outbase + '.pstex'
|
epsfile = outbase + '.pstex'
|
||||||
tmp = mkstemp()
|
tmp = mkstemp()
|
||||||
boundingboxline = re.compile('%%BoundingBox:\s+(\d*)\s+(\d*)\s+(\d*)\s+(\d*)')
|
boundingboxline = re.compile(b'%%BoundingBox:\s+(\d*)\s+(\d*)\s+(\d*)\s+(\d*)')
|
||||||
for line in open(epsfile).xreadlines():
|
for line in open(epsfile, 'rb'):
|
||||||
if line[:13] == '%%BoundingBox':
|
if line[:13] == b'%%BoundingBox':
|
||||||
(llx, lly, urx, ury) = map(int, boundingboxline.search(line).groups())
|
(llx, lly, urx, ury) = list(map(int, boundingboxline.search(line).groups()))
|
||||||
width = urx - llx
|
width = urx - llx
|
||||||
height = ury - lly
|
height = ury - lly
|
||||||
xoffset = - llx
|
xoffset = - llx
|
||||||
yoffset = - lly
|
yoffset = - lly
|
||||||
tmp.write('''%%%%BoundingBox: 0 0 %d %d
|
tmp.write(b'''%%%%BoundingBox: 0 0 %d %d
|
||||||
<< /PageSize [%d %d] >> setpagedevice
|
<< /PageSize [%d %d] >> setpagedevice
|
||||||
gsave %d %d translate
|
gsave %d %d translate
|
||||||
''' % (width, height, width, height, xoffset, yoffset))
|
''' % (width, height, width, height, xoffset, yoffset))
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
# the real eps file will be overwritten by a tex file named file.eps.
|
# the real eps file will be overwritten by a tex file named file.eps.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
import os, sys
|
import os, sys
|
||||||
|
|
||||||
# We expect two args, the names of the input and output files.
|
# We expect two args, the names of the input and output files.
|
||||||
@ -45,5 +46,5 @@ outbase = os.path.splitext(output)[0]
|
|||||||
# Generate the PSTEX_T file
|
# Generate the PSTEX_T file
|
||||||
if os.system('fig2dev -Lpstex %s %s.eps' % (input, outbase)) != 0 or \
|
if os.system('fig2dev -Lpstex %s %s.eps' % (input, outbase)) != 0 or \
|
||||||
os.system('fig2dev -Lpstex_t -p%s %s %s' % (outbase, input, output)) != 0:
|
os.system('fig2dev -Lpstex_t -p%s %s %s' % (outbase, input, output)) != 0:
|
||||||
print 'fig2dev fails'
|
print ('fig2dev fails')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -17,14 +17,15 @@
|
|||||||
# picture files that are stored as relative paths are replaced
|
# picture files that are stored as relative paths are replaced
|
||||||
# with the absolute path.
|
# with the absolute path.
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
import os, sys
|
import os, sys
|
||||||
|
|
||||||
if len(sys.argv) != 3:
|
if len(sys.argv) != 3:
|
||||||
print >> sys.stderr, "Usage: fig_copy.py <from file> <to file>"
|
print ("Usage: fig_copy.py <from file> <to file>", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if not os.path.isfile(sys.argv[1]):
|
if not os.path.isfile(sys.argv[1]):
|
||||||
print >> sys.stderr, "Unable to read", sys.argv[1]
|
print ("Unable to read", sys.argv[1], file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
from_dir = os.path.split(os.path.realpath(sys.argv[1]))[0]
|
from_dir = os.path.split(os.path.realpath(sys.argv[1]))[0]
|
||||||
@ -45,14 +46,14 @@ import re
|
|||||||
# We're looking for a line of text that defines an entry of
|
# We're looking for a line of text that defines an entry of
|
||||||
# type '2' (a polyline), subtype '5' (an external picture file).
|
# type '2' (a polyline), subtype '5' (an external picture file).
|
||||||
# The line has 14 other data fields.
|
# The line has 14 other data fields.
|
||||||
patternline = re.compile(r'^\s*2\s+5(\s+[0-9.+-]+){14}\s*$')
|
patternline = re.compile(br'^\s*2\s+5(\s+[0-9.+-]+){14}\s*$')
|
||||||
emptyline = re.compile(r'^\s*$')
|
emptyline = re.compile(br'^\s*$')
|
||||||
commentline = re.compile(r'^\s*#.*$')
|
commentline = re.compile(br'^\s*#.*$')
|
||||||
# we allow space in path name
|
# we allow space in path name
|
||||||
figureline = re.compile(r'^(\s*[01]\s*)(\S[\S ]*)(\s*)$')
|
figureline = re.compile(br'^(\s*[01]\s*)(\S[\S ]*)(\s*)$')
|
||||||
|
|
||||||
input = open(sys.argv[1], 'r')
|
input = open(sys.argv[1], 'rb')
|
||||||
output = open(sys.argv[2], 'w')
|
output = open(sys.argv[2], 'wb')
|
||||||
|
|
||||||
# path in the fig is relative to this path
|
# path in the fig is relative to this path
|
||||||
os.chdir(from_dir)
|
os.chdir(from_dir)
|
||||||
@ -68,7 +69,7 @@ for line in input:
|
|||||||
found = False
|
found = False
|
||||||
elif patternline.match(line):
|
elif patternline.match(line):
|
||||||
found = True
|
found = True
|
||||||
print >> output, line,
|
output.write(line)
|
||||||
|
|
||||||
input.close()
|
input.close()
|
||||||
output.close()
|
output.close()
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#
|
#
|
||||||
# Please report any problems on the devel list.
|
# Please report any problems on the devel list.
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
import sys, os
|
import sys, os
|
||||||
|
|
||||||
class secbib:
|
class secbib:
|
||||||
@ -78,13 +79,13 @@ def InsertBib(fil, out):
|
|||||||
|
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
print r'''
|
print (r'''
|
||||||
Usage: python include_bib.py file.tex [outfile.tex]
|
Usage: python include_bib.py file.tex [outfile.tex]
|
||||||
Includes the contents of file.bbl, which must exist in the
|
Includes the contents of file.bbl, which must exist in the
|
||||||
same directory as file.tex, in place of the \bibliography
|
same directory as file.tex, in place of the \bibliography
|
||||||
command, and creates the new file outfile.tex. If no name
|
command, and creates the new file outfile.tex. If no name
|
||||||
for that file is given, we create: file-bbl.tex.
|
for that file is given, we create: file-bbl.tex.
|
||||||
'''
|
''')
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
args = len(sys.argv)
|
args = len(sys.argv)
|
||||||
@ -95,7 +96,7 @@ if __name__ == "__main__":
|
|||||||
# we might should make sure this is a tex file....
|
# we might should make sure this is a tex file....
|
||||||
infile = sys.argv[1]
|
infile = sys.argv[1]
|
||||||
if infile[-4:] != ".tex":
|
if infile[-4:] != ".tex":
|
||||||
print "Error: " + infile + " is not a TeX file"
|
print ("Error: " + infile + " is not a TeX file")
|
||||||
usage()
|
usage()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
@ -105,4 +106,4 @@ if __name__ == "__main__":
|
|||||||
outfile = infile[:-4] + "-bbl.tex"
|
outfile = infile[:-4] + "-bbl.tex"
|
||||||
|
|
||||||
newfile = InsertBib(infile, outfile)
|
newfile = InsertBib(infile, outfile)
|
||||||
print "Wrote " + outfile
|
print ("Wrote " + outfile)
|
||||||
|
@ -22,20 +22,21 @@ Bernard Michael Hurley <berhardh@westherts.ac.uk>
|
|||||||
modifications to original listerrors."""
|
modifications to original listerrors."""
|
||||||
__copyright__ = "Copyright 2002 - Kayvan A. Sylvan."
|
__copyright__ = "Copyright 2002 - Kayvan A. Sylvan."
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
import sys, string
|
import sys, string
|
||||||
|
|
||||||
def write_error(msg, tool = "noweb", line_number = 1):
|
def write_error(msg, tool = "noweb", line_number = 1):
|
||||||
"""Write out the given message in TeX error style.
|
"""Write out the given message in TeX error style.
|
||||||
|
|
||||||
called like: write_error(msg, tool, line_number)."""
|
called like: write_error(msg, tool, line_number)."""
|
||||||
print "! Build Error: ==> %s ==>\n" % (tool),
|
print ("! Build Error: ==> %s ==>" % tool)
|
||||||
print " ...\n\nl.%d ...\n" % (line_number),
|
print (" ...\n\nl.%d ..." % line_number)
|
||||||
if type(msg) == type("str"): # simple string
|
if type(msg) == type("str"): # simple string
|
||||||
print msg
|
print (msg)
|
||||||
else: # some kind of list (sequence or tuple)
|
else: # some kind of list (sequence or tuple)
|
||||||
for m in msg:
|
for m in msg:
|
||||||
if m != "": print m,
|
if m != "": print (m, end=" ")
|
||||||
print
|
print ()
|
||||||
|
|
||||||
__lines = [] # lines pushed back
|
__lines = [] # lines pushed back
|
||||||
|
|
||||||
@ -62,12 +63,13 @@ def main():
|
|||||||
|
|
||||||
Reads stdin and writes to stdout. Filter errors"""
|
Reads stdin and writes to stdout. Filter errors"""
|
||||||
|
|
||||||
while 1:
|
while True:
|
||||||
line = getline()
|
line = getline()
|
||||||
if line == "": break
|
if line == "": break
|
||||||
try_patterns_dispatch = [ noweb_try, gcc_try, xlc_try ]
|
try_patterns_dispatch = [ noweb_try, gcc_try, xlc_try ]
|
||||||
for predicate in try_patterns_dispatch:
|
for predicate in try_patterns_dispatch:
|
||||||
if predicate(line): break
|
if predicate(line): break
|
||||||
|
|
||||||
def noweb_try(line):
|
def noweb_try(line):
|
||||||
"""see if line is a noweb error.
|
"""see if line is a noweb error.
|
||||||
|
|
||||||
|
@ -52,6 +52,10 @@ def main(argv):
|
|||||||
latex_file = argv[3]
|
latex_file = argv[3]
|
||||||
latex_base, latex_ext = os.path.splitext(latex_file)
|
latex_base, latex_ext = os.path.splitext(latex_file)
|
||||||
|
|
||||||
|
# convert strings to bytes since we are using binary files
|
||||||
|
from_base = from_base.encode()
|
||||||
|
latex_base = latex_base.encode()
|
||||||
|
|
||||||
# Read the input file and write the output file
|
# Read the input file and write the output file
|
||||||
if(not os.path.isfile(abs_from_file)):
|
if(not os.path.isfile(abs_from_file)):
|
||||||
error("%s is not a valid file.\n" % abs_from_file)
|
error("%s is not a valid file.\n" % abs_from_file)
|
||||||
|
Loading…
Reference in New Issue
Block a user