28 lines
596 B
Python
28 lines
596 B
Python
|
import os
|
||
|
|
||
|
import tomllib
|
||
|
|
||
|
|
||
|
class Settings:
|
||
|
def __init__(self, data: dict = None):
|
||
|
if data:
|
||
|
self._data = data
|
||
|
else:
|
||
|
with open(
|
||
|
os.getenv("RECTES_CONF_FILE", "/etc/rectes/rectes.toml"), "rb"
|
||
|
) as f:
|
||
|
self._data = tomllib.load(f)
|
||
|
|
||
|
def __getattr__(self, item):
|
||
|
try:
|
||
|
value = self._data[item]
|
||
|
except KeyError:
|
||
|
raise AttributeError
|
||
|
if isinstance(value, dict):
|
||
|
return Settings(data=value)
|
||
|
else:
|
||
|
return value
|
||
|
|
||
|
|
||
|
settings = Settings()
|