1
|
|
|
""" |
2
|
|
|
This file contains entry points for commands |
3
|
|
|
""" |
4
|
|
|
|
5
|
|
|
import traceback |
6
|
|
|
|
7
|
|
|
from .command_line_client.arf_to_html import ArfToHtml |
8
|
|
|
from .command_line_client.arf_to_json import ArfToJson |
9
|
|
|
from .command_line_client.json_to_html import JsonToHtml |
10
|
|
|
|
11
|
|
|
CRED = '\033[91m' |
12
|
|
|
CEND = '\033[0m' |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
def print_detail_traceback_if_verbose(args): |
|
|
|
|
16
|
|
|
if any(arg in args for arg in ("-v", "--verbose")): |
17
|
|
|
traceback.print_exc() |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
def arf_to_graph(args=None): |
|
|
|
|
21
|
|
|
try: |
22
|
|
|
main(ArfToHtml(args)) |
23
|
|
|
except Exception as error: |
|
|
|
|
24
|
|
|
print_detail_traceback_if_verbose(args) |
25
|
|
|
print((CRED + 'Error: {}' + CEND).format(error)) |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
def arf_to_json(args=None): |
|
|
|
|
29
|
|
|
try: |
30
|
|
|
main(ArfToJson(args)) |
31
|
|
|
except Exception as error: |
|
|
|
|
32
|
|
|
print_detail_traceback_if_verbose(args) |
33
|
|
|
print((CRED + 'Error: {}' + CEND).format(error)) |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
def json_to_graph(args=None): |
|
|
|
|
37
|
|
|
try: |
38
|
|
|
main(JsonToHtml(args)) |
39
|
|
|
except Exception as error: |
|
|
|
|
40
|
|
|
print_detail_traceback_if_verbose(args) |
41
|
|
|
print((CRED + 'Error: {}' + CEND).format(error)) |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
def main(client): |
45
|
|
|
rules = client.search_rules_id() |
46
|
|
|
if len(rules) > 1: |
47
|
|
|
answers = client.run_gui_and_return_answers() |
48
|
|
|
if answers is not None: |
49
|
|
|
client.prepare_data(answers) |
50
|
|
|
else: |
51
|
|
|
client.prepare_data({'rules': [rules[0]]}) |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
if __name__ == '__main__': |
55
|
|
|
import argparse |
56
|
|
|
|
57
|
|
|
parser = argparse.ArgumentParser() |
58
|
|
|
subparsers = parser.add_subparsers() |
59
|
|
|
|
60
|
|
|
parser_arf_to_graph = subparsers.add_parser( |
61
|
|
|
'arf-to-graph', help='Executes the arf-to-graph command.') |
62
|
|
|
parser_arf_to_graph.set_defaults(command=arf_to_graph) |
63
|
|
|
|
64
|
|
|
parser_arf_to_json = subparsers.add_parser( |
65
|
|
|
'arf-to-json', help='Executes the arf-to-json command.') |
66
|
|
|
parser_arf_to_json.set_defaults(command=arf_to_json) |
67
|
|
|
|
68
|
|
|
parser_json_to_graph = subparsers.add_parser( |
69
|
|
|
'json-to-graph', help='Executes the json-to-graph command.') |
70
|
|
|
parser_json_to_graph.set_defaults(command=json_to_graph) |
71
|
|
|
|
72
|
|
|
args, command_args = parser.parse_known_args() |
73
|
|
|
args.command(command_args) |
74
|
|
|
|
It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior: