spaceapi-server/spaceapi_server/plugins/__init__.py

23 lines
575 B
Python
Raw Normal View History

2019-11-25 02:48:12 +01:00
2021-05-30 17:52:25 +02:00
import yaml
from spaceapi_server import config, template
2019-11-25 02:48:12 +01:00
def template_function(fn):
2019-11-25 03:14:14 +01:00
"""
2019-11-25 02:48:12 +01:00
Register the decorated function as a callable template function.
2019-11-25 04:10:20 +01:00
:param fn: The function to register.
2019-11-25 03:14:14 +01:00
"""
2021-05-30 17:52:25 +02:00
yaml.SafeLoader.add_constructor(f'!{fn.__name__}', template.plugin_constructor)
template.PluginInvocation.register_plugin(fn.__name__, fn)
2019-11-25 02:48:12 +01:00
return fn
def get_plugin_config(name: str):
2019-11-25 03:14:14 +01:00
"""
Return a plugin's configuration under .plugins[name]
:param name: The plugin name.
2019-11-25 03:14:14 +01:00
"""
return config.get().get('plugins', {}).get(name, {})