2020-12-15 08:35:44 +01:00
|
|
|
# -*- mode: python -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""Chargement de la configuration locale
|
|
|
|
"""
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2021-08-29 19:57:32 +02:00
|
|
|
from app import log
|
2021-06-19 23:21:37 +02:00
|
|
|
from app.scodoc import sco_config
|
2020-12-15 08:35:44 +01:00
|
|
|
|
|
|
|
# scodoc_local defines a CONFIG object
|
|
|
|
# here we check if there is a local config file
|
|
|
|
|
|
|
|
|
2021-05-29 18:22:51 +02:00
|
|
|
def load_local_configuration(scodoc_cfg_dir):
|
2020-12-15 08:35:44 +01:00
|
|
|
"""Load local configuration file (if exists)
|
|
|
|
and merge it with CONFIG.
|
|
|
|
"""
|
2021-09-05 12:30:11 +02:00
|
|
|
local_config_filename = os.path.join(scodoc_cfg_dir, "scodoc_local.py")
|
|
|
|
local_config = None
|
|
|
|
if os.path.exists(local_config_filename):
|
2021-05-29 18:22:51 +02:00
|
|
|
if not scodoc_cfg_dir in sys.path:
|
2021-09-05 12:30:11 +02:00
|
|
|
sys.path.insert(0, scodoc_cfg_dir)
|
2020-12-15 08:35:44 +01:00
|
|
|
try:
|
2021-09-05 12:30:11 +02:00
|
|
|
from scodoc_local import CONFIG as local_config
|
2020-12-15 08:35:44 +01:00
|
|
|
|
2021-09-05 12:30:11 +02:00
|
|
|
log("imported %s" % local_config_filename)
|
2020-12-15 08:35:44 +01:00
|
|
|
except ImportError:
|
2021-09-05 12:30:11 +02:00
|
|
|
log("Error: can't import %s" % local_config_filename)
|
|
|
|
del sys.path[0]
|
|
|
|
if local_config is None:
|
2020-12-15 08:35:44 +01:00
|
|
|
return
|
|
|
|
# Now merges local config in our CONFIG
|
2021-09-05 12:30:11 +02:00
|
|
|
for x in [x for x in local_config if x[0] != "_"]:
|
|
|
|
v = local_config.get(x)
|
|
|
|
if not x in sco_config.CONFIG:
|
|
|
|
log(f"Warning: local config setting unused parameter {x} (skipped)")
|
2020-12-15 08:35:44 +01:00
|
|
|
else:
|
|
|
|
if v != sco_config.CONFIG[x]:
|
2021-09-05 12:30:11 +02:00
|
|
|
log(f"Setting parameter {x} from {local_config_filename}")
|
2020-12-15 08:35:44 +01:00
|
|
|
sco_config.CONFIG[x] = v
|