def __get_set_matches(self, lines, line_matchers): for matcher in line_matchers: PTS.line("GET_SET_MATCHES", '', '', matcher, lines) matcher_type = matcher['type'].lower() if matcher_type == 'array': self.__iterate_lines_for_array_match(lines, matcher) elif matcher_type == 'bool': self.__iterate_lines_for_bool_match(lines, matcher)
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
def run(self, command_item, buffer_name=''): command_item_buffer_name = command_item.get("buffer_name", "") cci = ConfigCommandItem() cci.command = command_item['name'] cci.calling_buffer_name = buffer_name cci.buffer_name = command_item_buffer_name or buffer_name PTS.info("RUN_CONFIG_COMMAND", cci.command, cci.buffer_name, command_item) ConfigCommand().run_config_command(cci)
def run(self, command_item, buffer_name=''): buffer_name = buffer_name or command_item.get("buffer_name", '') command_value = command_item['command'] interpolated_command_value = Interpolate.interpolate_variables( command_value) PTS.info("RUN_COMMAND", interpolated_command_value, buffer_name, command_item) return CommandHandler().run_command(interpolated_command_value, buffer_name)
def __run_config_command_action(self, command_action, config_command_item): ok_to_run = self.__condition.is_ok_to_run(command_action.when_condition) if len(command_action.when_condition) > 0: PTS.info("WHEN_CONDITION", command_action.action_name, config_command_item.buffer_name, "Run: " + str(ok_to_run) + ", To Run: " + str(command_action.action_value.get("name", "")) + ", Condition: '" + str(command_action.when_condition) + "'") if ok_to_run: action_args = self.__converter.to_action_args(command_action.action_value, command_action.event_input_args, command_action.buffer_name) lines = Action.run_action(command_action.action_name, action_args) buffer_cache = ConfigCommandBufferCache(config_command_item.buffer_name) buffer_cache.set(lines, config_command_item, command_action, action_args)
def run(self, command_item, buffer_name=''): PTS.info("RUN_COMMAND_WITH_MATCH", command_item["command"], buffer_name, command_item) self.__set_locals(command_item, buffer_name) self._lines = CommandHandler().run_command(self._command_item_command) if self._try_set_var: self.__get_match() if self._try_set_array_var: self.__get_array_match() self.__try_set_variable() PTS.info("*RUN_COMMAND_WITH_MATCH", str(command_item["command"]), str(buffer_name), "Match: '" + str(self._regex_match) + "', Var: '" + str(self._try_set_var) + "', Result: '" + str(self._match_result) + str(self._try_set_array_var) + "'")
def run(self, command_item, buffer_name=''): if buffer_name: template_paths = Ph.get_paths_for_plugin('templates') template_filename = command_item.get("filename", '') PTS.info("DISPLAY_TEMPLATE", template_filename, buffer_name, command_item) for templates_path in template_paths: template_filename_path = os.path.join(templates_path, template_filename) if os.path.isfile(template_filename_path): self.__process_template_file(buffer_name, templates_path, template_filename) break
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 run(self, command_item, buffer_name=''): self.__set_locals(command_item, buffer_name) if self._event_input_args: self._event_input_args = self.__get_interpolated_args( self._event_input_args) if self._function_args: self._function_args = self.__get_interpolated_args( self._function_args) PTS.info("RUN_EDITOR_FUNCTION", self._function_name, buffer_name, command_item) return self.__run_command()
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"])
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 filter_string(lines, filter_name): if filter_name.lower() in FILTERED_BUFFERS_LIST: buffer_filter = create_object(filter_name)() buffer_filter.process(lines) return buffer_filter.processed_lines if filter_name.lower() in FILTERED_BUFFERS_CONFIG_LIST: PTS.line("FILTER_STRING", filter_name, '', '', '') buffer_filter = FILTERED_BUFFER_CONFIG_OBJECTS_DICT[ filter_name.lower()] buffer_filter.process(lines) return buffer_filter.processed_lines return lines
def process(self, lines): PTS.line("FILTER_PROCESS", 'START', '', '', '') for raw_line in lines.split("\n") if isinstance(lines, str) else lines: PTS.line("RAW_LINE", '', '', '', raw_line) self.__get_set_matches(lines, self.line_matchers_pre) self.processed_lines = self.__process_lines(lines) self.__get_set_matches(self.processed_lines, self.line_matchers_post) PTS.line("FILTER_PROCESS", 'END', '', '', self.processed_lines)
def run(self, command_item, buffer_name='', command_args=None): self.__set_locals(command_item, buffer_name, command_args or {}) self.__set_function_module_locals() self.__update_command_args() self.__run_function_update_variable() PTS.info("RUN_PYTHON_FUNCTION", self._function_name, buffer_name, command_item)