+ (base, ext) = os.path.splitext(f)
+ texfile = os.path.join(inputdir, f)
+ if overwrite:
+ # we are updating the test references, so use roundtrip to allow
+ # for checking the LyX export as well.
+ cmd = '%s -roundtrip -f %s' % (tex2lyx, texfile)
+ else:
+ lyxfile = os.path.join(outputdir, base + ".lyx")
+ cmd = '%s -roundtrip -copyfiles -f %s %s' % (tex2lyx, texfile, lyxfile)
+ print 'Executing: ' + cmd + "\n"
+ proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ proc.wait()
+ err = proc.returncode
+ errorstring = proc.stderr.read()
+ if not errorstring is None:
+ print errorstring
+ if err != 0:
+ errors.append(f)
+ elif not overwrite:
+ lyxfile1 = getlyxinput(lyx,
+ os.path.join(inputdir, base + ".lyx.lyx"),
+ os.path.join(outputdir, base + ".lyx1.lyx") , uselyx2lyx)
+ if lyxfile1 is None:
+ errors.append(f)
+ else:
+ lyxfile2 = getlyxinput(lyx,
+ os.path.join(outputdir, base + ".lyx"),
+ os.path.join(outputdir, base + ".lyx2.lyx"), uselyx2lyx)
+ if lyxfile2 is None:
+ errors.append(f)
+ 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()
+ i1 = 0
+ for linex in lines1:
+ if linex[:-1] == '\origin ' + inputdir + '/':
+ lines1[i1] = '\origin ' + outputdir + '/' + "\n"
+ break
+ i1 = i1+1
+ lines2 = f2.readlines()
+ f1.close()
+ f2.close()
+ # ignore the first line e.g. 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))
+
+def getlyxinput(lyx, lyxfx, lyxf, uselyx2lyx):
+ if uselyx2lyx:
+ cmd = '%s -E lyx %s %s' % (lyx, lyxf, lyxfx)
+ sys.stdout.writelines(cmd)
+ sys.stdout.writelines("\n")