1
|
1 |
|
import sys |
2
|
1 |
|
import traceback |
3
|
|
|
|
4
|
1 |
|
from .command_line_client.arf_to_html import ArfToHtml |
5
|
1 |
|
from .command_line_client.arf_to_json import ArfToJson |
6
|
1 |
|
from .command_line_client.json_to_html import JsonToHtml |
7
|
1 |
|
from .command_line_client.arf_to_html_report import ArfToHtmlReport |
8
|
1 |
|
CRED = '\033[91m' |
9
|
1 |
|
CEND = '\033[0m' |
10
|
|
|
|
11
|
|
|
|
12
|
1 |
|
def print_where_is_saved_result(results_src): |
13
|
1 |
|
if results_src: |
14
|
1 |
|
print("Results are saved:", file=sys.stderr) |
15
|
1 |
|
for src in results_src: |
16
|
1 |
|
print(src, file=sys.stderr) |
17
|
|
|
|
18
|
|
|
|
19
|
1 |
|
def print_detail_traceback_if_verbose(args): |
20
|
1 |
|
if any(arg in args for arg in ("-v", "--verbose")): |
21
|
1 |
|
traceback.print_exc() |
22
|
|
|
|
23
|
|
|
|
24
|
1 |
|
def arf_to_report(args): |
25
|
|
|
try: |
26
|
|
|
main(ArfToHtmlReport(args)) |
27
|
|
|
except Exception as error: |
28
|
|
|
print_detail_traceback_if_verbose(args) |
29
|
|
|
print((CRED + 'Error: {}' + CEND).format(error)) |
30
|
|
|
|
31
|
|
|
|
32
|
1 |
|
def arf_to_graph(args): |
33
|
1 |
|
try: |
34
|
1 |
|
main(ArfToHtml(args)) |
35
|
1 |
|
except Exception as error: |
36
|
1 |
|
print_detail_traceback_if_verbose(args) |
37
|
1 |
|
print((CRED + 'Error: {}' + CEND).format(error)) |
38
|
|
|
|
39
|
|
|
|
40
|
1 |
|
def arf_to_json(args): |
41
|
1 |
|
try: |
42
|
1 |
|
main(ArfToJson(args)) |
43
|
1 |
|
except Exception as error: |
44
|
1 |
|
print_detail_traceback_if_verbose(args) |
45
|
1 |
|
print((CRED + 'Error: {}' + CEND).format(error)) |
46
|
|
|
|
47
|
|
|
|
48
|
1 |
|
def json_to_graph(args): |
49
|
1 |
|
try: |
50
|
1 |
|
main(JsonToHtml(args)) |
51
|
1 |
|
except Exception as error: |
52
|
1 |
|
print_detail_traceback_if_verbose(args) |
53
|
1 |
|
print((CRED + 'Error: {}' + CEND).format(error)) |
54
|
|
|
|
55
|
|
|
|
56
|
1 |
|
def main(client): |
57
|
1 |
|
results_src = [] |
58
|
1 |
|
rules = client.search_rules_id() |
59
|
1 |
|
if len(rules) > 1: |
60
|
1 |
|
answers = client.run_gui_and_return_answers() |
61
|
1 |
|
if answers is not None: |
62
|
1 |
|
results_src = client.prepare_data(answers) |
63
|
|
|
else: |
64
|
1 |
|
results_src = client.prepare_data({'rules': [rules[0]]}) |
65
|
1 |
|
if client.verbose: |
66
|
1 |
|
print_where_is_saved_result(results_src) |
67
|
|
|
|
68
|
|
|
|
69
|
1 |
|
if __name__ == '__main__': |
70
|
1 |
|
import argparse |
71
|
|
|
|
72
|
1 |
|
parser = argparse.ArgumentParser() |
73
|
1 |
|
subparsers = parser.add_subparsers() |
74
|
|
|
|
75
|
1 |
|
parser_arf_to_graph = subparsers.add_parser( |
76
|
|
|
'arf-to-graph', help='Executes the arf-to-graph command.') |
77
|
1 |
|
parser_arf_to_graph.set_defaults(command=arf_to_graph) |
78
|
|
|
|
79
|
1 |
|
parser_arf_to_json = subparsers.add_parser( |
80
|
|
|
'arf-to-json', help='Executes the arf-to-json command.') |
81
|
1 |
|
parser_arf_to_json.set_defaults(command=arf_to_json) |
82
|
|
|
|
83
|
1 |
|
parser_json_to_graph = subparsers.add_parser( |
84
|
|
|
'json-to-graph', help='Executes the json-to-graph command.') |
85
|
1 |
|
parser_json_to_graph.set_defaults(command=json_to_graph) |
86
|
|
|
|
87
|
1 |
|
parser_arf_to_report = subparsers.add_parser( |
88
|
|
|
'arf-to-report', help='Executes the arf-to-report command.') |
89
|
1 |
|
parser_arf_to_report.set_defaults(command=arf_to_report) |
90
|
|
|
|
91
|
1 |
|
args, command_args = parser.parse_known_args() |
92
|
|
|
args.command(command_args) |
93
|
|
|
|