[System] config now deep update when multiple config files are used

This commit is contained in:
Ferdinand Thiessen 2020-10-30 23:59:07 +01:00
parent f60c06bc17
commit 9455920141
1 changed files with 19 additions and 6 deletions

View File

@ -1,24 +1,37 @@
import logging.config
import os
import toml
import logging.config
import collections.abc
from pathlib import Path
from werkzeug.middleware.proxy_fix import ProxyFix
from flaschengeist import _module_path, logger
def __update(d, u):
for k, v in u.items():
if isinstance(v, collections.abc.Mapping):
d[k] = __update(d.get(k, {}), v)
else:
d[k] = v
return d
# Default config:
config = {}
paths = [_module_path, Path.home() / ".config"]
__paths = [_module_path, Path.home() / ".config"]
if "FLASCHENGEIST_CONF" in os.environ:
paths.append(Path(os.environ.get("FLASCHENGEIST_CONF")))
for loc in paths:
__paths.append(Path(os.environ.get("FLASCHENGEIST_CONF")))
for loc in __paths:
try:
with (loc / "flaschengeist.toml").open() as source:
logger.info("Reading config file from >{}<".format(loc))
config.update(toml.load(source))
__update(config, toml.load(source))
except IOError:
pass
# Always enable this builtin plugins!
config.update({"auth": {"enabled": True}, "roles": {"enabled": True}, "users": {"enabled": True}})
__update(config, {"auth": {"enabled": True}, "roles": {"enabled": True}, "users": {"enabled": True}})
def configure_app(app):