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

oval_graph.command_line_client.arf_to_json   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 97.44%

Importance

Changes 0
Metric Value
eloc 46
dl 0
loc 57
ccs 38
cts 39
cp 0.9744
rs 10
c 0
b 0
f 0
wmc 15

7 Methods

Rating   Name   Duplication   Size   Complexity  
A ArfToJson.file_is_empty() 0 3 1
A ArfToJson.prepare_data() 0 18 4
A ArfToJson.prepare_parser() 0 3 1
A ArfToJson.__init__() 0 3 1
A ArfToJson._get_message() 0 4 1
B ArfToJson.save_dict_as_json() 0 8 6
A ArfToJson.create_dict_of_rule() 0 2 1
1 1
import json
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2 1
import os
3
4 1
from ..exceptions import NotChecked
5 1
from .client_arf_input import ClientArfInput
6
7
8 1
class ArfToJson(ClientArfInput):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
9 1
    def __init__(self, args):
10 1
        super().__init__(args)
11 1
        self.out = self.arg.output
12
13 1
    def _get_message(self):
14 1
        return {
15
            'description': 'Client for generating JSON of SCAP rule evaluation results',
16
            'source_filename': 'ARF scan file',
17
        }
18
19 1
    def create_dict_of_rule(self, rule_id):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
20 1
        return self.arf_xml_parser.get_oval_tree(rule_id).save_tree_to_dict()
21
22 1
    @staticmethod
23
    def file_is_empty(path):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
24 1
        return os.stat(path).st_size == 0
25
26 1
    def save_dict_as_json(self, dict_, src):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
27 1
        if os.path.isfile(src) and not self.file_is_empty(src):
28 1
            with open(src, "r") as file_:
29 1
                data = json.load(file_)
30 1
                for key in data:
31 1
                    dict_[key] = data[key]
32 1
        with open(src, "w+") as file_:
33 1
            json.dump(dict_, file_)
34
35 1
    def prepare_data(self, rules):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
36 1
        out = []
37 1
        rule = None
38 1
        out_oval_tree_dict = dict()
39 1
        for rule in rules['rules']:
40 1
            try:
41 1
                out_oval_tree_dict[
42
                    rule + self._get_date()] = self.create_dict_of_rule(rule)
43 1
            except NotChecked as error:
44
                out_oval_tree_dict[
45
                    rule + self._get_date()] = str(error)
46 1
        if self.out is not None:
47 1
            self.save_dict_as_json(out_oval_tree_dict, self.out)
48 1
            out.append(self.out)
49
        else:
50 1
            print(
51
                str(json.dumps(out_oval_tree_dict, sort_keys=False, indent=4)))
52 1
        return out
53
54 1
    def prepare_parser(self, parser):
55 1
        super().prepare_parser(parser)
56
        self.prepare_args_when_user_can_list_in_rules(parser)
57