| 
                    1
                 | 
                                    
                             1                          | 
                
                 | 
                import webbrowser  | 
            
            
                                                        
            
                                    
            
            
                | 
                    2
                 | 
                                    
                             1                          | 
                
                 | 
                import json  | 
            
            
                                                        
            
                                    
            
            
                | 
                    3
                 | 
                                    
                             1                          | 
                
                 | 
                import os  | 
            
            
                                                        
            
                                    
            
            
                | 
                    4
                 | 
                                    
                             1                          | 
                
                 | 
                import argparse  | 
            
            
                                                        
            
                                    
            
            
                | 
                    5
                 | 
                                    
                             1                          | 
                
                 | 
                from datetime import datetime  | 
            
            
                                                        
            
                                    
            
            
                | 
                    6
                 | 
                                    
                             1                          | 
                
                 | 
                import shutil  | 
            
            
                                                        
            
                                    
            
            
                | 
                    7
                 | 
                                    
                             1                          | 
                
                 | 
                import sys  | 
            
            
                                                        
            
                                    
            
            
                | 
                    8
                 | 
                                    
                             1                          | 
                
                 | 
                import re  | 
            
            
                                                        
            
                                    
            
            
                | 
                    9
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                        
            
                                    
            
            
                | 
                    10
                 | 
                                    
                             1                          | 
                
                 | 
                from .client import Client  | 
            
            
                                                        
            
                                    
            
            
                | 
                    11
                 | 
                                    
                             1                          | 
                
                 | 
                from .oval_node import restore_dict_to_tree  | 
            
            
                                                        
            
                                    
            
            
                | 
                    12
                 | 
                                    
                             1                          | 
                
                 | 
                from .converter import Converter  | 
            
            
                                                        
            
                                    
            
            
                | 
                    13
                 | 
                                    
                             1                          | 
                
                 | 
                from .exceptions import NotChecked  | 
            
            
                                                        
            
                                    
            
            
                | 
                    14
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                        
            
                                    
            
            
                | 
                    15
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                        
            
                                    
            
            
                | 
                    16
                 | 
                                    
                             1                          | 
                
                 | 
                class JsonToHtml(Client):  | 
            
            
                                                        
            
                                    
            
            
                | 
                    17
                 | 
                                    
                             1                          | 
                
                 | 
                    def __init__(self, args):  | 
            
            
                                                        
            
                                    
            
            
                | 
                    18
                 | 
                                    
                             1                          | 
                
                 | 
                        self.parser = None  | 
            
            
                                                        
            
                                    
            
            
                | 
                    19
                 | 
                                    
                             1                          | 
                
                 | 
                        self.MESSAGES = self._get_message()  | 
            
            
                                                        
            
                                    
            
            
                | 
                    20
                 | 
                                    
                             1                          | 
                
                 | 
                        self.arg = self.parse_arguments(args)  | 
            
            
                                                        
            
                                    
            
            
                | 
                    21
                 | 
                                    
                             1                          | 
                
                 | 
                        self.off_webbrowser = self.arg.off_web_browser  | 
            
            
                                                        
            
                                    
            
            
                | 
                    22
                 | 
                                    
                             1                          | 
                
                 | 
                        self.hide_passing_tests = self.arg.hide_passing_tests  | 
            
            
                                                        
            
                                    
            
            
                | 
                    23
                 | 
                                    
                             1                          | 
                
                 | 
                        self.source_filename = self.arg.source_filename  | 
            
            
                                                        
            
                                    
            
            
                | 
                    24
                 | 
                                    
                             1                          | 
                
                 | 
                        self.rule_name = self.arg.rule_id  | 
            
            
                                                        
            
                                    
            
            
                | 
                    25
                 | 
                                    
                             1                          | 
                
                 | 
                        self.out = self.arg.output  | 
            
            
                                                        
            
                                    
            
            
                | 
                    26
                 | 
                                    
                             1                          | 
                
                 | 
                        self.all_in_one = self.arg.all_in_one  | 
            
            
                                                        
            
                                    
            
            
                | 
                    27
                 | 
                                    
                             1                          | 
                
                 | 
                        self.all_rules = True if self.all_in_one else self.arg.all  | 
            
            
                                                        
            
                                    
            
            
                | 
                    28
                 | 
                                    
                             1                          | 
                
                 | 
                        self.isatty = sys.stdout.isatty()  | 
            
            
                                                        
            
                                    
            
            
                | 
                    29
                 | 
                                    
                             1                          | 
                
                 | 
                        self.show_failed_rules = False  | 
            
            
                                                        
            
                                    
            
            
                | 
                    30
                 | 
                                    
                             1                          | 
                
                 | 
                        self.show_not_selected_rules = False  | 
            
            
                                                        
            
                                    
            
            
                | 
                    31
                 | 
                                    
                             1                          | 
                
                 | 
                        self.oval_tree = None  | 
            
            
                                                        
            
                                    
            
            
                | 
                    32
                 | 
                                    
                             1                          | 
                
                 | 
                        self.off_webbrowser = self.arg.off_web_browser  | 
            
            
                                                        
            
                                    
            
            
                | 
                    33
                 | 
                                    
                             1                          | 
                
                 | 
                        self.json_data_file = self.get_json_data_file()  | 
            
            
                                                        
            
                                    
            
            
                | 
                    34
                 | 
                                    
                             1                          | 
                
                 | 
                        self.parts = self.get_src('parts') | 
            
            
                                                        
            
                                    
            
            
                | 
                    35
                 | 
                                    
                             1                          | 
                
                 | 
                        self.START_OF_FILE_NAME = 'graph-of-'  | 
            
            
                                                        
            
                                    
            
            
                | 
                    36
                 | 
                                    
                             1                          | 
                
                 | 
                        self.date = datetime.now().strftime("-%d_%m_%Y-%H_%M_%S") | 
            
            
                                                        
            
                                    
            
            
                | 
                    37
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                        
            
                                    
            
            
                | 
                    38
                 | 
                                    
                             1                          | 
                
                 | 
                    def _get_message(self):  | 
            
            
                                                        
            
                                    
            
            
                | 
                    39
                 | 
                                    
                             1                          | 
                
                 | 
                        MESSAGES = { | 
            
            
                                                        
            
                                    
            
            
                | 
                    40
                 | 
                                    
                                                     | 
                
                 | 
                            'description': 'Client for visualization of JSON created by command arf-to-json',  | 
            
            
                                                        
            
                                    
            
            
                | 
                    41
                 | 
                                    
                                                     | 
                
                 | 
                            '--output': 'The directory where to save output directory with files.',  | 
            
            
                                                        
            
                                    
            
            
                | 
                    42
                 | 
                                    
                                                     | 
                
                 | 
                            'source_filename': 'JSON file',  | 
            
            
                                                        
            
                                    
            
            
                | 
                    43
                 | 
                                    
                                                     | 
                
                 | 
                        }  | 
            
            
                                                        
            
                                    
            
            
                | 
                    44
                 | 
                                    
                             1                          | 
                
                 | 
                        return MESSAGES  | 
            
            
                                                        
            
                                    
            
            
                | 
                    45
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                        
            
                                    
            
            
                | 
                    46
                 | 
                                    
                             1                          | 
                
                 | 
                    def get_json_data_file(self):  | 
            
            
                                                        
            
                                    
            
            
                | 
                    47
                 | 
                                    
                             1                          | 
                
                 | 
                        with open(self.source_filename, 'r') as f:  | 
            
            
                                                        
            
                                    
            
            
                | 
                    48
                 | 
                                    
                             1                          | 
                
                 | 
                            try:  | 
            
            
                                                        
            
                                    
            
            
                | 
                    49
                 | 
                                    
                             1                          | 
                
                 | 
                                return json.load(f)  | 
            
            
                                                        
            
                                    
            
            
                | 
                    50
                 | 
                                    
                             1                          | 
                
                 | 
                            except Exception as error:  | 
            
            
                                                        
            
                                    
            
            
                | 
                    51
                 | 
                                    
                             1                          | 
                
                 | 
                                raise ValueError(  | 
            
            
                                                        
            
                                    
            
            
                | 
                    52
                 | 
                                    
                                                     | 
                
                 | 
                                    'Used file "{}" is not valid json.'.format( | 
            
            
                                                        
            
                                    
            
            
                | 
                    53
                 | 
                                    
                                                     | 
                
                 | 
                                        self.source_filename))  | 
            
            
                                                        
            
                                    
            
            
                | 
                    54
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                        
            
                                    
            
            
                | 
                    55
                 | 
                                    
                             1                          | 
                
                 | 
                    def load_json_to_oval_tree(self, rule):  | 
            
            
                                                        
            
                                    
            
            
                | 
                    56
                 | 
                                    
                             1                          | 
                
                 | 
                        dict_of_tree = self.json_data_file[rule]  | 
            
            
                                                        
            
                                    
            
            
                | 
                    57
                 | 
                                    
                             1                          | 
                
                 | 
                        if isinstance(dict_of_tree, str):  | 
            
            
                                                        
            
                                    
            
            
                | 
                    58
                 | 
                                    
                                                     | 
                
                 | 
                            raise NotChecked(dict_of_tree)  | 
            
            
                                                        
            
                                    
            
            
                | 
                    59
                 | 
                                    
                             1                          | 
                
                 | 
                        try:  | 
            
            
                                                        
            
                                    
            
            
                | 
                    60
                 | 
                                    
                             1                          | 
                
                 | 
                            return restore_dict_to_tree(dict_of_tree)  | 
            
            
                                                        
            
                                    
            
            
                | 
                    61
                 | 
                                    
                             1                          | 
                
                 | 
                        except Exception as error:  | 
            
            
                                                        
            
                                    
            
            
                | 
                    62
                 | 
                                    
                             1                          | 
                
                 | 
                            raise ValueError('Data is not valid for OVAL tree.') | 
            
            
                                                        
            
                                    
            
            
                | 
                    63
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                        
            
                                    
            
            
                | 
                    64
                 | 
                                    
                             1                          | 
                
                 | 
                    def create_dict_of_oval_node(self, oval_node):  | 
            
            
                                                        
            
                                    
            
            
                | 
                    65
                 | 
                                    
                             1                          | 
                
                 | 
                        converter = Converter(oval_node)  | 
            
            
                                                        
            
                                    
            
            
                | 
                    66
                 | 
                                    
                             1                          | 
                
                 | 
                        return converter.to_JsTree_dict(self.hide_passing_tests)  | 
            
            
                                                        
            
                                    
            
            
                | 
                    67
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                        
            
                                    
            
            
                | 
                    68
                 | 
                                    
                             1                          | 
                
                 | 
                    def load_rule_names(self):  | 
            
            
                                                        
            
                                    
            
            
                | 
                    69
                 | 
                                    
                             1                          | 
                
                 | 
                        return self.json_data_file.keys()  | 
            
            
                                                        
            
                                    
            
            
                | 
                    70
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                        
            
                                    
            
            
                | 
                    71
                 | 
                                    
                             1                          | 
                
                 | 
                    def search_rules_id(self):  | 
            
            
                                                        
            
                                    
            
            
                | 
                    72
                 | 
                                    
                             1                          | 
                
                 | 
                        rules = self._get_wanted_rules_from_array_of_IDs(  | 
            
            
                                                        
            
                                    
            
            
                | 
                    73
                 | 
                                    
                                                     | 
                
                 | 
                            self.load_rule_names())  | 
            
            
                                                        
            
                                    
            
            
                | 
                    74
                 | 
                                    
                             1                          | 
                
                 | 
                        notselected_rules = []  | 
            
            
                                                        
            
                                    
            
            
                | 
                    75
                 | 
                                    
                             1                          | 
                
                 | 
                        return self._check_rules_id(rules, notselected_rules)  | 
            
            
                                                        
            
                                    
            
            
                | 
                    76
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                        
            
                                    
            
            
                | 
                    77
                 | 
                                    
                             1                          | 
                
                 | 
                    def create_dict_of_rule(self, rule):  | 
            
            
                                                        
            
                                    
            
            
                | 
                    78
                 | 
                                    
                             1                          | 
                
                 | 
                        self.oval_tree = self.load_json_to_oval_tree(rule)  | 
            
            
                                                        
            
                                    
            
            
                | 
                    79
                 | 
                                    
                             1                          | 
                
                 | 
                        return self.create_dict_of_oval_node(self.oval_tree)  | 
            
            
                                                        
            
                                    
            
            
                | 
                    80
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                        
            
                                    
            
            
                | 
                    81
                 | 
                                    
                             1                          | 
                
                 | 
                    def _put_to_dict_oval_trees(self, dict_oval_trees, rule):  | 
            
            
                                                        
            
                                    
            
            
                | 
                    82
                 | 
                                    
                             1                          | 
                
                 | 
                        dict_oval_trees[rule.replace(  | 
            
            
                                                        
            
                                    
            
            
                | 
                    83
                 | 
                                    
                                                     | 
                
                 | 
                            self.START_OF_FILE_NAME, '')] = self.create_dict_of_rule(rule)  | 
            
            
                                                        
            
                                    
            
            
                | 
                    84
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                        
            
                                    
            
            
                | 
                    85
                 | 
                                    
                             1                          | 
                
                 | 
                    def _get_src_for_one_graph(self, rule):  | 
            
            
                                                        
            
                                    
            
            
                | 
                    86
                 | 
                                    
                             1                          | 
                
                 | 
                        return self.get_save_src(rule.replace(self.START_OF_FILE_NAME, ''))  | 
            
            
                                                        
            
                                    
            
            
                | 
                    87
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                        
            
                                    
            
            
                | 
                    88
                 | 
                                    
                             1                          | 
                
                 | 
                    def prepare_parser(self):  | 
            
            
                                                        
            
                                    
            
            
                | 
                    89
                 | 
                                    
                             1                          | 
                
                 | 
                        super().prepare_parser()  | 
            
            
                                                        
            
                                    
            
            
                | 
                    90
                 | 
                                    
                             1                          | 
                
                 | 
                        self.parser.add_argument(  | 
            
            
                                                        
            
                                    
            
            
                | 
                    91
                 | 
                                    
                                                     | 
                
                 | 
                            '--all-in-one',  | 
            
            
                                                        
            
                                    
            
            
                | 
                    92
                 | 
                                    
                                                     | 
                
                 | 
                            action="store_true",  | 
            
            
                                                        
            
                                    
            
            
                | 
                    93
                 | 
                                    
                                                     | 
                
                 | 
                            default=False,  | 
            
            
                                                        
            
                                    
            
            
                | 
                    94
                 | 
                                    
                                                     | 
                
                 | 
                            help="Processes all rules into one file.")  | 
            
            
                                                        
            
                                    
            
            
                | 
                    95
                 | 
                                    
                             1                          | 
                
                 | 
                        self.parser.add_argument(  | 
            
            
                                                        
            
                                    
            
            
                | 
                    96
                 | 
                                    
                                                     | 
                
                 | 
                            '--off-web-browser',  | 
            
            
                                                        
            
                                    
            
            
                | 
                    97
                 | 
                                    
                                                     | 
                
                 | 
                            action="store_true",  | 
            
            
                                                        
            
                                    
            
            
                | 
                    98
                 | 
                                    
                                                     | 
                
                 | 
                            default=False,  | 
            
            
                                                        
            
                                    
            
            
                | 
                    99
                 | 
                                    
                                                     | 
                
                 | 
                            help="It does not start the web browser.")  | 
            
            
                                                        
            
                                    
            
            
                | 
                    100
                 | 
                                    
                                                     | 
                
                 | 
                 |