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
0fbeb0dc32
commit
d5f51cc1b2
|
|
@ -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 segbits 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_db_in in glob.glob('{}/segbits*.db'.format(args.a_db)):
|
||||
a_db_base = os.path.basename(a_db_in)
|
||||
b_db_in = '{}/{}'.format(args.b_db, a_db_base)
|
||||
|
||||
if not os.path.exists(b_db_in):
|
||||
print('{} not found!'.format(b_db_in))
|
||||
continue
|
||||
|
||||
with tempfile.NamedTemporaryFile(suffix="_a_{}".format(
|
||||
a_db_base)) as a_db_out, tempfile.NamedTemporaryFile(
|
||||
suffix="_b_{}".format(a_db_base)) as b_db_out:
|
||||
subprocess.check_call(
|
||||
"sort {}".format(a_db_in), shell=True, stdout=a_db_out)
|
||||
subprocess.check_call(
|
||||
"sort {}".format(b_db_in), shell=True, stdout=b_db_out)
|
||||
|
||||
print("Comparing {}".format(a_db_base))
|
||||
subprocess.call(
|
||||
"diff -U 0 {} {}".format(a_db_out.name, b_db_out.name),
|
||||
shell=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
# diff_db_bits.sh <database a> <database b>
|
||||
#
|
||||
# Tool for comparing database segbits outputs from two database's.
|
||||
|
||||
DIR_A=$1
|
||||
DIR_B=$2
|
||||
|
||||
for A_DB_IN in $( ls ${DIR_A}/segbits*.db ); do
|
||||
A_DB_OUT="$(mktemp)_a_$(basename ${A_DB_IN})"
|
||||
B_DB_OUT="$(mktemp)_b_$(basename ${A_DB_IN})"
|
||||
|
||||
B_DB_IN="${DIR_B}/$(basename ${A_DB_IN})"
|
||||
|
||||
if [ ! -f "${B_DB_IN}" ]; then
|
||||
echo "${B_DB_IN} not found!"
|
||||
continue
|
||||
fi
|
||||
|
||||
sort ${A_DB_IN} > ${A_DB_OUT}
|
||||
sort ${B_DB_IN} > ${B_DB_OUT}
|
||||
|
||||
echo "Comparing $(basename ${A_DB_IN})"
|
||||
diff -U 0 ${A_DB_OUT} ${B_DB_OUT} || true
|
||||
done
|
||||
Loading…
Reference in New Issue