Skip to content

Commit

Permalink
Improve config check
Browse files Browse the repository at this point in the history
  • Loading branch information
kianby committed Nov 13, 2022
1 parent 07bdfbf commit 6722a0d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 4 additions & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions stacosys/conf/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,19 @@ def get_int(self, key: ConfigParameter):

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()
Expand Down

0 comments on commit 6722a0d

Please sign in to comment.