forked from f4pga/prjxray
-
Notifications
You must be signed in to change notification settings - Fork 1
/
diff_db_json.py
executable file
·48 lines (38 loc) · 1.43 KB
/
diff_db_json.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
import argparse
import subprocess
import tempfile
import os.path
import glob
def main():
parser = argparse.ArgumentParser(
description=
"Tool for comparing database JSON outputs from two database's.")
parser.add_argument('a_db')
parser.add_argument('b_db')
args = parser.parse_args()
assert os.path.isdir(args.a_db)
assert os.path.isdir(args.b_db)
for a_json_in in glob.glob('{}/*.json'.format(args.a_db)):
a_json_base = os.path.basename(a_json_in)
b_json_in = '{}/{}'.format(args.b_db, a_json_base)
if not os.path.exists(b_json_in):
print('{} not found!'.format(b_json_in))
continue
with tempfile.NamedTemporaryFile(suffix="_a_{}".format(
a_json_base)) as a_json_out, tempfile.NamedTemporaryFile(
suffix="_b_{}".format(a_json_base)) as b_json_out:
subprocess.check_call(
"python3 -m utils.xjson {}".format(a_json_in),
shell=True,
stdout=a_json_out)
subprocess.check_call(
"python3 -m utils.xjson {}".format(b_json_in),
shell=True,
stdout=b_json_out)
print("Comparing {}".format(a_json_base))
subprocess.call(
"diff -U 10 {} {}".format(a_json_out.name, b_json_out.name),
shell=True)
if __name__ == "__main__":
main()