[System] config now deep update when multiple config files are used
This commit is contained in:
parent
f60c06bc17
commit
9455920141
|
@ -1,24 +1,37 @@
|
||||||
import logging.config
|
|
||||||
import os
|
import os
|
||||||
import toml
|
import toml
|
||||||
|
import logging.config
|
||||||
|
import collections.abc
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||||
from flaschengeist import _module_path, logger
|
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:
|
# Default config:
|
||||||
config = {}
|
config = {}
|
||||||
paths = [_module_path, Path.home() / ".config"]
|
|
||||||
|
__paths = [_module_path, Path.home() / ".config"]
|
||||||
if "FLASCHENGEIST_CONF" in os.environ:
|
if "FLASCHENGEIST_CONF" in os.environ:
|
||||||
paths.append(Path(os.environ.get("FLASCHENGEIST_CONF")))
|
__paths.append(Path(os.environ.get("FLASCHENGEIST_CONF")))
|
||||||
for loc in paths:
|
for loc in __paths:
|
||||||
try:
|
try:
|
||||||
with (loc / "flaschengeist.toml").open() as source:
|
with (loc / "flaschengeist.toml").open() as source:
|
||||||
logger.info("Reading config file from >{}<".format(loc))
|
logger.info("Reading config file from >{}<".format(loc))
|
||||||
config.update(toml.load(source))
|
__update(config, toml.load(source))
|
||||||
except IOError:
|
except IOError:
|
||||||
pass
|
pass
|
||||||
# Always enable this builtin plugins!
|
# 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):
|
def configure_app(app):
|
||||||
|
|
Loading…
Reference in New Issue