forked from ScoDoc/DocScoDoc
45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
|
# -*- mode: python -*-
|
||
|
# -*- coding: utf-8 -*-
|
||
|
|
||
|
"""Chargement de la configuration locale
|
||
|
"""
|
||
|
import os
|
||
|
import sys
|
||
|
|
||
|
import sco_utils
|
||
|
from sco_utils import log, SCODOC_CFG_DIR
|
||
|
import sco_config
|
||
|
|
||
|
# scodoc_local defines a CONFIG object
|
||
|
# here we check if there is a local config file
|
||
|
|
||
|
|
||
|
def load_local_configuration():
|
||
|
"""Load local configuration file (if exists)
|
||
|
and merge it with CONFIG.
|
||
|
"""
|
||
|
# this path should be synced with upgrade.sh
|
||
|
LOCAL_CONFIG_FILENAME = os.path.join(SCODOC_CFG_DIR, "scodoc_local.py")
|
||
|
LOCAL_CONFIG = None
|
||
|
if os.path.exists(LOCAL_CONFIG_FILENAME):
|
||
|
if not SCODOC_CFG_DIR in sys.path:
|
||
|
sys.path.insert(1, SCODOC_CFG_DIR)
|
||
|
try:
|
||
|
from scodoc_local import CONFIG as LOCAL_CONFIG
|
||
|
|
||
|
log("imported %s" % LOCAL_CONFIG_FILENAME)
|
||
|
except ImportError:
|
||
|
log("Error: can't import %s" % LOCAL_CONFIG_FILENAME)
|
||
|
del sys.path[1]
|
||
|
if LOCAL_CONFIG is None:
|
||
|
return
|
||
|
# Now merges local config in our CONFIG
|
||
|
for x in [x for x in dir(LOCAL_CONFIG) if x[0] != "_"]:
|
||
|
v = getattr(LOCAL_CONFIG, x)
|
||
|
if not v in sco_config.CONFIG:
|
||
|
log("Warning: local config setting unused parameter %s (skipped)" % x)
|
||
|
else:
|
||
|
if v != sco_config.CONFIG[x]:
|
||
|
log("Setting parameter %s from %s" % (x, LOCAL_CONFIG_FILENAME))
|
||
|
sco_config.CONFIG[x] = v
|