Commit 17298b2d by Ray Glover Committed by Dominic Hamon

Python 2/3 compatibility (#361)

* [tools] python 2/3 support * update authors/contributors
parent 0dbcdf56
...@@ -18,6 +18,7 @@ Eugene Zhuk <eugene.zhuk@gmail.com> ...@@ -18,6 +18,7 @@ Eugene Zhuk <eugene.zhuk@gmail.com>
Evgeny Safronov <division494@gmail.com> Evgeny Safronov <division494@gmail.com>
Felix Homann <linuxaudio@showlabor.de> Felix Homann <linuxaudio@showlabor.de>
Google Inc. Google Inc.
International Business Machines Corporation
Ismael Jimenez Martinez <ismael.jimenez.martinez@gmail.com> Ismael Jimenez Martinez <ismael.jimenez.martinez@gmail.com>
Joao Paulo Magalhaes <joaoppmagalhaes@gmail.com> Joao Paulo Magalhaes <joaoppmagalhaes@gmail.com>
JianXiong Zhou <zhoujianxiong2@gmail.com> JianXiong Zhou <zhoujianxiong2@gmail.com>
......
...@@ -48,6 +48,7 @@ Pascal Leroy <phl@google.com> ...@@ -48,6 +48,7 @@ Pascal Leroy <phl@google.com>
Paul Redmond <paul.redmond@gmail.com> Paul Redmond <paul.redmond@gmail.com>
Pierre Phaneuf <pphaneuf@google.com> Pierre Phaneuf <pphaneuf@google.com>
Radoslav Yovchev <radoslav.tm@gmail.com> Radoslav Yovchev <radoslav.tm@gmail.com>
Ray Glover <ray.glover@uk.ibm.com>
Shuo Chen <chenshuo@chenshuo.com> Shuo Chen <chenshuo@chenshuo.com>
Yusuke Suzuki <utatane.tea@gmail.com> Yusuke Suzuki <utatane.tea@gmail.com>
Tobias Ulvgård <tobias.ulvgard@dirac.se> Tobias Ulvgård <tobias.ulvgard@dirac.se>
......
...@@ -59,7 +59,7 @@ def main(): ...@@ -59,7 +59,7 @@ def main():
json1 = gbench.util.run_or_load_benchmark(test1, benchmark_options) json1 = gbench.util.run_or_load_benchmark(test1, benchmark_options)
json2 = gbench.util.run_or_load_benchmark(test2, benchmark_options) json2 = gbench.util.run_or_load_benchmark(test2, benchmark_options)
output_lines = gbench.report.generate_difference_report(json1, json2) output_lines = gbench.report.generate_difference_report(json1, json2)
print 'Comparing %s to %s' % (test1, test2) print('Comparing %s to %s' % (test1, test2))
for ln in output_lines: for ln in output_lines:
print(ln) print(ln)
......
...@@ -132,7 +132,7 @@ class TestReportDifference(unittest.TestCase): ...@@ -132,7 +132,7 @@ class TestReportDifference(unittest.TestCase):
json1, json2 = self.load_results() json1, json2 = self.load_results()
output_lines_with_header = generate_difference_report(json1, json2, use_color=False) output_lines_with_header = generate_difference_report(json1, json2, use_color=False)
output_lines = output_lines_with_header[2:] output_lines = output_lines_with_header[2:]
print "\n".join(output_lines_with_header) print("\n".join(output_lines_with_header))
self.assertEqual(len(output_lines), len(expect_lines)) self.assertEqual(len(output_lines), len(expect_lines))
for i in xrange(0, len(output_lines)): for i in xrange(0, len(output_lines)):
parts = [x for x in output_lines[i].split(' ') if x] parts = [x for x in output_lines[i].split(' ') if x]
......
...@@ -20,21 +20,21 @@ def is_executable_file(filename): ...@@ -20,21 +20,21 @@ def is_executable_file(filename):
""" """
if not os.path.isfile(filename): if not os.path.isfile(filename):
return False return False
with open(filename, 'r') as f: with open(filename, mode='rb') as f:
magic_bytes = f.read(_num_magic_bytes) magic_bytes = f.read(_num_magic_bytes)
if sys.platform == 'darwin': if sys.platform == 'darwin':
return magic_bytes in [ return magic_bytes in [
'\xfe\xed\xfa\xce', # MH_MAGIC b'\xfe\xed\xfa\xce', # MH_MAGIC
'\xce\xfa\xed\xfe', # MH_CIGAM b'\xce\xfa\xed\xfe', # MH_CIGAM
'\xfe\xed\xfa\xcf', # MH_MAGIC_64 b'\xfe\xed\xfa\xcf', # MH_MAGIC_64
'\xcf\xfa\xed\xfe', # MH_CIGAM_64 b'\xcf\xfa\xed\xfe', # MH_CIGAM_64
'\xca\xfe\xba\xbe', # FAT_MAGIC b'\xca\xfe\xba\xbe', # FAT_MAGIC
'\xbe\xba\xfe\xca' # FAT_CIGAM b'\xbe\xba\xfe\xca' # FAT_CIGAM
] ]
elif sys.platform.startswith('win'): elif sys.platform.startswith('win'):
return magic_bytes == 'MZ' return magic_bytes == b'MZ'
else: else:
return magic_bytes == '\x7FELF' return magic_bytes == b'\x7FELF'
def is_json_file(filename): def is_json_file(filename):
...@@ -68,7 +68,7 @@ def classify_input_file(filename): ...@@ -68,7 +68,7 @@ def classify_input_file(filename):
elif is_json_file(filename): elif is_json_file(filename):
ftype = IT_JSON ftype = IT_JSON
else: else:
err_msg = "'%s' does not name a valid benchmark executable or JSON file" err_msg = "'%s' does not name a valid benchmark executable or JSON file" % filename
return ftype, err_msg return ftype, err_msg
...@@ -80,7 +80,7 @@ def check_input_file(filename): ...@@ -80,7 +80,7 @@ def check_input_file(filename):
""" """
ftype, msg = classify_input_file(filename) ftype, msg = classify_input_file(filename)
if ftype == IT_Invalid: if ftype == IT_Invalid:
print "Invalid input file: %s" % msg print("Invalid input file: %s" % msg)
sys.exit(1) sys.exit(1)
return ftype return ftype
......
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