Test Failed
Pull Request — master (#173)
by Jan
02:52
created

oval_graph.command_line   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

6 Functions

Rating   Name   Duplication   Size   Complexity  
A print_detail_traceback_if_verbose() 0 3 2
A arf_to_graph() 0 6 2
A json_to_graph() 0 6 2
A main() 0 11 4
A arf_to_json() 0 6 2
A print_where_is_saved_result() 0 5 3
1
'''
2
    This file contains entry points for commands
3
'''
4
5
import sys
6
import traceback
7
8
from .command_line_client.arf_to_html import ArfToHtml
9
from .command_line_client.arf_to_json import ArfToJson
10
from .command_line_client.json_to_html import JsonToHtml
11
12
CRED = '\033[91m'
13
CEND = '\033[0m'
14
15
16
def print_where_is_saved_result(results_src):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
17
    if results_src:
18
        print("Results are saved:", file=sys.stderr)
19
        for src in results_src:
20
            print(src, file=sys.stderr)
21
22
23
def print_detail_traceback_if_verbose(args):
0 ignored issues
show
Coding Style Naming introduced by
Function name "print_detail_traceback_if_verbose" doesn't conform to '[a-z_][a-z0-9_]2,30$' pattern ('[a-z_][a-z0-9_]2,30$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
introduced by
Missing function or method docstring
Loading history...
Comprehensibility Bug introduced by
args is re-defining a name which is already available in the outer-scope (previously defined on line 83).

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:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
24
    if any(arg in args for arg in ("-v", "--verbose")):
25
        traceback.print_exc()
26
27
28
def arf_to_graph(args=None):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
Comprehensibility Bug introduced by
args is re-defining a name which is already available in the outer-scope (previously defined on line 83).

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:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
29
    try:
30
        main(ArfToHtml(args))
31
    except Exception as error:
0 ignored issues
show
Best Practice introduced by
Catching very general exceptions such as Exception is usually not recommended.

Generally, you would want to handle very specific errors in the exception handler. This ensure that you do not hide other types of errors which should be fixed.

So, unless you specifically plan to handle any error, consider adding a more specific exception.

Loading history...
32
        print_detail_traceback_if_verbose(args)
33
        print((CRED + 'Error: {}' + CEND).format(error))
34
35
36
def arf_to_json(args=None):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
Comprehensibility Bug introduced by
args is re-defining a name which is already available in the outer-scope (previously defined on line 83).

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:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
37
    try:
38
        main(ArfToJson(args))
39
    except Exception as error:
0 ignored issues
show
Best Practice introduced by
Catching very general exceptions such as Exception is usually not recommended.

Generally, you would want to handle very specific errors in the exception handler. This ensure that you do not hide other types of errors which should be fixed.

So, unless you specifically plan to handle any error, consider adding a more specific exception.

Loading history...
40
        print_detail_traceback_if_verbose(args)
41
        print((CRED + 'Error: {}' + CEND).format(error))
42
43
44
def json_to_graph(args=None):
0 ignored issues
show
Comprehensibility Bug introduced by
args is re-defining a name which is already available in the outer-scope (previously defined on line 83).

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:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
introduced by
Missing function or method docstring
Loading history...
45
    try:
46
        main(JsonToHtml(args))
47
    except Exception as error:
0 ignored issues
show
Best Practice introduced by
Catching very general exceptions such as Exception is usually not recommended.

Generally, you would want to handle very specific errors in the exception handler. This ensure that you do not hide other types of errors which should be fixed.

So, unless you specifically plan to handle any error, consider adding a more specific exception.

Loading history...
48
        print_detail_traceback_if_verbose(args)
49
        print((CRED + 'Error: {}' + CEND).format(error))
50
51
52
def main(client):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
53
    results_src = []
54
    rules = client.search_rules_id()
55
    if len(rules) > 1:
56
        answers = client.run_gui_and_return_answers()
57
        if answers is not None:
58
            results_src = client.prepare_data(answers)
59
    else:
60
        results_src = client.prepare_data({'rules': [rules[0]]})
61
    if client.arg.verbose:
62
        print_where_is_saved_result(results_src)
63
64
65
if __name__ == '__main__':
66
    import argparse
67
68
    parser = argparse.ArgumentParser()
69
    subparsers = parser.add_subparsers()
70
71
    parser_arf_to_graph = subparsers.add_parser(
72
        'arf-to-graph', help='Executes the arf-to-graph command.')
73
    parser_arf_to_graph.set_defaults(command=arf_to_graph)
74
75
    parser_arf_to_json = subparsers.add_parser(
76
        'arf-to-json', help='Executes the arf-to-json command.')
77
    parser_arf_to_json.set_defaults(command=arf_to_json)
78
79
    parser_json_to_graph = subparsers.add_parser(
80
        'json-to-graph', help='Executes the json-to-graph command.')
81
    parser_json_to_graph.set_defaults(command=json_to_graph)
82
83
    args, command_args = parser.parse_known_args()
84
    args.command(command_args)
85