commit 6c9211aa40283164607b16034e9d2a8ce92ac1b8
Author: Enrico Forestieri
Date: Sat Feb 1 17:16:04 2025 +0100
Fix lyxpak.py on posix systems
Try to solve the mess between byte- and string-objects.
Fixes #13148.
---
lib/scripts/lyxpak.py | 58 +++
1 file changed, 31 insertions(+), 27 deletions(-)
diff --git a/lib/scripts/lyxpak.py b/lib/scripts/lyxpak.py
index 38cd4c62b8..306be08c16 100755
--- a/lib/scripts/lyxpak.py
+++ b/lib/scripts/lyxpak.py
@@ -31,7 +31,7 @@ else:
from getopt import getopt
# Pre-compiled regular expressions.
-re_lyxfile = re.compile(br"\.lyx$")
+re_lyxfile = re.compile(r"\.lyx$")
re_input = re.compile(b'^(.*)(input|include){(\\s*)(.+)(\\s*)}.*$')
re_ertinput = re.compile(b'^(input|include)({)(\\s*)(.+)(\\s*)}.*$')
re_package = re.compile(b'^(.*)(usepackage){(\\s*)(.+)(\\s*)}.*$')
@@ -68,12 +68,12 @@ def tostr(message):
def gzopen(file):
-input = open(file.decode('utf-8'), 'rb')
+input = open(file, 'rb')
magicnum = input.read(2)
input.close()
if magicnum == b"\x1f\x8b":
-return gzip.open(file.decode('utf-8'))
-return open(file.decode('utf-8'), 'rb')
+return gzip.open(file)
+return open(file, 'rb')
def find_exe(candidates, extlist, path):
@@ -106,7 +106,7 @@ def gather_files(curfile, incfiles, lyx2lyx):
# code page. So, we resort to running lyx2lyx on a copy.
tmp = NamedTemporaryFile(delete=False)
tmp.close()
-copyfile(curfile.decode('utf-8'), tmp.name)
+copyfile(curfile, tmp.name)
try:
l2l_stdout = subprocess.check_output([PYTHON_BIN, lyx2lyx,
tmp.name])
except subprocess.CalledProcessError:
@@ -134,7 +134,7 @@ def gather_files(curfile, incfiles, lyx2lyx):
while i < len(lines):
# Gather used files.
recursive = True
-extlist = [b'']
+extlist = ['']
match = re_filename.match(lines[i])
if not match:
if maybe_in_ert:
@@ -143,20 +143,20 @@ def gather_files(curfile, incfiles, lyx2lyx):
match = re_input.match(lines[i])
if not match:
match = re_package.match(lines[i])
-extlist = [b'.sty']
+extlist = ['.sty']
if not match:
match = re_class.match(lines[i])
-extlist = [b'.cls']
+extlist = ['.cls']
if not match:
if maybe_in_ert:
match = re_ertnorecur.match(lines[i])
else:
match = re_norecur.match(lines[i])
-extlist = [b'', b'.eps', b'.pdf', b'.png', b'.jpg']
+extlist = ['', '.eps', '.pdf', '.png', '.jpg']
recursive = False
maybe_in_ert = is_lyxfile and lines[i] == b"\\backslash"
if match:
-file = match.group(4).strip(b'"')
+file = tostr(match.group(4).strip(b'"'))
if not os.path.isabs(file):
file = os.path.join(curdir, file)
file_exists = False
@@ -180,12 +180,12 @@ def gather_files(curfile, incfiles, lyx2lyx):
# Gather bibtex *.bst files.
match = re_options.match(lines[i])
if match:
-file = match.group(3).strip(b'"')
-if file.startswith(b"bibtotoc,"):
+file = tostr(match.group(3).strip(b'"'))
+if file.startswith("bibtotoc,"):
file = file[9:]
ext = os.path.splitext(file)[-1]
-if ext != b'.bst':
-file = file + b'.bst'
+if ext != '.bst':
+file = file + '.bst'
if not os.path.isabs(file):
file = os.path.join(curdir, file)
if os.path.exists(file):
@@ -199,10 +199,10 @@ def gather_files(curfile, incfiles, lyx2lyx):
bibfiles = match.group(3).strip(b'"').split(b',')
j = 0
while j < len(bibfiles):
-file = bibfiles[j]
+file = tostr(bibfiles[j])
ext = os.path.splitext(file)[-1]
-if ext != b'.bib':
-file = file + b'.bib'
+if ext != '.bib':
+file = file + '.bib'
if not os.path.isabs(file):
file = os.path.join(curdir, file)
if os.path.exists(file):
@@ -297,27 +297,31 @@ def main(args):
if not os.path.isdir(outdir):
error('Error: "%s" is not a directory.' % outdir)
-lyxfile = argv[0]
+if running_on_windows:
+lyxfile = tostr(argv[0])
+else:
+lyxfile = argv[0]
+
if not os.path.exists(lyxfile):
-error('File "%s" not found.' % tostr(lyxfile))
+error('File "{lyxfile}" not fou