| 1 | #!/usr/bin/env python2
 | 
| 2 | """
 | 
| 3 | compare_pairs.py
 | 
| 4 | """
 | 
| 5 | from __future__ import print_function
 | 
| 6 | 
 | 
| 7 | import subprocess
 | 
| 8 | import sys
 | 
| 9 | 
 | 
| 10 | 
 | 
| 11 | def Check(left, right):
 | 
| 12 |     with open(left) as f1, open(right) as f2:
 | 
| 13 |         b1 = f1.read()
 | 
| 14 |         b2 = f2.read()
 | 
| 15 | 
 | 
| 16 |     if b1 != b2:
 | 
| 17 |         print("%s != %s" % (left, right))
 | 
| 18 |         sys.stdout.flush()  # prevent interleaving
 | 
| 19 | 
 | 
| 20 |         # Only invoke a subprocess when they are NOT equal
 | 
| 21 |         subprocess.call(["diff", "-u", left, right])
 | 
| 22 |         return False
 | 
| 23 | 
 | 
| 24 |     return True
 | 
| 25 | 
 | 
| 26 | 
 | 
| 27 | def main(argv):
 | 
| 28 |     num_failures = 0
 | 
| 29 | 
 | 
| 30 |     paths = argv[1:]
 | 
| 31 |     n = len(paths)
 | 
| 32 |     i = 0
 | 
| 33 |     while i < n:
 | 
| 34 |         log_path = paths[i]
 | 
| 35 |         py_path = paths[i + 1]
 | 
| 36 | 
 | 
| 37 |         #print(log_path, py_path)
 | 
| 38 | 
 | 
| 39 |         if not Check(log_path, py_path):
 | 
| 40 |             num_failures += 1
 | 
| 41 |         else:
 | 
| 42 |             print("OK %s" % log_path)
 | 
| 43 |             print("   %s" % py_path)
 | 
| 44 |             #sys.stdout.flush()
 | 
| 45 | 
 | 
| 46 |         i += 2
 | 
| 47 | 
 | 
| 48 |     if num_failures != 0:
 | 
| 49 |         print("logs-equal: %d failures" % num_failures)
 | 
| 50 |         return 1
 | 
| 51 | 
 | 
| 52 |     return 0
 | 
| 53 | 
 | 
| 54 | 
 | 
| 55 | if __name__ == '__main__':
 | 
| 56 |     try:
 | 
| 57 |         sys.exit(main(sys.argv))
 | 
| 58 |     except RuntimeError as e:
 | 
| 59 |         print('FATAL: %s' % e, file=sys.stderr)
 | 
| 60 |         sys.exit(1)
 |