def alias_event_handler(_, **kwargs):
    """
    An event handler for alias transformation when EVENT_INVOKER_PRE_TRUNCATE_CMD_TBL event is invoked.
    """
    try:
        telemetry.start()

        start_time = timeit.default_timer()
        args = kwargs.get('args')
        alias_manager = AliasManager(**kwargs)

        # [:] will keep the reference of the original args
        args[:] = alias_manager.transform(args)

        if is_alias_command(['create', 'import'], args):
            load_cmd_tbl_func = kwargs.get('load_cmd_tbl_func', lambda _: {})
            cache_reserved_commands(load_cmd_tbl_func)

        elapsed_time = (timeit.default_timer() - start_time) * 1000
        logger.debug(DEBUG_MSG_WITH_TIMING, args, elapsed_time)

        telemetry.set_execution_time(round(elapsed_time, 2))
    except Exception as client_exception:  # pylint: disable=broad-except
        telemetry.set_exception(client_exception)
        raise
    finally:
        telemetry.conclude()
def alias_event_handler(_, **kwargs):
    """
    An event handler for alias transformation when EVENT_INVOKER_PRE_TRUNCATE_CMD_TBL event is invoked.
    """
    try:
        telemetry.start()

        start_time = timeit.default_timer()
        args = kwargs.get('args')
        alias_manager = AliasManager(**kwargs)

        # [:] will keep the reference of the original args
        args[:] = alias_manager.transform(args)

        if is_alias_command(['create', 'import'], args):
            load_cmd_tbl_func = kwargs.get('load_cmd_tbl_func', lambda _: {})
            cache_reserved_commands(load_cmd_tbl_func)

        elapsed_time = (timeit.default_timer() - start_time) * 1000
        logger.debug(DEBUG_MSG_WITH_TIMING, args, elapsed_time)

        telemetry.set_execution_time(round(elapsed_time, 2))
    except Exception as client_exception:  # pylint: disable=broad-except
        telemetry.set_exception(client_exception)
        raise
    finally:
        telemetry.conclude()
 def load_alias_table(self):
     """
     Load (create, if not exist) the alias config file.
     """
     try:
         # w+ creates the alias config file if it does not exist
         open_mode = 'r+' if os.path.exists(GLOBAL_ALIAS_PATH) else 'w+'
         with open(GLOBAL_ALIAS_PATH, open_mode) as alias_config_file:
             self.alias_config_str = alias_config_file.read()
         self.alias_table.read(GLOBAL_ALIAS_PATH)
         telemetry.set_number_of_aliases_registered(len(self.alias_table.sections()))
     except Exception as exception:  # pylint: disable=broad-except
         logger.warning(CONFIG_PARSING_ERROR, AliasManager.process_exception_message(exception))
         self.alias_table = get_config_parser()
         telemetry.set_exception(exception)
Beispiel #4
0
 def load_alias_table(self):
     """
     Load (create, if not exist) the alias config file.
     """
     try:
         # w+ creates the alias config file if it does not exist
         open_mode = 'r+' if os.path.exists(GLOBAL_ALIAS_PATH) else 'w+'
         with open(GLOBAL_ALIAS_PATH, open_mode) as alias_config_file:
             self.alias_config_str = alias_config_file.read()
         self.alias_table.read(GLOBAL_ALIAS_PATH)
         telemetry.set_number_of_aliases_registered(
             len(self.alias_table.sections()))
     except Exception as exception:  # pylint: disable=broad-except
         logger.warning(CONFIG_PARSING_ERROR,
                        AliasManager.process_exception_message(exception))
         self.alias_table = get_config_parser()
         telemetry.set_exception(exception)