spaceapi-server/spaceapi_server/config/__init__.py

26 lines
454 B
Python
Raw Normal View History

2019-11-25 02:48:12 +01:00
2021-05-30 17:52:25 +02:00
import yaml
2019-11-25 02:48:12 +01:00
# The parsed config object
__CONFIG = {}
def load(filename: str) -> None:
2019-11-25 03:14:14 +01:00
"""
2021-05-30 17:52:25 +02:00
Load a YAML-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
2021-05-30 17:52:25 +02:00
# Open and parse the YAML config file
2019-11-25 02:48:12 +01:00
with open(filename, 'r') as conf:
2021-05-30 17:52:25 +02:00
__CONFIG = yaml.safe_load(conf)
2019-11-25 02:48:12 +01:00
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
2019-12-02 22:32:17 +01:00
return __CONFIG