Esempio n. 1
0
 def __init__(self):
     self.__base_filter_name = Config().get_setting("buffers",
                                                    "base_filter_name")
     self.__error_filter_name = Config().get_setting(
         "buffers", "error_filter_name")
     self.__error_buffer_name = Config().get_setting(
         "buffers", "error_buffer_name")
Esempio n. 2
0
 def run(self, command_item, buffer_name=''):
     set_variable = command_item.get("set_variable", '')
     if set_variable:
         interpolated_set_variable = Interpolate.interpolate_variables(
             set_variable)
         buffer_name = Config().get_editor_wrapper(
         ).get_current_buffer_name()
         Config().set_variable(interpolated_set_variable, buffer_name)
Esempio n. 3
0
 def __process_template_file(self, buffer_name, templates_path, template_filename):
     template_loader = jinja2.FileSystemLoader(searchpath=templates_path)
     template_env = jinja2.Environment(loader=template_loader)
     template = template_env.get_template(template_filename)
     config_variables = Config().get_variables()
     output_text = template.render(config_variables)
     if output_text:
         output_text_array = output_text.split('\n')
         Config().set_internal_buffer_cache(buffer_name, output_text_array)
Esempio n. 4
0
def test__can_run_command_and_set_test_buffer():
    try:
        test_tide = Tide()
        command_handler = CommandHandler()
        command_handler.spawn_process()
        buffer_result = Config().get_internal_buffer_caches()
        test_tide.run_config_command('test_command')
        assert "test_buffer" in buffer_result.keys()
    except Exception as ex:
        pytest.fail("error initialising CommandHandler: " + str(ex))
Esempio n. 5
0
def test__can_run_command_and_set_session_log_buffer():
    try:
        from tide.config.config import Config
        command_handler = CommandHandler()
        command_handler.spawn_process()
        result = command_handler.run_command("echo hi")
        buffer_result = Config().get_internal_buffer_caches()
        assert buffer_result.get("vg_session_log") is not None
    except Exception as ex:
        pytest.fail("error initialising CommandHandler: " + str(ex))
Esempio n. 6
0
 def __init__(self):
     self.default_args = Config().get_setting(
         "process", "main_process_default_arguments")
     self.end_of_output_regex = Config().get_setting(
         "process", "end_of_output_regex")
     self.find_full_proc_name = Config().get_setting(
         "process", "find_full_process_name")
     self.main_proc_name = Config().get_setting("process",
                                                "main_process_name")
     self.ttl_stream_timeout = Config().get_setting("process",
                                                    "ttl_stream_timeout")
Esempio n. 7
0
def check_set_remote(command_args):
    if 'target remote' in command_args["process_command"].lower():
        binary_loaded = False
        symbols_found = True
        for line in command_args["lines"]:
            if 'Reading symbols from' in line or '(no debugging symbols found)' in line:
                binary_loaded = True
            if '(no debugging symbols found)' in line:
                symbols_found = False
        Config().set_variable('remote_target', 1)
        Config().set_variable('binary_loaded', int(binary_loaded))
        Config().set_variable('symbols_loaded',
                              int(symbols_found and binary_loaded))
Esempio n. 8
0
 def run(self, command_item, buffer_name=''):
     msg = command_item.get("msg", '')
     interpolated_message = Interpolate.interpolate_variables(msg)
     buffer_name = command_item.get("buffer_name", 0)
     all_config = command_item.get("all_config", 0)
     print("print_debug:")
     if all_config:
         print("  all_config:\n  ")
         json.dump(Config().get(), sys.stdout, indent=4)
     if buffer_name:
         print("  buffer name:\n  ")
         json.dump(Config().get_buffer(buffer_name), sys.stdout, indent=4)
     print("" + str(interpolated_message))
Esempio n. 9
0
def test_does_not_raise_exception_on_initialisation():
    try:
        config_command_action_list = Config().get(
        )["commands"]["test_command"]["steps"][0]
        command_action = CommandAction(config_command_action_list, '')
    except Exception as ex:
        pytest.fail("error initialising CommandAction: " + str(ex))
Esempio n. 10
0
 def __create_config_command_item(self, command, buffer_name, event_name):
     config_command_item = ConfigCommandItem()
     config_command_item.command = command
     config_command_item.buffer_name = buffer_name if buffer_name else Config(
     ).get_buffer_name_for_command(command)
     config_command_item.event_name = event_name
     return config_command_item
Esempio n. 11
0
 def run(self, command_item, buffer_name=''):
     variable_name = command_item['variable_name']
     variable_value = Config().get_variable(variable_name)
     PTS.info("RUN_COMMAND_STRING", variable_name, buffer_name,
              command_item)
     if variable_value:
         return CommandHandler().run_command(variable_value, buffer_name)
     return None
Esempio n. 12
0
def test_has_command_action_of_type_run_command():
    try:
        config_command_action_list = Config().get(
        )["commands"]["test_command"]["steps"][0]
        command_action = CommandAction(config_command_action_list, '')
        assert 'run_command' == command_action.action_name
    except Exception as ex:
        pytest.fail("error initialising CommandAction: " + str(ex))
Esempio n. 13
0
 def __find_event_input_args(self):
     if self.__command and self.__buffer_name and self.__event_name:
         event_command_list = Config().get_buffer_events_by_name(
             self.__buffer_name, self.__event_name)
         for event_command in event_command_list:
             if event_command["command"] == self.__command:
                 return event_command.get("input_args", [])
     return None
Esempio n. 14
0
def __filter_log_string_and_add_to_buffer_cache(log_string):
    log_lines = Filter.filter_string(log_string, SESSION_BUFFER_NAME)
    full_cache = Config().get_internal_buffer_cache(SESSION_BUFFER_NAME)
    if ADD_TIMESTAMP:
        full_cache.append(__get_timestamp_separator())
    full_cache.extend(log_lines)
    Config().set_internal_buffer_cache(SESSION_BUFFER_NAME, full_cache)
Esempio n. 15
0
 def __process_when_condition(self):
     when_condition = self.__when_condition
     for variable in Config().get_variable_names():
         if variable in self.__when_condition:
             config_variable = self.__sanitise_config_variable(variable)
             when_condition = when_condition.replace(
                 variable, config_variable)
     self.__eval_when_condition = eval(when_condition
                                       or self.__when_condition)
Esempio n. 16
0
 def __iterate_lines_for_bool_match(self, lines, matcher):
     match_regex = matcher['regex']
     match_variable = matcher["variable_name"]
     for line in lines:
         match = re.search(match_regex, line)
         if match:
             PTS.line("MATCH_BOOL", match_variable, match_regex, True, line)
             Config().get_variables()[matcher["variable_name"]] = 1
             return
         PTS.line("MATCH_BOOL", match_variable, match_regex, False, line)
def test__run_command_with_match_on_hex():
    try:
        tide_handler = Tide('test_mock')
        tide_handler.start()
        tide_handler.run_config_command("test_command")
        result = Config().get_variable("test_match_variable")
        tide_handler.stop()
        assert result == '0x00001234abcd'
    except Exception as ex:
        pytest.fail("error in filter tests: " + str(ex))
Esempio n. 18
0
def test__run_command_with_match_on_array():
    try:
        tide_handler = Tide()
        tide_handler.start()
        tide_handler.run_config_command("test_command")
        result = Config().get_variable("test_match_array")
        tide_handler.stop()
        assert '0x00001234abce' in result
        assert '0x000000009876' in result
    except Exception as ex:
        pytest.fail("error in filter tests: " + str(ex))
Esempio n. 19
0
 def stop(self):
     try:
         Config().get_editor_wrapper().stop_tide()
         self.__command_handler.close_command_handler()
         del self.__command_handler
         self.__command_handler = None
         SPC.remove_all()
     except Exception as ex:
         print(
             f"error in TideAction.stop(): {str(ex)}\n Traceback: {traceback.format_exc()}"
         )
Esempio n. 20
0
 def __iterate_lines_for_array_match(self, lines, matcher):
     matches_list = []
     match_regex = matcher['regex']
     match_variable = matcher["variable_name"]
     for line in lines:
         match = re.search(matcher['regex'], line)
         if match:
             PTS.line("MATCH_ARRAY", match_variable, match_regex, match.group(1), line)
             matches_list.append(match.group(1))
         else:
             PTS.line("MATCH_ARRAY", match_variable, match_regex, None, line)
     Config().get_variables()[matcher["variable_name"]] = matches_list
 def run(self, command_item, buffer_name=''):
     PTS.info("RUN_COMMAND_WITH_MATCH_GROUP", command_item["command"],
              buffer_name, command_item)
     self.__set_locals(command_item, buffer_name)
     self._lines = CommandHandler().run_command(
         self._command_item["command"])
     temp_dict = {}
     for key, value in self._match_dictionary.items():
         temp_dict[key] = self.__get_match(value)
     self._match_dictionary.update(temp_dict)
     for key, value in self._match_dictionary.items():
         Config().set_variable(key, value["result"])
Esempio n. 22
0
 def start(self, startup_commands):
     try:
         self.__command_handler = CommandHandler()
         self.__command_handler.spawn_process(startup_commands)
         self.__startup_commands.run()
         self.__buffer_commands.run()
         Config().get_editor_wrapper().send_message_to_editor(
             {"startup_complete": True})
     except Exception as ex:
         print(
             f"error in TideAction.start(): {str(ex)}\n Traceback: {traceback.format_exc()}"
         )
Esempio n. 23
0
def test__can_run_command_and_set_test_buffer_has_value_of_line():
    try:
        test_tide = Tide()
        command_handler = CommandHandler()
        command_handler.spawn_process()
        buffer_result = Config().get_internal_buffer_caches()
        test_tide.run_config_command('test_command')
        assert buffer_result["test_buffer"][0] == 'echo "hello"\r'
        assert buffer_result["test_buffer"][1] == 'hello\r'
        assert buffer_result["test_buffer"][
            2] == '/work/tide/tests/pytest_tests # \x1b[6n'
    except Exception as ex:
        pytest.fail("error initialising CommandHandler: " + str(ex))
Esempio n. 24
0
 def to_command_action_list(self):
     command_action_list = Config().get_command_steps(self.__command)
     updated_command_action_list = []
     for command_action_config in command_action_list:
         updated_command_action_config = command_action_config.copy()
         event_input_args = self.__find_event_input_args()
         if event_input_args:
             updated_command_action_config[
                 "event_input_args"] = event_input_args
         command_action_object = CommandAction(
             updated_command_action_config, self.__buffer_name)
         updated_command_action_list.append(command_action_object)
     return updated_command_action_list
Esempio n. 25
0
 def info(command_type, command, buffer_name, value):
     if Config().get_setting("debugging", "print_to_stdout"):
         heading_text = "[INFO]"
         command_type_text = "[" + str(command_type) + "]"
         command_text = "[" + str(command) + "]"
         buffer_text = "[" + str(buffer_name) + "]"
         value_text = str(value)
         command_type_text = command_type_text.ljust(
             30) if ljust else command_type_text
         command_text = command_text.ljust(28) if ljust else command_text
         buffer_text = buffer_text.ljust(20) if ljust else buffer_text
         value_text = (value_text[:110] +
                       '..') if len(value_text) > 110 else value_text
         print(heading_text, command_type_text, command_text, buffer_text,
               value_text)
Esempio n. 26
0
 def line(filter_type, process_or_match, process_or_match_on, result,
          raw_value):
     if Config().get_setting("debugging",
                             "print_to_stdout") and Config().get_setting(
                                 "debugging", "print_to_stdout_filters"):
         heading_text = "[INFO]"
         filter_type_text = "[" + str(filter_type) + "]"
         process_or_match_text = "[" + str(process_or_match) + "]"
         process_or_match_on_text = (
             process_or_match_on[:25] +
             '..') if len(process_or_match_on) > 25 else process_or_match_on
         process_or_match_on_text = "[" + str(process_or_match_on) + "]"
         result_text = "[" + str(result) + "]"
         raw_value_string = str(raw_value)
         raw_value_text = (
             raw_value_string[:75] +
             '..') if len(raw_value_string) > 75 else raw_value_string
         if ljust:
             filter_type_text = filter_type_text.ljust(30)
             process_or_match_text = process_or_match_text.ljust(30)
             process_or_match_on_text = process_or_match_on_text.ljust(28)
             result_text = result_text.ljust(10)
         print(heading_text, filter_type_text, process_or_match_text,
               process_or_match_on_text, result_text, raw_value_text)
Esempio n. 27
0
 def __initialise_buffer_in_config(self, buffer_name):
     if buffer_name not in Config().get_internal_buffer_caches():
         if not Config().get_internal_buffer_caches():
             Config().set_internal("buffer_caches", {})
         Config().set_internal_buffer_cache(buffer_name, [])
Esempio n. 28
0
 def set(self, lines, config_command_item, command_action, action_args):
     if lines:
         internal_buffer_name = config_command_item.buffer_name or self.__get_internal_buffer_name(action_args)
         lines = self.__set_lines_where_no_buffer_name(internal_buffer_name, lines, command_action)
         Config().set_internal_buffer_cache(internal_buffer_name, lines)
Esempio n. 29
0
 def __sanitise_config_variable(self, variable):
     config_variable = str(Config().get_variable(variable))
     if " " in config_variable or not config_variable:
         config_variable = "'" + str(config_variable) + "'"
     return config_variable
Esempio n. 30
0
 def __try_set_variable(self):
     if self._match_result:
         if self._try_set_var:
             Config().get()["variables"][self._try_set_var] = self._match_result
         if self._try_set_array_var:
             Config().get()["variables"][self._try_set_array_var] = self._match_result