From 7fa738d240d34d52b5b5b4a872dfd140c3b5c825 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Sat, 1 Apr 2023 14:13:04 +0200 Subject: [PATCH] test --- cbpi/__init__.py | 2 +- cbpi/api/dataclasses.py | 3 ++- cbpi/controller/config_controller.py | 9 +++------ cbpi/controller/plugin_controller.py | 24 ++++++++++++++++++++++++ 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index be197c8..7b27d51 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.1.7" +__version__ = "4.1.8.a1" __codename__ = "Groundhog Day" diff --git a/cbpi/api/dataclasses.py b/cbpi/api/dataclasses.py index 5007a64..c840f5c 100644 --- a/cbpi/api/dataclasses.py +++ b/cbpi/api/dataclasses.py @@ -199,11 +199,12 @@ class Config: description: str = None type: ConfigType = ConfigType.STRING options: Any = None + source: str = None def __str__(self): return "....name={} value={}".format(self.name, self.value) def to_dict(self): - return dict(name=self.name, value=self.value, type=self.type.value, description=self.description, options=self.options) + return dict(name=self.name, value=self.value, type=self.type.value, description=self.description, options=self.options, source=self.source) @dataclass class NotificationAction: diff --git a/cbpi/controller/config_controller.py b/cbpi/controller/config_controller.py index 6d62d79..2159706 100644 --- a/cbpi/controller/config_controller.py +++ b/cbpi/controller/config_controller.py @@ -19,21 +19,18 @@ class ConfigController: self.path_static = cbpi.config_folder.get_file_path("config.yaml") self.logger.info("Config folder path : " + os.path.join(Path(self.cbpi.config_folder.configFolderPath).absolute())) - def get_state(self): - + def get_state(self): result = {} for key, value in self.cache.items(): result[key] = value.to_dict() - - return result - + return result async def init(self): self.static = load_config(self.path_static) with open(self.path) as json_file: data = json.load(json_file) for key, value in data.items(): - self.cache[key] = Config(name=value.get("name"), value=value.get("value"), description=value.get("description"), type=ConfigType(value.get("type", "string")), options=value.get("options", None) ) + self.cache[key] = Config(name=value.get("name"), value=value.get("value"), description=value.get("description"), type=ConfigType(value.get("type", "string")), options=value.get("options", None), source=value.get("source", "craftbeerpi") ) def get(self, name, default=None): self.logger.debug("GET CONFIG VALUE %s (default %s)" % (name, default)) diff --git a/cbpi/controller/plugin_controller.py b/cbpi/controller/plugin_controller.py index e958371..23da582 100644 --- a/cbpi/controller/plugin_controller.py +++ b/cbpi/controller/plugin_controller.py @@ -205,6 +205,7 @@ class PluginController(): from importlib.metadata import (distribution, metadata, version) meta = metadata(key) + logging.warning(key) result.append({row: meta[row] for row in list(metadata(key))}) except Exception as e: @@ -215,3 +216,26 @@ class PluginController(): logger.error(e) return [] return result + + async def load_plugin_names(self, filter="cbpi"): + result = [] + result.append(dict(Name="craftbeerpi")) + try: + discovered_plugins = { + name: importlib.import_module(name) + for finder, name, ispkg + in pkgutil.iter_modules() + if name.startswith('cbpi') and len(name) > 4 + } + for key, module in discovered_plugins.items(): + try: + meta = metadata(key) + result.append(dict(Name=meta["Name"])) + + except Exception as e: + logger.error("FAILED to load plugin {} ".format(key)) + logger.error(e) + except Exception as e: + logger.error(e) + return result + return result