Total Complexity | 10 |
Total Lines | 49 |
Duplicated Lines | 0 % |
Coverage | 78.95% |
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 | |||
15 | 1 | def run_gui_and_return_answers(self): |
|
16 | try: |
||
17 | if sys.stdout.isatty(): |
||
18 | import inquirer |
||
19 | return inquirer.prompt(self.get_questions()) |
||
20 | else: |
||
21 | return {'rules': [ |
||
22 | rule['id_rule'] for rule in self.search_rules_id()]} |
||
23 | except ImportError: |
||
24 | print(self.get_selection_rules()) |
||
25 | return None |
||
26 | |||
27 | 1 | def create_dict_of_rule(self, rule_id): |
|
28 | 1 | return self.xml_parser.get_oval_tree(rule_id).save_tree_to_dict() |
|
29 | |||
30 | 1 | def save_dict_as_json(self, dict_, src): |
|
31 | 1 | with open(src + '.json', "w+") as f: |
|
32 | 1 | json.dump(dict_, f) |
|
33 | |||
34 | 1 | def prepare_data(self, rules): |
|
35 | 1 | try: |
|
36 | 1 | out = [] |
|
37 | 1 | out_oval_tree_dict = dict() |
|
38 | 1 | for rule in rules['rules']: |
|
39 | 1 | out_oval_tree_dict[rule] = self.create_dict_of_rule(rule) |
|
40 | 1 | if self.out is not None: |
|
41 | 1 | src = self.get_save_src(rule) |
|
42 | 1 | self.save_dict_as_json(out_oval_tree_dict, src) |
|
43 | 1 | out.append(src) |
|
44 | 1 | print( |
|
45 | str(json.dumps(out_oval_tree_dict, sort_keys=False, indent=4))) |
||
46 | 1 | return out |
|
47 | 1 | except Exception as error: |
|
48 | raise ValueError('Rule: "{}" Error: "{}"'.format(rule, error)) |
||
|
|||
49 |