From c7acc03c8fe0e3679295915ccb3b972ab2701735 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 18 Oct 2023 22:10:32 +0200 Subject: [PATCH] [`inspect`] Added `get_enabled_plugins` and `get_enabled_backends` actions. --- platypush/plugins/inspect/__init__.py | 15 +++++++++++++++ platypush/utils/__init__.py | 23 +++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/platypush/plugins/inspect/__init__.py b/platypush/plugins/inspect/__init__.py index 2267787798..f1307bd161 100644 --- a/platypush/plugins/inspect/__init__.py +++ b/platypush/plugins/inspect/__init__.py @@ -15,6 +15,7 @@ from platypush.plugins import Plugin, action from platypush.message import Message from platypush.message.event import Event from platypush.message.response import Response +from platypush.utils import get_enabled_backends, get_enabled_plugins from platypush.utils.mock import auto_mocks from platypush.utils.manifest import Manifest, Manifests @@ -270,5 +271,19 @@ class InspectPlugin(Plugin): return Config.get() + @action + def get_enabled_plugins(self) -> List[str]: + """ + Get the list of enabled plugins. + """ + return list(get_enabled_plugins().keys()) + + @action + def get_enabled_backends(self) -> List[str]: + """ + Get the list of enabled backends. + """ + return list(get_enabled_backends().keys()) + # vim:sw=4:ts=4:et: diff --git a/platypush/utils/__init__.py b/platypush/utils/__init__.py index a1e99d0788..b49b158fc1 100644 --- a/platypush/utils/__init__.py +++ b/platypush/utils/__init__.py @@ -564,6 +564,29 @@ def get_enabled_plugins() -> dict: return plugins +def get_enabled_backends() -> dict: + """ + Get the enabled backends. + + :return: A dictionary with the enabled backends, in the format ``name`` -> + :class:`platypush.backend.Backend` instance. + """ + from platypush.config import Config + from platypush.context import get_backend + + backends = {} + for name in Config.get_backends(): + try: + backend = get_backend(name.removeprefix('backend.')) + if backend: + backends[name] = backend + except Exception as e: + logger.warning('Could not initialize backend %s', name) + logger.exception(e) + + return backends + + def get_redis_conf() -> dict: """ Get the Redis connection arguments from the configuration.