mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-12 22:14:35 +00:00
configure.py: Python 3 compatibility
Don't assume any encoding for the layout files and treat them in the same way python 2 does. Thanks José for the idea. This commit supersedes50e21b71
ande19b2a71
.
This commit is contained in:
parent
fab6ee2f4d
commit
8f70d55148
@ -9,7 +9,7 @@
|
|||||||
# Full author contact details are available in file CREDITS.
|
# Full author contact details are available in file CREDITS.
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import glob, logging, os, re, shutil, subprocess, sys, stat, io
|
import glob, logging, os, re, shutil, subprocess, sys, stat
|
||||||
|
|
||||||
# set up logging
|
# set up logging
|
||||||
logging.basicConfig(level = logging.DEBUG,
|
logging.basicConfig(level = logging.DEBUG,
|
||||||
@ -1337,9 +1337,9 @@ def checkLatexConfig(check_config, bool_docbook):
|
|||||||
# Construct the list of classes to test for.
|
# Construct the list of classes to test for.
|
||||||
# build the list of available layout files and convert it to commands
|
# build the list of available layout files and convert it to commands
|
||||||
# for chkconfig.ltx
|
# for chkconfig.ltx
|
||||||
declare = re.compile(r'^\s*#\s*\\Declare(LaTeX|DocBook)Class\s*(\[([^,]*)(,.*)*\])*\s*{(.*)}\s*$')
|
declare = re.compile(b'^\\s*#\\s*\\\\Declare(LaTeX|DocBook)Class\\s*(\[([^,]*)(,.*)*\])*\\s*{(.*)}\\s*$')
|
||||||
category = re.compile(r'^\s*#\s*\\DeclareCategory{(.*)}\s*$')
|
category = re.compile(b'^\\s*#\\s*\\\\DeclareCategory{(.*)}\\s*$')
|
||||||
empty = re.compile(r'^\s*$')
|
empty = re.compile(b'^\\s*$')
|
||||||
testclasses = list()
|
testclasses = list()
|
||||||
for file in (glob.glob( os.path.join('layouts', '*.layout') )
|
for file in (glob.glob( os.path.join('layouts', '*.layout') )
|
||||||
+ glob.glob( os.path.join(srcdir, 'layouts', '*.layout' ) ) ):
|
+ glob.glob( os.path.join(srcdir, 'layouts', '*.layout' ) ) ):
|
||||||
@ -1347,36 +1347,34 @@ def checkLatexConfig(check_config, bool_docbook):
|
|||||||
if not os.path.isfile(file):
|
if not os.path.isfile(file):
|
||||||
continue
|
continue
|
||||||
classname = file.split(os.sep)[-1].split('.')[0]
|
classname = file.split(os.sep)[-1].split('.')[0]
|
||||||
decline = ""
|
decline = b""
|
||||||
catline = ""
|
catline = b""
|
||||||
if os.name == 'nt':
|
for line in open(file, 'rb').readlines():
|
||||||
enco = sys.getfilesystemencoding()
|
if not empty.match(line) and line[0] != b'#'[0]:
|
||||||
else:
|
if decline == b"":
|
||||||
enco="utf8"
|
|
||||||
for line in io.open(file, encoding=enco).readlines():
|
|
||||||
if not empty.match(line) and line[0] != '#':
|
|
||||||
if decline == "":
|
|
||||||
logger.warning("Failed to find valid \Declare line "
|
logger.warning("Failed to find valid \Declare line "
|
||||||
"for layout file `%s'.\n\t=> Skipping this file!" % file)
|
"for layout file `%s'.\n\t=> Skipping this file!" % file)
|
||||||
nodeclaration = True
|
nodeclaration = True
|
||||||
# A class, but no category declaration. Just break.
|
# A class, but no category declaration. Just break.
|
||||||
break
|
break
|
||||||
if declare.search(line) != None:
|
if declare.search(line) != None:
|
||||||
decline = "\\TestDocClass{%s}{%s}" % (classname, line[1:].strip())
|
decline = b"\\TestDocClass{%s}{%s}" \
|
||||||
|
% (classname.encode('ascii'), line[1:].strip())
|
||||||
testclasses.append(decline)
|
testclasses.append(decline)
|
||||||
elif category.search(line) != None:
|
elif category.search(line) != None:
|
||||||
catline = ("\\DeclareCategory{%s}{%s}"
|
catline = (b"\\DeclareCategory{%s}{%s}"
|
||||||
% (classname, category.search(line).groups()[0]))
|
% (classname.encode('ascii'),
|
||||||
|
category.search(line).groups()[0]))
|
||||||
testclasses.append(catline)
|
testclasses.append(catline)
|
||||||
if catline == "" or decline == "":
|
if catline == b"" or decline == b"":
|
||||||
continue
|
continue
|
||||||
break
|
break
|
||||||
if nodeclaration:
|
if nodeclaration:
|
||||||
continue
|
continue
|
||||||
testclasses.sort()
|
testclasses.sort()
|
||||||
cl = io.open('chklayouts.tex', 'w', encoding=enco)
|
cl = open('chklayouts.tex', 'wb')
|
||||||
for line in testclasses:
|
for line in testclasses:
|
||||||
cl.write(line + '\n')
|
cl.write(line + b'\n')
|
||||||
cl.close()
|
cl.close()
|
||||||
#
|
#
|
||||||
# we have chklayouts.tex, then process it
|
# we have chklayouts.tex, then process it
|
||||||
|
Loading…
Reference in New Issue
Block a user