From 3b92688b8495ba1671877976c6ba769adcbd8264 Mon Sep 17 00:00:00 2001 From: Alexander Zaft Date: Thu, 25 May 2023 10:57:44 +0200 Subject: [PATCH] Warn about duplicate module definitions in a file check for each file, if every module definition occurs only once Change-Id: I4f37f67c07d68068cbced718908927a594defc88 Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/31194 Tested-by: Jenkins Automated Tests Reviewed-by: Enrico Faulhaber Reviewed-by: Markus Zolliker Reviewed-by: Alexander Zaft --- frappy/config.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/frappy/config.py b/frappy/config.py index c19cc6a1..1b77f154 100644 --- a/frappy/config.py +++ b/frappy/config.py @@ -22,10 +22,12 @@ import os import re +from collections import Counter from frappy.errors import ConfigError from frappy.lib import generalConfig + class Undef: pass @@ -126,7 +128,7 @@ class Config(dict): self.modules.append(mod) -def process_file(filename): +def process_file(filename, log): with open(filename, 'rb') as f: config_text = f.read() node = NodeCollector() @@ -135,6 +137,13 @@ def process_file(filename): # pylint: disable=exec-used exec(compile(config_text, filename, 'exec'), ns) + + # check for duplicates in the file itself. Between files comes later + duplicates = [name for name, count in Counter([mod['name'] + for mod in mods.list]).items() if count > 1] + if duplicates: + log.warning('Duplicate module name in file \'%s\': %s', + filename, ','.join(duplicates)) return Config(node, mods) @@ -177,7 +186,7 @@ def load_config(cfgfiles, log): for cfgfile in cfgfiles.split(','): filename = to_config_path(cfgfile, log) log.debug('Parsing config file %s...', filename) - cfg = process_file(filename) + cfg = process_file(filename, log) if config: config.merge_modules(cfg) else: