From 880d472a4ab647e9ffbd9ac31a6c84a2b9553eff Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Thu, 24 Oct 2024 13:58:38 +0200 Subject: [PATCH] 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 Reviewed-by: Enrico Faulhaber Reviewed-by: Markus Zolliker --- frappy/lib/__init__.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/frappy/lib/__init__.py b/frappy/lib/__init__.py index 8aa2e90..96b9eae 100644 --- a/frappy/lib/__init__.py +++ b/frappy/lib/__init__.py @@ -37,10 +37,6 @@ from pathlib import Path SECoP_DEFAULT_PORT = 10767 -_gcfg_help = """ -""" - - class GeneralConfig: """generalConfig holds server configuration items @@ -94,17 +90,16 @@ class GeneralConfig: if cfg.get('confdir') is None: cfg['confdir'] = configfile.parent # environment variables will overwrite the config file + missing_keys = [] for key in mandatory: - env = environ.get(f'FRAPPY_{key.upper()}') - if env is not None: - if ':' in env: - cfg[key] = [Path(v) for v in env.split(':')] - else: - cfg[key] = Path(env) - missing_keys = [ - key for key in mandatory - if cfg.get(key) is None and self.defaults.get(key) is None - ] + env = environ.get(f'FRAPPY_{key.upper()}') or cfg.get(key) + if env is None: + if self.defaults.get(key) is None: + missing_keys.append(key) + else: + if not isinstance(env, Path): + env = [Path(v) for v in env.split(':')] + cfg[key] = env if missing_keys: if configfile: raise KeyError(f"missing value for {' and '.join(missing_keys)} in {configfile}")