Improve config check

pull/11/head
Yax 2 years ago
parent 07bdfbf240
commit 6722a0de5c

@ -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)

@ -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()

Loading…
Cancel
Save