Passed
Pull Request — master (#156)
by Jan
04:02
created

ClientHtmlOutput.prepare_data()   A

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 6
nop 2
dl 0
loc 6
ccs 6
cts 6
cp 1
crap 1
rs 10
c 0
b 0
f 0
1 1
import os
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
introduced by
import missing from __future__ import absolute_import
Loading history...
2 1
import subprocess
3 1
import tempfile
4 1
import webbrowser
5
6 1
from .._builder_html_graph import BuilderHtmlGraph
7 1
from ..exceptions import NotChecked
8 1
from .client import Client
9
10
11 1
class ClientHtmlOutput(Client):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
Bug introduced by
The method _get_lines_of_wanted_not_selected_rules which was declared abstract in the super-class Client
was not overridden.

Methods which raise NotImplementedError should be overridden in concrete child classes.

Loading history...
Bug introduced by
The method get_only_fail_rule which was declared abstract in the super-class Client
was not overridden.

Methods which raise NotImplementedError should be overridden in concrete child classes.

Loading history...
Bug introduced by
The method search_rules_id which was declared abstract in the super-class Client
was not overridden.

Methods which raise NotImplementedError should be overridden in concrete child classes.

Loading history...
12 1
    def __init__(self, args):
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
13 1
        super().__init__(args)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
14 1
        self.parts = self.get_src('../parts')
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
15 1
        self.start_of_file_name = 'graph-of-'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
16
17 1
        self.all_in_one = self.arg.all_in_one
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
18 1
        self.all_rules = True if self.all_in_one else self.arg.all
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
19 1
        self.display_html = True if self.out is None else self.arg.display
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
20 1
        self.html_builder = BuilderHtmlGraph(self.parts, self.verbose, self.all_in_one)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (87/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
21 1
        self.web_browsers = []
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
22
23 1
    @staticmethod
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
24
    def print_red_text(text):
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
introduced by
Missing function or method docstring
Loading history...
25
        start_red_color = '\033[91m'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
26
        end_red_color = '\033[0m'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
27
        print(start_red_color + str(text) + end_red_color)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
28
29 1
    @staticmethod
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
30
    def get_src(src):
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
introduced by
Missing function or method docstring
Loading history...
31 1
        _dir = os.path.dirname(os.path.realpath(__file__))
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
32 1
        return str(os.path.join(_dir, src))
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
33
34 1
    def prepare_data(self, rules):
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
35 1
        out_src = []
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
36 1
        oval_tree_dict = dict()
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
37 1
        self._prepare_data(rules, oval_tree_dict, out_src)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
38 1
        self.open_results_in_web_browser(out_src)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
39 1
        return out_src
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
40
41 1
    def _prepare_data(self, rules, dict_oval_trees, out_src):
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
42 1
        for rule in rules['rules']:
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
43 1
            try:
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 12 tabs, expected 3
Loading history...
44 1
                self._put_to_dict_oval_trees(dict_oval_trees, rule)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 16 tabs, expected 4
Loading history...
Bug introduced by
The Instance of ClientHtmlOutput does not seem to have a member named _put_to_dict_oval_trees.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
45 1
                if not self.all_in_one:
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 16 tabs, expected 4
Loading history...
46 1
                    self._build_and_save_html(
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 20 tabs, expected 5
Loading history...
47
                        dict_oval_trees,
48
                        self._get_src_for_one_graph(rule),
49
                        dict(rules=[rule]),
50
                        out_src
51
                    )
52 1
                    dict_oval_trees = {}
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 20 tabs, expected 5
Loading history...
53 1
            except NotChecked as error:
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 12 tabs, expected 3
Loading history...
54
                self.print_red_text(error)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 16 tabs, expected 4
Loading history...
55 1
        if self.all_in_one:
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
56
            self._build_and_save_html(
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 12 tabs, expected 3
Loading history...
57
                dict_oval_trees, self.get_save_src(
58
                    'rules' + self.date), rules, out_src)
59
60 1
    def _build_and_save_html(self, dict_oval_trees, src, rules, out_src):
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
61 1
        self.html_builder.save_html(dict_oval_trees, src, rules)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
62 1
        out_src.append(src)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
63
64 1
    def _get_src_for_one_graph(self, rule):
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
65 1
        return self.get_save_src(rule + self.date)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
66
67 1
    def get_save_src(self, rule):
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
introduced by
Missing function or method docstring
Loading history...
68 1
        if self.out is not None:
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
69 1
            os.makedirs(self.out, exist_ok=True)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 12 tabs, expected 3
Loading history...
70 1
            return os.path.join(
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 12 tabs, expected 3
Loading history...
71
                self.out,
72
                self.start_of_file_name + rule + '.html')
73 1
        return os.path.join(
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
74
            tempfile.gettempdir(),
75
            self.start_of_file_name + rule + '.html')
76
77 1
    def open_results_in_web_browser(self, paths_to_results):
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
introduced by
Missing function or method docstring
Loading history...
78 1
        if self.display_html:
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
79 1
            try:
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 12 tabs, expected 3
Loading history...
80 1
                self.web_browsers.append(
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 16 tabs, expected 4
Loading history...
81
                    subprocess.Popen(["firefox", *paths_to_results]))
82
            except subprocess.CalledProcessError:
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 12 tabs, expected 3
Loading history...
83
                default_web_browser_name = webbrowser.get().name
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 16 tabs, expected 4
Loading history...
84
                self.web_browsers.append(
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 16 tabs, expected 4
Loading history...
85
                    subprocess.Popen([default_web_browser_name, *paths_to_results]))
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (84/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
86
87 1
    def kill_web_browsers(self):
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
introduced by
Missing function or method docstring
Loading history...
88 1
        for web_browser in self.web_browsers:
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
89 1
            web_browser.kill()
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 12 tabs, expected 3
Loading history...
90
91 1
    def prepare_args_when_output_is_html(self):
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
Coding Style Naming introduced by
Method name "prepare_args_when_output_is_html" 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...
92 1
        self.parser.add_argument(
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
93
            '-i',
94
            '--all-in-one',
95
            action="store_true",
96
            default=False,
97
            help="Processes all rules into one file.")
98 1
        self.parser.add_argument(
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
99
            '-d',
100
            '--display',
101
            action="store_true",
102
            default=False,
103
            help="Enables opening a web browser with a graph, when is used --output.")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (86/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
104