]> git.lyx.org Git - lyx.git/blobdiff - lib/scripts/lyxpreview_tools.py
Remove profiling.py
[lyx.git] / lib / scripts / lyxpreview_tools.py
index 93964083a5d8f604ea0b2f7586b409fe199d71aa..56ff33e38b168fed032ff4dc260446420672ff8e 100644 (file)
@@ -1,4 +1,3 @@
-
 # file lyxpreview_tools.py
 # This file is part of LyX, the document processor.
 # Licence details can be found in the file COPYING.
@@ -166,7 +165,7 @@ def run_command_win32(cmd):
         try:
             hr, buffer = win32file.ReadFile(stdout_r, 4096)
             if hr != winerror.ERROR_IO_PENDING:
-                data = data + buffer
+                data = data + str(buffer)
 
         except pywintypes.error as e:
             if e.args[0] != winerror.ERROR_BROKEN_PIPE:
@@ -294,14 +293,14 @@ def run_latex(latex, latex_file, bibtex = None):
         latex_status, latex_stdout = run_tex(latex, latex_file)
     # Rerun latex if necessary
     progress("Checking if a latex rerun is necessary")
-    if string_in_file("Warning: Citation", log_file):
+    if string_in_file("Warning: (Citation|Reference)", log_file):
         latex_status, latex_stdout = run_tex(latex, latex_file)
 
     return latex_status, latex_stdout
 
 
 def run_tex(tex, tex_file):
-    tex_call = '%s "%s"' % (tex, tex_file)
+    tex_call = f'{tex} "{tex_file}"'
 
     tex_status, tex_stdout = run_command(tex_call)
     if tex_status:
@@ -313,9 +312,10 @@ def run_tex(tex, tex_file):
 def string_in_file(string, infile):
     if not os.path.isfile(infile):
         return False
-    f = open(infile, 'r')
+    string_re = re.compile(string.encode())
+    f = open(infile, 'rb')
     for line in f.readlines():
-        if string in line:
+        if string_re.search(line):
             f.close()
             return True
     f.close()
@@ -325,15 +325,15 @@ def string_in_file(string, infile):
 # Returns a list of indexes of pages giving errors extracted from the latex log
 def check_latex_log(log_file):
 
-    error_re = re.compile("^! ")
-    snippet_re = re.compile("^Preview: Snippet ")
-    data_re = re.compile("([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)")
+    error_re = re.compile(b"^! ")
+    snippet_re = re.compile(b"^Preview: Snippet ")
+    data_re = re.compile(b"([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)")
 
     found_error = False
     error_pages = []
 
     try:
-        for line in open(log_file, 'r').readlines():
+        for line in open(log_file, 'rb').readlines():
             if not found_error:
                 match = error_re.match(line)
                 if match != None:
@@ -347,7 +347,7 @@ def check_latex_log(log_file):
                 found_error = False
                 match = data_re.search(line)
                 if match == None:
-                    error("Unexpected data in %s\n%s" % (log_file, line))
+                    error(f"Unexpected data in {log_file}\n{line}")
 
                 error_pages.append(int(match.group(1)))