spaceapi-server/spaceapi_server/config/__init__.py

35 lines
665 B
Python
Raw Normal View History

2019-11-25 02:48:12 +01:00
import json
# The parsed config object
__CONFIG = {}
def load(filename: str) -> None:
2019-11-25 03:14:14 +01:00
"""
2019-11-25 02:48:12 +01:00
Load a JSON-formatted configuration file.
2019-11-25 04:10:20 +01:00
:param filename: The config file to load.
2019-11-25 03:14:14 +01:00
"""
2019-11-25 02:48:12 +01:00
global __CONFIG
# Open and parse the JSON config file
with open(filename, 'r') as conf:
__CONFIG = json.load(conf)
def get() -> dict:
2019-11-25 03:14:14 +01:00
"""
2019-11-25 02:48:12 +01:00
Return the current configuration.
2019-11-25 03:14:14 +01:00
"""
2019-11-25 02:48:12 +01:00
global __CONFIG
return __CONFIG
2019-11-25 04:10:20 +01:00
def get_plugin_config(name: str):
"""
Return a plugin's configuration under .plugins[name]
:param name: The plugin name.
"""
global __CONFIG
return __CONFIG.get('plugins', {}).get(name, {})