tex2lyx roundtrip: Ignore the lyx-version which created

When comparing the contents of two lyx-files, we should not care about the specific version. Later, this can be extended to also not care whether the file is produced by tex2lyx, lyx2lyx, or LyX.

Modified-By: Vincent van Ravesteijn <vfr@lyx.org>
This commit is contained in:
Kornel Benko 2013-07-04 18:52:31 +02:00 committed by Vincent van Ravesteijn
parent 5bacf85b48
commit 39bef61e84

View File

@ -20,6 +20,16 @@ import os, string, sys, time, difflib, filecmp, subprocess, re
def usage(prog_name):
return "Usage: %s [uselyx2lyx] [<tex2lyx binary> [[<script dir>] [[<output dir>] [testfile]]]]" % prog_name
pat_fl = re.compile(r'^#LyX file created by tex2lyx .*$')
def compareLyx(lines1, lines2):
if lines1[1:] != lines2[1:]:
return False
if not pat_fl.match(lines1[0]):
return False
if not pat_fl.match(lines2[0]):
return False
return True
def main(argv):
# Parse and manipulate the command line arguments.
@ -102,19 +112,22 @@ def main(argv):
os.path.join(outputdir, base + ".lyx2.lyx"), uselyx2lyx)
if lyxfile2 is None:
errors.append(f)
elif not filecmp.cmp(lyxfile1, lyxfile2, False):
else:
t1 = time.ctime(os.path.getmtime(lyxfile1))
t2 = time.ctime(os.path.getmtime(lyxfile2))
f1 = open(lyxfile1, 'r')
f2 = open(lyxfile2, 'r')
lines1 = f1.readlines()
lines2 = f2.readlines()
diff = difflib.unified_diff(lines1, lines2, lyxfile1, lyxfile2, t1, t2)
f1.close()
f2.close()
# ignore the first line i.e., the version of lyx
if not compareLyx(lines1, lines2):
diff = difflib.unified_diff(lines1, lines2, lyxfile1, lyxfile2, t1, t2)
sys.stdout.writelines(diff)
errors.append(f)
if len(errors) > 0:
error('Converting the following files failed: %s' % ', '.join(errors))