forked from platypush/platypush
[inspect
] Added get_enabled_plugins
and get_enabled_backends
actions.
This commit is contained in:
parent
c05d887551
commit
c7acc03c8f
2 changed files with 38 additions and 0 deletions
|
@ -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:
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue