-
Notifications
You must be signed in to change notification settings - Fork 6
/
differ.py
executable file
·56 lines (43 loc) · 1.51 KB
/
differ.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
#!/usr/bin/env python3
import argparse
import logging
import re
def get_commands_from_file(filename):
commands = {}
with open(filename) as commandfile:
for line in commandfile:
line = re.sub(r"#.*", "", line)
line = line.strip()
match = re.match(
r".*@(?P<subunit>.+?):(?P<function>.+?)=(?P<value>.*)", line
)
if match is not None:
subunit = match.group("subunit")
function = match.group("function")
value = match.group("value")
if subunit not in commands:
commands[subunit] = set()
commands[subunit].add(function)
return commands
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Compare 2 files containing YNCA commands, output will be the commands not available in reference."
)
parser.add_argument(
"reference",
help="Reference file to compare against.",
)
parser.add_argument(
"other",
help="File to compare.",
)
args = parser.parse_args()
reference_commands = get_commands_from_file(args.reference)
other_commands = get_commands_from_file(args.other)
for subunit, functions in other_commands.items():
for function in sorted(functions):
try:
if function not in reference_commands[subunit]:
print(f"@{subunit}:{function}")
except KeyError:
pass