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

ArfToJson.prepare_data()   A

Complexity

Conditions 4

Size

Total Lines 18
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 4.0058

Importance

Changes 0
Metric Value
cc 4
eloc 17
nop 2
dl 0
loc 18
ccs 13
cts 14
cp 0.9286
crap 4.0058
rs 9.55
c 0
b 0
f 0
1 1
import json
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 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 _get_message(self):
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
10 1
        return {
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
11
            'description': 'Client for generating JSON of SCAP rule evaluation results',
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (88/80).

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

Loading history...
12
            'source_filename': 'ARF scan file',
13
        }
14
15 1
    def create_dict_of_rule(self, rule_id):
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...
16 1
        return self.xml_parser.get_oval_tree(rule_id).save_tree_to_dict()
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
17
18 1
    @staticmethod
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
19
    def file_is_empty(path):
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...
20 1
        return os.stat(path).st_size == 0
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
21
22 1
    def save_dict_as_json(self, dict_, 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...
23 1
        if os.path.isfile(src) and not self.file_is_empty(src):
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
24 1
            with open(src, "r") as file_:
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 12 tabs, expected 3
Loading history...
25 1
                data = json.load(file_)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 16 tabs, expected 4
Loading history...
26 1
                for key in data:
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 16 tabs, expected 4
Loading history...
27 1
                    dict_[key] = data[key]
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 20 tabs, expected 5
Loading history...
28 1
        with open(src, "w+") as file_:
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
29 1
            json.dump(dict_, file_)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 12 tabs, expected 3
Loading history...
30
31 1
    def prepare_data(self, rules):
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
32 1
        out = []
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
33 1
        rule = None
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
34 1
        out_oval_tree_dict = dict()
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
35 1
        for rule in rules['rules']:
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
36 1
            try:
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 12 tabs, expected 3
Loading history...
37 1
                out_oval_tree_dict[
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 16 tabs, expected 4
Loading history...
38
                    rule + self.date] = self.create_dict_of_rule(rule)
39 1
            except NotChecked as error:
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 12 tabs, expected 3
Loading history...
40
                out_oval_tree_dict[
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 16 tabs, expected 4
Loading history...
41
                    rule + self.date] = str(error)
42 1
        if self.out is not None:
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
43 1
            self.save_dict_as_json(out_oval_tree_dict, self.out)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 12 tabs, expected 3
Loading history...
44 1
            out.append(self.out)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 12 tabs, expected 3
Loading history...
45
        else:
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
46 1
            print(
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 12 tabs, expected 3
Loading history...
47
                str(json.dumps(out_oval_tree_dict, sort_keys=False, indent=4)))
48 1
        return out
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
49
50 1
    def prepare_parser(self):
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
51 1
        super().prepare_parser()
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
52
        self.prepare_args_when_user_can_list_in_rules()
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
53