[4512] | 1 | #!/usr/bin/env python3 |
---|
| 2 | |
---|
[2412] | 3 | """This script should be called by "diffdef.sh". It operates on |
---|
[4512] | 4 | different lines with common variables. |
---|
[2082] | 5 | |
---|
[2412] | 6 | Author: Lionel GUEZ""" |
---|
[2082] | 7 | |
---|
| 8 | import sys, os.path |
---|
| 9 | |
---|
| 10 | with open(os.path.join(sys.argv[1], "common_var")) as common_var1, \ |
---|
| 11 | open(os.path.join(sys.argv[2], "common_var")) as common_var2, \ |
---|
| 12 | open("common_lines", "a") as common_lines, \ |
---|
| 13 | open("uniq_val", "w") as uniq_val: |
---|
| 14 | uniq_val.write("Comparison of " + sys.argv[1] + " and " + sys.argv[2] |
---|
| 15 | + ":\n") # title line |
---|
| 16 | for line1, line2 in zip(common_var1, common_var2): |
---|
| 17 | i = line1.index("=") |
---|
| 18 | var_name = line1[:i] |
---|
| 19 | value1 = line1[i + 1:-1] |
---|
| 20 | value2 = line2[i + 1:-1] |
---|
| 21 | try: |
---|
| 22 | value1_num = float(value1) |
---|
| 23 | value2_num = float(value2) |
---|
| 24 | except ValueError: |
---|
| 25 | uniq_val.write(var_name + "=\t" + value1 + "\t" + value2 + "\n") |
---|
| 26 | else: |
---|
| 27 | if (value1_num, value2_num) == (0, 0) \ |
---|
| 28 | or abs(value2_num - value1_num) \ |
---|
| 29 | / max(abs(value1_num), abs(value2_num)) <= 1e-5: |
---|
| 30 | # These should not be integer values, write a formatted value: |
---|
| 31 | common_lines.write(var_name + "=" + str(value1_num) + "\n") |
---|
| 32 | else: |
---|
| 33 | # These could be integer values, write the original strings: |
---|
| 34 | uniq_val.write(var_name + "=\t" + value1 + "\t" + value2 |
---|
| 35 | + "\n") |
---|