Total Complexity | 7 |
Total Lines | 38 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | 1 | import webbrowser |
|
2 | 1 | import json |
|
3 | 1 | import os |
|
4 | 1 | import shutil |
|
5 | 1 | import pprint |
|
6 | 1 | from datetime import datetime |
|
7 | 1 | import sys |
|
8 | |||
9 | 1 | from .converter import Converter |
|
10 | 1 | from .client import Client |
|
11 | |||
12 | |||
13 | 1 | class ArfToJson(Client): |
|
14 | 1 | def create_dict_of_rule(self, rule_id): |
|
15 | 1 | return self.xml_parser.get_oval_tree(rule_id).save_tree_to_dict() |
|
16 | |||
17 | 1 | def save_dict_as_json(self, dict_, src): |
|
18 | 1 | with open(src + '.json', "w+") as f: |
|
19 | 1 | json.dump(dict_, f) |
|
20 | |||
21 | 1 | def prepare_data(self, rules): |
|
22 | 1 | try: |
|
23 | 1 | out = [] |
|
24 | 1 | rule = None |
|
25 | 1 | out_oval_tree_dict = dict() |
|
26 | 1 | for rule in rules['rules']: |
|
27 | 1 | out_oval_tree_dict[rule] = self.create_dict_of_rule(rule) |
|
28 | 1 | if self.out is not None: |
|
29 | 1 | src = self.get_save_src(rule) |
|
30 | 1 | self.save_dict_as_json(out_oval_tree_dict, src) |
|
31 | 1 | out.append(src) |
|
32 | else: |
||
33 | 1 | print( |
|
34 | str(json.dumps(out_oval_tree_dict, sort_keys=False, indent=4))) |
||
35 | 1 | return out |
|
36 | 1 | except Exception as error: |
|
37 | raise ValueError('Rule: "{}" Error: "{}"'.format(rule, error)) |
||
38 |