improve traceback while processing config file

the filename of the executed config file has to
be known to 'exec' for a meaningfull traceback

Change-Id: I3403740dc9198ce5f64741fbb112cb908159c704
Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/31055
Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de>
Reviewed-by: Alexander Zaft <a.zaft@fz-juelich.de>
Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
This commit is contained in:
2023-05-09 07:47:05 +02:00
parent 259970249a
commit dfe0038494

View File

@ -126,13 +126,15 @@ class Config(dict):
self.modules.append(mod)
def process_file(config_text):
def process_file(filename):
with open(filename, 'rb') as f:
config_text = f.read()
node = NodeCollector()
mods = Collector(Mod)
ns = {'Node': node.add, 'Mod': mods.add, 'Param': Param, 'Command': Param, 'Group': Group}
# pylint: disable=exec-used
exec(config_text, ns)
exec(compile(config_text, filename, 'exec'), ns)
return Config(node, mods)
@ -175,9 +177,7 @@ def load_config(cfgfiles, log):
for cfgfile in cfgfiles.split(','):
filename = to_config_path(cfgfile, log)
log.debug('Parsing config file %s...', filename)
with open(filename, 'rb') as f:
config_text = f.read()
cfg = process_file(config_text)
cfg = process_file(filename)
if config:
config.merge_modules(cfg)
else: