Improve config check

This commit is contained in:
Yax 2022-11-13 13:09:36 +01:00
parent 07bdfbf240
commit 6722a0de5c
2 changed files with 13 additions and 3 deletions

5
run.py
View file

@ -41,7 +41,10 @@ def stacosys_server(config_pathname):
# load config
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)
# check database file exists (prevents from creating a fresh db)

View file

@ -71,12 +71,19 @@ class Config:
def get_bool(self, key: ConfigParameter):
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")
def check(self):
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):
d = dict()