Passed
Pull Request — master (#177)
by Jan
05:53 queued 02:05
created

oval_graph.command_line.json_to_graph()   A

Complexity

Conditions 2

Size

Total Lines 6
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 6
nop 1
dl 0
loc 6
ccs 6
cts 6
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
'''
2
    This file contains entry points for commands
3
'''
4
5 1
import sys
0 ignored issues
show
Unused Code introduced by
The import sys seems to be unused.
Loading history...
6 1
import traceback
7
8 1
from .command_line_client.arf_to_html import ArfToHtml
9 1
from .command_line_client.arf_to_json import ArfToJson
10 1
from .command_line_client.json_to_html import JsonToHtml
11
12 1
CRED = '\033[91m'
13 1
CEND = '\033[0m'
14
15
16 1
def print_detail_traceback_if_verbose(args):
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 73).

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...
17 1
    if any(arg in args for arg in ("-v", "--verbose")):
18 1
        traceback.print_exc()
19
20
21 1
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 73).

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...
22 1
    try:
23 1
        main(ArfToHtml(args))
24 1
    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...
25 1
        print_detail_traceback_if_verbose(args)
26 1
        print((CRED + 'Error: {}' + CEND).format(error))
27
28
29 1
def arf_to_json(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 73).

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...
30 1
    try:
31 1
        main(ArfToJson(args))
32 1
    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...
33 1
        print_detail_traceback_if_verbose(args)
34 1
        print((CRED + 'Error: {}' + CEND).format(error))
35
36
37 1
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 73).

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...
38 1
    try:
39 1
        main(JsonToHtml(args))
40 1
    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...
41 1
        print_detail_traceback_if_verbose(args)
42 1
        print((CRED + 'Error: {}' + CEND).format(error))
43
44
45 1
def main(client):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
46 1
    rules = client.search_rules_id()
47 1
    if len(rules) > 1:
48 1
        answers = client.run_gui_and_return_answers()
49 1
        if answers is not None:
50 1
            results_src = client.prepare_data(answers)
0 ignored issues
show
Unused Code introduced by
The variable results_src seems to be unused.
Loading history...
51
    else:
52 1
        client.prepare_data({'rules': [rules[0]]})
53
54
55 1
if __name__ == '__main__':
56 1
    import argparse
57
58 1
    parser = argparse.ArgumentParser()
59 1
    subparsers = parser.add_subparsers()
60
61 1
    parser_arf_to_graph = subparsers.add_parser(
62
        'arf-to-graph', help='Executes the arf-to-graph command.')
63 1
    parser_arf_to_graph.set_defaults(command=arf_to_graph)
64
65 1
    parser_arf_to_json = subparsers.add_parser(
66
        'arf-to-json', help='Executes the arf-to-json command.')
67 1
    parser_arf_to_json.set_defaults(command=arf_to_json)
68
69 1
    parser_json_to_graph = subparsers.add_parser(
70
        'json-to-graph', help='Executes the json-to-graph command.')
71 1
    parser_json_to_graph.set_defaults(command=json_to_graph)
72
73 1
    args, command_args = parser.parse_known_args()
74
    args.command(command_args)
75