Passed
Pull Request — master (#149)
by Jan
04:51
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 1
import sys
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
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):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
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):
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 91).

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...
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=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 91).

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...
25
    try:
26
        main(ArfToHtmlReport(args))
27
    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...
28
        print_detail_traceback_if_verbose(args)
29
        print((CRED + 'Error: {}' + CEND).format(error))
30
31
32 1
def arf_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 91).

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...
33 1
    try:
34 1
        main(ArfToHtml(args))
35 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...
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=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 91).

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...
41 1
    try:
42 1
        main(ArfToJson(args))
43 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...
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=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 91).

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...
49 1
    try:
50 1
        main(JsonToHtml(args))
51 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...
52 1
        print_detail_traceback_if_verbose(args)
53 1
        print((CRED + 'Error: {}' + CEND).format(error))
54
55
56 1
def main(client):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
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.arg.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