|
1
|
|
|
""" |
|
2
|
|
|
This file contains entry points for commands |
|
3
|
|
|
""" |
|
4
|
|
|
|
|
5
|
1 |
|
import traceback |
|
6
|
|
|
|
|
7
|
1 |
|
from .command_line_client.arf_to_html import ArfToHtml |
|
8
|
1 |
|
from .command_line_client.arf_to_json import ArfToJson |
|
9
|
1 |
|
from .command_line_client.json_to_html import JsonToHtml |
|
10
|
1 |
|
from .exceptions import NotTestedRule |
|
11
|
|
|
|
|
12
|
1 |
|
C_RED = '\033[91m' |
|
13
|
1 |
|
C_END = '\033[0m' |
|
14
|
1 |
|
ERRORS = (ValueError, TypeError, ResourceWarning, NotTestedRule) |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
1 |
|
def arf_to_graph(params=None): |
|
18
|
1 |
|
catch_errors(ArfToHtml, params) |
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
1 |
|
def arf_to_json(params=None): |
|
22
|
1 |
|
catch_errors(ArfToJson, params) |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
1 |
|
def json_to_graph(params=None): |
|
26
|
1 |
|
catch_errors(JsonToHtml, params) |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
1 |
|
def catch_errors(client_class, params): |
|
30
|
1 |
|
try: |
|
31
|
1 |
|
main(client_class(params)) |
|
32
|
1 |
|
except ERRORS as error: |
|
33
|
1 |
|
if any(param in params for param in ("-v", "--verbose")): |
|
34
|
1 |
|
traceback.print_exc() |
|
35
|
1 |
|
print('{}Error: {}{}'.format(C_RED, error, C_END)) |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
1 |
|
def main(client): |
|
39
|
1 |
|
rules = client.search_rules_id() |
|
40
|
1 |
|
if len(rules) > 1: |
|
41
|
1 |
|
answers = client.run_gui_and_return_answers() |
|
42
|
1 |
|
if answers is not None: |
|
43
|
1 |
|
client.prepare_data(answers) |
|
44
|
|
|
else: |
|
45
|
1 |
|
client.prepare_data({'rules': [rules[0]]}) |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
1 |
|
if __name__ == '__main__': |
|
49
|
1 |
|
import argparse |
|
50
|
|
|
|
|
51
|
1 |
|
parser = argparse.ArgumentParser() |
|
52
|
1 |
|
subparsers = parser.add_subparsers() |
|
53
|
|
|
|
|
54
|
1 |
|
parser_arf_to_graph = subparsers.add_parser( |
|
55
|
|
|
'arf-to-graph', help='Executes the arf-to-graph command.') |
|
56
|
1 |
|
parser_arf_to_graph.set_defaults(command=arf_to_graph) |
|
57
|
|
|
|
|
58
|
1 |
|
parser_arf_to_json = subparsers.add_parser( |
|
59
|
|
|
'arf-to-json', help='Executes the arf-to-json command.') |
|
60
|
1 |
|
parser_arf_to_json.set_defaults(command=arf_to_json) |
|
61
|
|
|
|
|
62
|
1 |
|
parser_json_to_graph = subparsers.add_parser( |
|
63
|
|
|
'json-to-graph', help='Executes the json-to-graph command.') |
|
64
|
1 |
|
parser_json_to_graph.set_defaults(command=json_to_graph) |
|
65
|
|
|
|
|
66
|
1 |
|
args, command_args = parser.parse_known_args() |
|
67
|
|
|
args.command(command_args) |
|
68
|
|
|
|