generalConfig: fix the case when confdir is a list of paths

convert all env variable values containing ':' into a list of paths
+ fix one case where an env variable is not converted to a Path
+ remove unused _gcfg_help

Change-Id: Ibc51ab4606ca51e0e87d0fedfac1aca4952f3270
Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/34872
Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de>
Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de>
Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
This commit is contained in:
zolliker 2024-10-24 13:58:38 +02:00
parent eac58982d9
commit 8e05090795

View File

@ -37,10 +37,6 @@ from pathlib import Path
SECoP_DEFAULT_PORT = 10767 SECoP_DEFAULT_PORT = 10767
_gcfg_help = """
"""
class GeneralConfig: class GeneralConfig:
"""generalConfig holds server configuration items """generalConfig holds server configuration items
@ -94,17 +90,16 @@ class GeneralConfig:
if cfg.get('confdir') is None: if cfg.get('confdir') is None:
cfg['confdir'] = configfile.parent cfg['confdir'] = configfile.parent
# environment variables will overwrite the config file # environment variables will overwrite the config file
missing_keys = []
for key in mandatory: for key in mandatory:
env = environ.get(f'FRAPPY_{key.upper()}') env = environ.get(f'FRAPPY_{key.upper()}') or cfg.get(key)
if env is not None: if env is None:
if ':' in env: if self.defaults.get(key) is None:
cfg[key] = [Path(v) for v in env.split(':')] missing_keys.append(key)
else: else:
cfg[key] = Path(env) if not isinstance(env, Path):
missing_keys = [ env = [Path(v) for v in env.split(':')]
key for key in mandatory cfg[key] = env
if cfg.get(key) is None and self.defaults.get(key) is None
]
if missing_keys: if missing_keys:
if configfile: if configfile:
raise KeyError(f"missing value for {' and '.join(missing_keys)} in {configfile}") raise KeyError(f"missing value for {' and '.join(missing_keys)} in {configfile}")