Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mycpp] Move Python script out of shell
- Loading branch information
Andy Chu
committed
Sep 8, 2022
1 parent
f73182b
commit ae481f9
Showing
3 changed files
with
69 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env python2 | ||
""" | ||
compare_pairs.py | ||
""" | ||
from __future__ import print_function | ||
|
||
import subprocess | ||
import sys | ||
|
||
def Check(left, right): | ||
with open(left) as f1, open(right) as f2: | ||
b1 = f1.read() | ||
b2 = f2.read() | ||
|
||
if b1 != b2: | ||
print("%s != %s" % (left, right)) | ||
sys.stdout.flush() # prevent interleaving | ||
|
||
# Only invoke a subprocess when they are NOT equal | ||
subprocess.call(["diff", "-u", left, right]) | ||
return False | ||
|
||
return True | ||
|
||
def main(argv): | ||
num_failures = 0 | ||
|
||
paths = argv[1:] | ||
n = len(paths) | ||
i = 0 | ||
while i < n: | ||
log_path = paths[i] | ||
py_path = paths[i+1] | ||
|
||
#print(log_path, py_path) | ||
|
||
if not Check(log_path, py_path): | ||
num_failures += 1 | ||
else: | ||
print("OK %s" % log_path) | ||
print(" %s" % py_path) | ||
#sys.stdout.flush() | ||
|
||
i += 2 | ||
|
||
if num_failures != 0: | ||
print("logs-equal: %d failures" % num_failures) | ||
return 1 | ||
|
||
return 0 | ||
|
||
|
||
if __name__ == '__main__': | ||
try: | ||
sys.exit(main(sys.argv)) | ||
except RuntimeError as e: | ||
print('FATAL: %s' % e, file=sys.stderr) | ||
sys.exit(1) |