Passed
Pull Request — master (#157)
by Jan
02:16
created

oval_graph.command_line   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 59
dl 0
loc 81
ccs 55
cts 55
cp 1
rs 10
c 0
b 0
f 0
wmc 15

6 Functions

Rating   Name   Duplication   Size   Complexity  
A main() 0 11 4
A print_where_is_saved_result() 0 5 3
A print_detail_traceback_if_verbose() 0 3 2
A arf_to_graph() 0 6 2
A json_to_graph() 0 6 2
A arf_to_json() 0 6 2
1 1
import sys
2 1
import traceback
3
4 1
from .arf_to_html import ArfToHtml
5 1
from .arf_to_json import ArfToJson
6 1
from .json_to_html import JsonToHtml
7
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_graph(args):
25 1
    try:
26 1
        main(ArfToHtml(args))
27 1
    except Exception as error:
28 1
        print_detail_traceback_if_verbose(args)
29 1
        print((CRED + 'Error: {}' + CEND).format(error))
30
31
32 1
def arf_to_json(args):
33 1
    try:
34 1
        main(ArfToJson(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 json_to_graph(args):
41 1
    try:
42 1
        main(JsonToHtml(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 main(client):
49 1
    results_src = []
50 1
    rules = client.search_rules_id()
51 1
    if len(rules) > 1:
52 1
        answers = client.run_gui_and_return_answers()
53 1
        if answers is not None:
54 1
            results_src = client.prepare_data(answers)
55
    else:
56 1
        results_src = client.prepare_data({'rules': [rules[0]]})
57 1
    if client.verbose:
58 1
        print_where_is_saved_result(results_src)
59
60
61 1
if __name__ == '__main__':
62 1
    import argparse
63
64 1
    parser = argparse.ArgumentParser()
65 1
    subparsers = parser.add_subparsers()
66
67 1
    parser_arf_to_graph = subparsers.add_parser(
68
        'arf-to-graph', help='Executes the arf-to-graph command.')
69 1
    parser_arf_to_graph.set_defaults(command=arf_to_graph)
70
71 1
    parser_arf_to_json = subparsers.add_parser(
72
        'arf-to-json', help='Executes the arf-to-json command.')
73 1
    parser_arf_to_json.set_defaults(command=arf_to_json)
74
75 1
    parser_json_to_graph = subparsers.add_parser(
76
        'json-to-graph', help='Executes the json-to-graph command.')
77 1
    parser_json_to_graph.set_defaults(command=json_to_graph)
78
79 1
    args, command_args = parser.parse_known_args()
80
    args.command(command_args)
81