mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 10:00:33 +00:00
Handle encoding error in layout file parsing more gracefully
Issue a warning about non-decodable files, but do not break completely. Addresses #11736
This commit is contained in:
parent
b175f5a315
commit
c4da8d38c9
@ -1402,25 +1402,34 @@ def checkLatexConfig(check_config, bool_docbook):
|
|||||||
classname = file.split(os.sep)[-1].split('.')[0]
|
classname = file.split(os.sep)[-1].split('.')[0]
|
||||||
decline = ""
|
decline = ""
|
||||||
catline = ""
|
catline = ""
|
||||||
for line in open(file, 'r', encoding='utf8').readlines():
|
try:
|
||||||
if not empty.match(line) and line[0] != '#'[0]:
|
for line in open(file, 'r', encoding='utf8').readlines():
|
||||||
if decline == "":
|
if not empty.match(line) and line[0] != '#'[0]:
|
||||||
logger.warning("Failed to find valid \Declare line "
|
if decline == "":
|
||||||
"for layout file `%s'.\n\t=> Skipping this file!" % file)
|
logger.warning("Failed to find valid \Declare line "
|
||||||
nodeclaration = True
|
"for layout file `%s'.\n\t=> Skipping this file!" % file)
|
||||||
# A class, but no category declaration. Just break.
|
nodeclaration = True
|
||||||
|
# A class, but no category declaration. Just break.
|
||||||
|
break
|
||||||
|
if declare.match(line) != None:
|
||||||
|
decline = "\\TestDocClass{%s}{%s}" % (classname, line[1:].strip())
|
||||||
|
testclasses.append(decline)
|
||||||
|
elif category.match(line) != None:
|
||||||
|
catline = ("\\DeclareCategory{%s}{%s}"
|
||||||
|
% (classname, category.match(line).groups()[0]))
|
||||||
|
testclasses.append(catline)
|
||||||
|
if catline == "" or decline == "":
|
||||||
|
continue
|
||||||
break
|
break
|
||||||
if declare.match(line) != None:
|
if nodeclaration:
|
||||||
decline = "\\TestDocClass{%s}{%s}" % (classname, line[1:].strip())
|
|
||||||
testclasses.append(decline)
|
|
||||||
elif category.match(line) != None:
|
|
||||||
catline = ("\\DeclareCategory{%s}{%s}"
|
|
||||||
% (classname, category.match(line).groups()[0]))
|
|
||||||
testclasses.append(catline)
|
|
||||||
if catline == "" or decline == "":
|
|
||||||
continue
|
continue
|
||||||
break
|
except UnicodeDecodeError:
|
||||||
if nodeclaration:
|
logger.warning("**************************************************\n"
|
||||||
|
"Layout file '%s'\n"
|
||||||
|
"cannot be decoded in utf-8.\n"
|
||||||
|
"Please check if the file has the correct encoding.\n"
|
||||||
|
"Skipping this file!\n"
|
||||||
|
"**************************************************" % file)
|
||||||
continue
|
continue
|
||||||
testclasses.sort()
|
testclasses.sort()
|
||||||
cl = open('chklayouts.tex', 'w', encoding='utf8')
|
cl = open('chklayouts.tex', 'w', encoding='utf8')
|
||||||
|
Loading…
Reference in New Issue
Block a user