def parse_command_output(self, cmd, command_result): blocks = [] table = [] # Each row is dictionary if BLOCK_PARSER_KEY in cmd: if ARGUMENTS_KEY in cmd[BLOCK_PARSER_KEY]: block_parser = import_utilities.load_block_parser( cmd[BLOCK_PARSER_KEY][NAME_KEY])( **cmd[BLOCK_PARSER_KEY][ARGUMENTS_KEY]) else: block_parser = import_utilities.load_class( cmd[BLOCK_PARSER_KEY][NAME_KEY])() blocks = import_utilities.load_class_method( block_parser, 'parse')(command_result) else: blocks.append(command_result) for block in blocks: try: if not block: continue result_dict = self.process_block(block, cmd) if len(result_dict) > 0: table += result_dict except IndexError as e: py_logger.info( "Couldn't parse block {}\nfor command {}".format( block, cmd[COMMAND_KEY])) py_logger.error(e) table = self.filter_columns(cmd, table) return table
def join_tables(self): if not self.table_joiners: return try: for joiner_config in self.table_joiners: joiner_class = import_utilities.load_class(joiner_config[NAME_KEY])() source_table = self.result_map[joiner_config[SOURCE_TABLE_KEY]] destination_table = self.result_map[joiner_config[DESTINATION_TABLE_KEY]] source_column = joiner_config[SOURCE_COLUMN_KEY] destination_column = joiner_config[DESTINATION_COLUMN_KEY] table = import_utilities.load_class_method(joiner_class, 'join_tables')(source_table, destination_table, source_column, destination_column) self.result_map[joiner_config[JOINED_TABLE_ID_KEY]] = table except KeyError as e: py_logger.error("Failed to join tables: KeyError : {}".format(e)) raise e
def call_process_table_function(process_table, result_dict): return import_utilities.load_class_method( process_table, 'process_tables')(result_dict)
def call_post_function(pre_post_processor, result_dict): return import_utilities.load_class_method(pre_post_processor, 'post_process')(result_dict)
def call_pre_function(pre_post_processor, block): return import_utilities.load_class_method(pre_post_processor, 'pre_process')(block)