diff --git a/flaschengeist/config.py b/flaschengeist/config.py index cda1e4f..100d6e3 100644 --- a/flaschengeist/config.py +++ b/flaschengeist/config.py @@ -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):