Passed
Pull Request — master (#149)
by Jan
04:55
created

oval_graph.command_line_client.client_html_output   A

Complexity

Total Complexity 22

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Test Coverage

Coverage 87.69%

Importance

Changes 0
Metric Value
eloc 91
dl 0
loc 107
ccs 57
cts 65
cp 0.8769
rs 10
c 0
b 0
f 0
wmc 22

12 Methods

Rating   Name   Duplication   Size   Complexity  
A ClientHtmlOutput.__init__() 0 11 3
A ClientHtmlOutput._build_and_save_html() 0 3 1
A ClientHtmlOutput.kill_web_browsers() 0 3 2
A ClientHtmlOutput._prepare_data() 0 18 5
A ClientHtmlOutput.prepare_args_display() 0 7 1
A ClientHtmlOutput.get_src() 0 4 1
A ClientHtmlOutput.prepare_args_all_in_one() 0 7 1
A ClientHtmlOutput.get_save_src() 0 9 2
A ClientHtmlOutput._get_src_for_one_graph() 0 2 1
A ClientHtmlOutput.open_results_in_web_browser() 0 9 3
A ClientHtmlOutput.print_red_text() 0 5 1
A ClientHtmlOutput.prepare_data() 0 6 1
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):
13 1
        super().__init__(args)
14 1
        self.parts = self.get_src('../parts')
15 1
        self.start_of_file_name = 'graph-of-'
16
17 1
        self.all_in_one = self.arg.all_in_one
18 1
        self.all_rules = True if self.all_in_one else self.arg.all
19 1
        self.display_html = True if self.out is None else self.arg.display
20 1
        self.html_builder = BuilderHtmlGraph(
21
            self.parts, self.verbose, self.all_in_one)
22 1
        self.web_browsers = []
23
24 1
    @staticmethod
25
    def print_red_text(text):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
26
        start_red_color = '\033[91m'
27
        end_red_color = '\033[0m'
28
        print(start_red_color + str(text) + end_red_color)
29
30 1
    @staticmethod
31
    def get_src(src):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
32 1
        _dir = os.path.dirname(os.path.realpath(__file__))
33 1
        return str(os.path.join(_dir, src))
34
35 1
    def prepare_data(self, rules):
36 1
        out_src = []
37 1
        oval_tree_dict = dict()
38 1
        self._prepare_data(rules, oval_tree_dict, out_src)
39 1
        self.open_results_in_web_browser(out_src)
40 1
        return out_src
41
42 1
    def _prepare_data(self, rules, dict_oval_trees, out_src):
43 1
        for rule in rules['rules']:
44 1
            try:
45 1
                self._put_to_dict_oval_trees(dict_oval_trees, rule)
0 ignored issues
show
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...
46 1
                if not self.all_in_one:
47 1
                    self._build_and_save_html(
48
                        dict_oval_trees,
49
                        self._get_src_for_one_graph(rule),
50
                        dict(rules=[rule]),
51
                        out_src
52
                    )
53 1
                    dict_oval_trees = {}
54 1
            except NotChecked as error:
55
                self.print_red_text(error)
56 1
        if self.all_in_one:
57
            self._build_and_save_html(
58
                dict_oval_trees, self.get_save_src(
59
                    'rules' + self.date), rules, out_src)
60
61 1
    def _build_and_save_html(self, dict_oval_trees, src, rules, out_src):
62 1
        self.html_builder.save_html(dict_oval_trees, src, rules)
63 1
        out_src.append(src)
64
65 1
    def _get_src_for_one_graph(self, rule):
66 1
        return self.get_save_src(rule + self.date)
67
68 1
    def get_save_src(self, rule):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
69 1
        if self.out is not None:
70 1
            os.makedirs(self.out, exist_ok=True)
71 1
            return os.path.join(
72
                self.out,
73
                self.start_of_file_name + rule + '.html')
74 1
        return os.path.join(
75
            tempfile.gettempdir(),
76
            self.start_of_file_name + rule + '.html')
77
78 1
    def open_results_in_web_browser(self, paths_to_results):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
79 1
        if self.display_html:
80 1
            try:
81 1
                self.web_browsers.append(
82
                    subprocess.Popen(["firefox", *paths_to_results]))
83
            except subprocess.CalledProcessError:
84
                default_web_browser_name = webbrowser.get().name
85
                self.web_browsers.append(
86
                    subprocess.Popen([default_web_browser_name, *paths_to_results]))
87
88 1
    def kill_web_browsers(self):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
89 1
        for web_browser in self.web_browsers:
90 1
            web_browser.kill()
91
92 1
    def prepare_args_all_in_one(self):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
93 1
        self.parser.add_argument(
94
            '-i',
95
            '--all-in-one',
96
            action="store_true",
97
            default=False,
98
            help="Processes all rules into one file.")
99
100 1
    def prepare_args_display(self):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
101 1
        self.parser.add_argument(
102
            '-d',
103
            '--display',
104
            action="store_true",
105
            default=False,
106
            help="Enables opening a web browser with a graph, when is used --output.")
107