-
Notifications
You must be signed in to change notification settings - Fork 0
/
dixf.py
executable file
·122 lines (103 loc) · 3.66 KB
/
dixf.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
'''
Generate shorter, more meaningful diff of configuration dumps
Ignore "password/certificate encryption" changes (each dump file can have different encoding)
./dixf.py --run_tests; red_green_bar.py $? $COLUMNS
'''
import sys
import unittest
import argparse
import fr_gt_diff
import lbl_df
import src_rng
import ctx_blck
import sngl_prd
FILE_A_NAME = '--old'
FILE_B_NAME = '--new'
def recognize_options():
parser = argparse.ArgumentParser()
parser.add_argument(FILE_A_NAME,
default=None,
help='Previous file name')
parser.add_argument(FILE_B_NAME,
default=None,
help='Next file name')
parser.add_argument('--out',
default=None,
help='Output file name with simplified changes')
parser.add_argument('--ln_numbers',
action='store_true', default=False,
help='Show line numbers with insert/replace/equal/... actions')
parser.add_argument('--forced_show',
action='store_true', default=False,
help='Show difference lines before discarding known/ignored replacements')
parser.add_argument('--focus_in',
default=None,
help='Focus on lines in old/previous file, for example: 4132, 4132-4162, 50- or -100')
parser.add_argument('--run_tests',
action='store_true', default=False,
help='Run tests')
parser.add_argument('-v', '--verbose',
action='store_true', default=False,
help='Verbose output')
opt_bag = parser.parse_args()
return parser, opt_bag
fast_test_ls = [
fr_gt_diff.TestDiffEngine,
lbl_df.TestPreparedLabels,
src_rng.TestFocusedLines,
ctx_blck.TestContextBlock,
sngl_prd.TestSinglePeriod,
]
def add_all_fast(suite):
for one_test in fast_test_ls:
suite.addTest(unittest.makeSuite(one_test))
def summary_status(suite):
text_test_result = unittest.TextTestRunner().run(suite)
return not not (text_test_result.failures or text_test_result.errors)
def perform_slow_tests():
suite = unittest.TestSuite()
add_all_fast(suite)
return summary_status(suite)
def the_main():
result = 1
parser, opt_bag = recognize_options()
option_done = 0
if opt_bag.run_tests:
result = perform_slow_tests()
option_done = 1
if not option_done:
fa = None
fb = None
name_a = opt_bag.old
if name_a is not None:
fa = fr_gt_diff.rd(name_a)
name_b = opt_bag.new
if name_b is not None:
fb = fr_gt_diff.rd(name_b)
if name_a is not None or name_b is not None:
if name_a is None:
parser.print_help()
raise RuntimeError('Lacking option: %s' % FILE_A_NAME)
if name_b is None:
parser.print_help()
raise RuntimeError('Lacking option: %s' % FILE_B_NAME)
name_c = opt_bag.out
inox_tool = fr_gt_diff.InoxTool()
inox_tool.take_lists(fa, fb)
inox_tool.analyze_differences(
focus_in=opt_bag.focus_in,
ln_numbers=opt_bag.ln_numbers,
forced_show=opt_bag.forced_show,
name_c=name_c,
verbose=opt_bag.verbose,
)
result = 0
option_done = 1
if not option_done:
parser.print_help()
return result
if __name__ == '__main__':
result = the_main()
sys.exit(result)