Passed
Pull Request — master (#129)
by Jan
06:43 queued 02:42
created

JsonToHtml.load_rule_names()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 1
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
'''
2
    This file contains a class for command json-to-graph
3
'''
4
5
import json
6
7
from .client import Client
8
from .oval_node import restore_dict_to_tree
9
from .converter import Converter
10
from .exceptions import NotChecked
11
from ._builder_html_graph import BuilderHtmlGraph
12
13
14
class JsonToHtml(Client):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
15
    def __init__(self, args):
16
        super().__init__(args)
17
        self.json_data_file = self.get_json_data_file()
18
        self.oval_tree = None
19
20
    def _set_attributes(self):
21
        self.all_in_one = self.arg.all_in_one
22
        self.all_rules = True if self.all_in_one else self.arg.all
23
        self.display_html = True if self.out is None else self.arg.display
24
        self.html_builder = BuilderHtmlGraph(self.parts, self.verbose)
0 ignored issues
show
Bug introduced by
It seems like a value for argument all_in_one is missing in the constructor call.
Loading history...
25
26
    def _get_message(self):
27
        MESSAGES = {
0 ignored issues
show
Coding Style Naming introduced by
Variable name "MESSAGES" 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...
28
            'description': 'Client for visualization of JSON created by command arf-to-json',
29
            'source_filename': 'JSON file',
30
        }
31
        return MESSAGES
32
33
    def get_json_data_file(self):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
34
        with open(self.source_filename, 'r') as f:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "f" 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...
35
            try:
36
                return json.load(f)
37
            except Exception as error:
0 ignored issues
show
Unused Code introduced by
The variable error seems to be unused.
Loading history...
38
                raise ValueError(
0 ignored issues
show
introduced by
Consider explicitly re-raising using the 'from' keyword
Loading history...
39
                    'Used file "{}" is not valid json.'.format(
40
                        self.source_filename))
41
42
    def load_json_to_oval_tree(self, rule):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
43
        dict_of_tree = self.json_data_file[rule]
44
        if isinstance(dict_of_tree, str):
45
            raise NotChecked(dict_of_tree)
46
        try:
47
            return restore_dict_to_tree(dict_of_tree)
48
        except Exception as error:
0 ignored issues
show
Unused Code introduced by
The variable error seems to be unused.
Loading history...
49
            raise ValueError('Data is not valid for OVAL tree.')
0 ignored issues
show
introduced by
Consider explicitly re-raising using the 'from' keyword
Loading history...
50
51
    def create_dict_of_oval_node(self, oval_node):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
52
        converter = Converter(oval_node)
53
        return converter.to_JsTree_dict(self.hide_passing_tests)
54
55
    def load_rule_names(self):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
56
        return self.json_data_file.keys()
57
58
    def search_rules_id(self):
59
        rules = self._get_wanted_rules_from_array_of_IDs(
60
            self.load_rule_names())
61
        notselected_rules = []
62
        return self._check_rules_id(rules, notselected_rules)
63
64
    def create_dict_of_rule(self, rule):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
65
        self.oval_tree = self.load_json_to_oval_tree(rule)
66
        return self.create_dict_of_oval_node(self.oval_tree)
67
68
    def _put_to_dict_oval_trees(self, dict_oval_trees, rule):
69
        dict_oval_trees[rule.replace(
70
            self.START_OF_FILE_NAME, '')] = self.create_dict_of_rule(rule)
71
72
    def _get_src_for_one_graph(self, rule):
73
        return self.get_save_src(rule.replace(self.START_OF_FILE_NAME, ''))
74
75
    def prepare_parser(self):
76
        super().prepare_parser()
77
        self.prepare_args_when_output_is_html()
78