Passed
Push — master ( 6428d5...bc0e9d )
by Matěj
90:12 queued 26s
created

ClientHtmlOutput.get_src()   A

Complexity

Conditions 1

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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