check configuration

pull/11/head
Yax 2 years ago
parent 57d6039e18
commit f8beb5f859

@ -39,9 +39,10 @@ def stacosys_server(config_pathname):
logger.error(f"Configuration file '{config_pathname}' not found.") logger.error(f"Configuration file '{config_pathname}' not found.")
sys.exit(1) sys.exit(1)
# initialize config # load config
conf = Config.load(config_pathname) conf = Config.load(config_pathname)
logger.info(conf.__repr__()) conf.check()
logger.info(conf)
# check database file exists (prevents from creating a fresh db) # check database file exists (prevents from creating a fresh db)
db_pathname = conf.get(ConfigParameter.DB_SQLITE_FILE) db_pathname = conf.get(ConfigParameter.DB_SQLITE_FILE)
@ -70,7 +71,7 @@ def stacosys_server(config_pathname):
conf.get_int(ConfigParameter.SMTP_PORT), conf.get_int(ConfigParameter.SMTP_PORT),
conf.get(ConfigParameter.SMTP_LOGIN), conf.get(ConfigParameter.SMTP_LOGIN),
conf.get(ConfigParameter.SMTP_PASSWORD), conf.get(ConfigParameter.SMTP_PASSWORD),
conf.get(ConfigParameter.SITE_ADMIN_EMAIL) conf.get(ConfigParameter.SITE_ADMIN_EMAIL),
) )
# inject config parameters into flask # inject config parameters into flask

@ -74,6 +74,10 @@ class Config:
assert value in ("yes", "true", "no", "false") assert value in ("yes", "true", "no", "false")
return value in ("yes", "true") return value in ("yes", "true")
def check(self):
for key in ConfigParameter:
assert self.get(key), f"Paramètre introuvable : {key.value}"
def __repr__(self): def __repr__(self):
d = dict() d = dict()
for section in self._cfg.sections(): for section in self._cfg.sections():

Loading…
Cancel
Save