Improve config check
This commit is contained in:
parent
07bdfbf240
commit
6722a0de5c
2 changed files with 13 additions and 3 deletions
5
run.py
5
run.py
|
@ -41,7 +41,10 @@ def stacosys_server(config_pathname):
|
||||||
|
|
||||||
# load config
|
# load config
|
||||||
conf = Config.load(config_pathname)
|
conf = Config.load(config_pathname)
|
||||||
conf.check()
|
is_config_ok, erreur_config = conf.check()
|
||||||
|
if not is_config_ok:
|
||||||
|
logger.error(f"Configuration incorrecte '{erreur_config}'")
|
||||||
|
sys.exit(1)
|
||||||
logger.info(conf)
|
logger.info(conf)
|
||||||
|
|
||||||
# check database file exists (prevents from creating a fresh db)
|
# check database file exists (prevents from creating a fresh db)
|
||||||
|
|
|
@ -71,12 +71,19 @@ class Config:
|
||||||
|
|
||||||
def get_bool(self, key: ConfigParameter):
|
def get_bool(self, key: ConfigParameter):
|
||||||
value = self.get(key)
|
value = self.get(key)
|
||||||
assert value in ("yes", "true", "no", "false")
|
assert value in (
|
||||||
|
"yes",
|
||||||
|
"true",
|
||||||
|
"no",
|
||||||
|
"false",
|
||||||
|
), f"Parameètre booléen incorrect {key.value}"
|
||||||
return value in ("yes", "true")
|
return value in ("yes", "true")
|
||||||
|
|
||||||
def check(self):
|
def check(self):
|
||||||
for key in ConfigParameter:
|
for key in ConfigParameter:
|
||||||
assert self.get(key), f"Paramètre introuvable : {key.value}"
|
if not self.get(key):
|
||||||
|
return (False, key.value)
|
||||||
|
return (True, None)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
d = dict()
|
d = dict()
|
||||||
|
|
Loading…
Add table
Reference in a new issue