-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
57 lines (42 loc) · 2.03 KB
/
Copy pathmain.py
File metadata and controls
57 lines (42 loc) · 2.03 KB
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
import argparse
from comparer import Comparer
class CLI:
def __init__(self):
self.arg_parser = argparse.ArgumentParser(description="CSV comparison tool (by default configured for Magento "
"core_config_data export files)")
self.add_arguments()
comparer = Comparer(*self.parse_arguments())
comparer.compare()
def add_arguments(self):
self.arg_parser.add_argument("file_1", help="File 1")
self.arg_parser.add_argument("file_2", help="File 2")
self.arg_parser.add_argument("--exclude", "-e", help="Exclude fields", default="0,5")
self.arg_parser.add_argument("--values", "-v", help="Value fields", default="4")
self.arg_parser.add_argument("--max-length", help="Output value max length (default=25)", default=25)
self.arg_parser.add_argument("--missing-only", "-m", help="Missing values only", action='store_true')
self.arg_parser.add_argument("--diff-only", "-d", help="Different values only", action='store_true')
self.arg_parser.add_argument("--any-format", help="Compare any format of CSV", action='store_true')
def parse_arguments(self):
args = self.arg_parser.parse_args()
# collect params
file_1 = args.file_1
file_2 = args.file_2
if not args.values:
raise AttributeError("Values attribute is required")
values = list(map(int, args.values.split(',')))
exclude = []
if args.exclude:
exclude = list(map(int, args.exclude.split(',')))
if args.max_length == '0':
max_length = None
else:
max_length = int(args.max_length)
cmp_type = Comparer.TYPE_ALL
if args.missing_only:
cmp_type = Comparer.TYPE_MISSING
elif args.diff_only:
cmp_type = Comparer.TYPE_DIFF
any_format = args.any_format
return [file_1, file_2, values, exclude, max_length, cmp_type, any_format]
if __name__ == '__main__':
CLI()