Commit 3e0b3c0e authored by Daniel Liew's avatar Daniel Liew Committed by Dan Liew
Browse files

Modified ktest-tool so that it is compatible with python3.


WARNING: Not tested!
parent 18141336
......@@ -13,21 +13,21 @@ class KTest:
def fromfile(path):
if not os.path.exists(path):
print "ERROR: file %s not found" % (path)
print("ERROR: file %s not found" % (path))
f = open(path,'rb')
hdr =
if len(hdr)!=5 or (hdr!='KTEST' and hdr != "BOUT\n"):
raise KTestError,'unrecognized file'
if len(hdr)!=5 or (hdr!=b'KTEST' and hdr != b"BOUT\n"):
raise KTestError('unrecognized file')
version, = struct.unpack('>i',
if version > version_no:
raise KTestError,'unrecognized version'
raise KTestError('unrecognized version')
numArgs, = struct.unpack('>i',
args = []
for i in range(numArgs):
size, = struct.unpack('>i',
if version >= 2:
symArgvs, = struct.unpack('>i',
......@@ -93,27 +93,27 @@ def main(args):
for file in args:
b = KTest.fromfile(file)
pos = 0
print 'ktest file : %r' % file
print 'args : %r' % b.args
print 'num objects: %r' % len(b.objects)
print('ktest file : %r' % file)
print('args : %r' % b.args)
print('num objects: %r' % len(b.objects))
for i,(name,data) in enumerate(b.objects):
if opts.trimZeros:
str = trimZeros(data)
str = data
print 'object %4d: name: %r' % (i, name)
print 'object %4d: size: %r' % (i, len(data))
print('object %4d: name: %r' % (i, name))
print('object %4d: size: %r' % (i, len(data)))
if opts.writeInts and len(data) == 4:
print 'object %4d: data: %r' % (i, struct.unpack('i',str)[0])
print ('object %4d: data: %r' % (i, struct.unpack('i',str)[0]))
elif opts.writeFloats and len(data) == 4:
print 'object %4d: data: %r' % (i, struct.unpack('f',str)[0])
print ('object %4d: data: %r' % (i, struct.unpack('f',str)[0]))
elif opts.writeFloats and len(data) == 8:
print 'object %4d: data: %r' % (i, struct.unpack('d',str)[0])
print ('object %4d: data: %r' % (i, struct.unpack('d',str)[0]))
print 'object %4d: data: %r' % (i, str)
print('object %4d: data: %r' % (i, str))
if file != args[-1]:
if __name__=='__main__':
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment