test script: batch roundtripper

git-svn-id: svn://svn.code.sf.net/p/fonttools/code/trunk@261 4cde692c-a291-49d1-8350-778aa11640f8
This commit is contained in:
jvr 2002-05-24 18:36:57 +00:00
parent 1872557451
commit 91df98b41f

71
Tools/ttroundtrip Executable file
View File

@ -0,0 +1,71 @@
#! /usr/bin/env python
"""ttroundtrip font1 ... fontN
Dump each font as TTX, compile again to TTF or OTF and dump again.
Then do a diff on the two TTX files. Log problems and diffs to a
file called "report.txt" in the current directory. This is only
for testing FontTools/TTX, the resulting files are deleted
afterwards."""
import sys
import os
import tempfile
report = open("report.txt", "w")
class Error(Exception): pass
def doCommand(cmd, verbose=1, okresult=None):
print "--> ", cmd
f = os.popen(cmd)
lines = []
for line in f:
if verbose:
sys.stdout.write(line)
lines.append(line)
result = os.wait()[1] >> 8
if result and result <> okresult:
raise Error, result
return "".join(lines)
if not sys.argv[1:]:
print __doc__
else:
for ttFile in sys.argv[1:]:
print "--- roundtripping %s ---" % ttFile
fn = os.path.basename(ttFile)
xmlFile1 = tempfile.mktemp(".%s.ttx1" % fn)
ttFile2 = tempfile.mktemp(".%s" % fn)
xmlFile2 = tempfile.mktemp(".%s.ttx2" % fn)
try:
cmd = 'ttdump -i -f "%s" "%s"' % (ttFile, xmlFile1)
doCommand(cmd, 0)
cmd = 'ttcompile -f "%s" "%s"' % (xmlFile1, ttFile2)
doCommand(cmd, 0)
cmd = 'ttdump -i -f "%s" "%s"' % (ttFile2, xmlFile2)
doCommand(cmd, 0)
cmd = 'diff -c2 -I ".*modified value\|checkSumAdjustment.*" "%s" "%s"' % (xmlFile1, xmlFile2)
diff = doCommand(cmd, 0, okresult=1)
if diff:
report.write("=============================================================\n")
report.write("%s\n" % xmlFile1)
report.write("%s\n" % xmlFile2)
report.write("-------------------------------------------------------------\n")
report.write(diff)
print diff
print "--- done ---"
except Error, why:
report.write("=============================================================\n")
report.write("%s\n" % ttFile)
report.write("*** round tripping aborted (code %s) ***\n" % why)
report.write("-------------------------------------------------------------\n")
print "*** round tripping aborted (code %s) ***" % why
for tmpFile in (xmlFile1, ttFile2, xmlFile2):
if os.path.exists(tmpFile):
os.remove(tmpFile)