2019-11-25 02:48:12 +01:00
|
|
|
|
2021-05-30 17:52:25 +02:00
|
|
|
import yaml
|
|
|
|
|
2019-11-30 04:49:01 +01:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2019-11-30 04:49:01 +01:00
|
|
|
def get_plugin_config(name: str):
|
2019-11-25 03:14:14 +01:00
|
|
|
"""
|
2019-11-30 04:49:01 +01:00
|
|
|
Return a plugin's configuration under .plugins[name]
|
|
|
|
:param name: The plugin name.
|
2019-11-25 03:14:14 +01:00
|
|
|
"""
|
2019-11-30 04:49:01 +01:00
|
|
|
return config.get().get('plugins', {}).get(name, {})
|