From 798d25e75c7e6b4305f4444cba67d3bc1eae4ab1 Mon Sep 17 00:00:00 2001 From: martin Date: Sat, 29 Mar 2025 16:37:05 +0100 Subject: [PATCH] LogTrigger: fixed substrings output --- cpu_governor_auto_adjust/triggers/log.py | 17 +++++++++++++---- pyproject.toml | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/cpu_governor_auto_adjust/triggers/log.py b/cpu_governor_auto_adjust/triggers/log.py index a8f76f6..9cfc983 100644 --- a/cpu_governor_auto_adjust/triggers/log.py +++ b/cpu_governor_auto_adjust/triggers/log.py @@ -20,9 +20,15 @@ class TriggerString: @cached_property def substrings(self) -> list[str]: + _substrings = [] if 'substrings' in self.json_data: - return self.json_data['substrings']['substring'] - return [] + if isinstance(self.json_data['substrings']['substring'], list): + _substrings.extend(self.json_data['substrings']) + elif isinstance(self.json_data['substrings']['substring'], str): + _substrings.append(self.json_data['substrings']['substring']) + else: + raise ValueError("substrings must be a list or a string") + return _substrings @cached_property def condition(self) -> str: @@ -69,12 +75,15 @@ class LogTrigger(Trigger): self.timestamp_last_active_change = datetime.now() if not self.active: self.log.info("activating trigger, log file: %s, trigger strings: %s, governor: %s", self.file, self.trigger_strings, self.governor.name) - self.active = True + self.active = True + self.log.info("Statistics: %s", self.get_statistic_info()) + def set_inactive(self) -> None: if self.active: self.log.info("deactivating trigger, log file: %s, trigger strings: %s, governor: %s", self.file, self.trigger_strings, self.governor.name) - self.active = False + self.active = False + self.log.info("Statistics: %s", self.get_statistic_info()) def _process_line(self, line: str) -> None: for trigger_string in self.trigger_strings: diff --git a/pyproject.toml b/pyproject.toml index ffad25b..864488f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "cpu_governor_auto_adjust" -version = "0.2.5" +version = "0.2.9" description = "This application has been developed to automatically change cpu governor based on certain triggers." authors = [ { name = "Martin Reurekas", email = "martin@semrks.nl" }