mirror of https://github.com/openXC7/prjxray.git
Convert shell script to python script.
Signed-off-by: Keith Rothman <537074+litghost@users.noreply.github.com>
This commit is contained in:
parent
5817e5932c
commit
782d2c4ced
|
|
@ -0,0 +1,44 @@
|
|||
#!/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 3 {} {}".format(a_json_out.name, b_json_out.name),
|
||||
shell=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
# diff_db_json.sh <database a> <database b>
|
||||
#
|
||||
# Tool for comparing database JSON outputs from two database's.
|
||||
|
||||
DIR_A=$1
|
||||
DIR_B=$2
|
||||
|
||||
for A_JSON_IN in $( ls ${DIR_A}/*.json ); do
|
||||
A_JSON_OUT="$(mktemp)_a"
|
||||
B_JSON_OUT="$(mktemp)_b"
|
||||
|
||||
B_JSON_IN="${DIR_B}/$(basename ${A_JSON_IN})"
|
||||
|
||||
if [ ! -f "${B_JSON_IN}" ]; then
|
||||
echo "${B_JSON_IN} not found!"
|
||||
continue
|
||||
fi
|
||||
|
||||
python3 -m utils.xjson ${A_JSON_IN} > ${A_JSON_OUT}
|
||||
python3 -m utils.xjson ${B_JSON_IN} > ${B_JSON_OUT}
|
||||
|
||||
echo "Comparing $(basename ${A_JSON_IN})"
|
||||
diff -U 3 ${A_JSON_OUT} ${B_JSON_OUT} || true
|
||||
done
|
||||
Loading…
Reference in New Issue