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 <pedersen+jenkins@frm2.tum.de> Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de> Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch> Reviewed-by: Alexander Zaft <a.zaft@fz-juelich.de>
This commit is contained in:
@@ -22,10 +22,12 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
from collections import Counter
|
||||||
|
|
||||||
from frappy.errors import ConfigError
|
from frappy.errors import ConfigError
|
||||||
from frappy.lib import generalConfig
|
from frappy.lib import generalConfig
|
||||||
|
|
||||||
|
|
||||||
class Undef:
|
class Undef:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -126,7 +128,7 @@ class Config(dict):
|
|||||||
self.modules.append(mod)
|
self.modules.append(mod)
|
||||||
|
|
||||||
|
|
||||||
def process_file(filename):
|
def process_file(filename, log):
|
||||||
with open(filename, 'rb') as f:
|
with open(filename, 'rb') as f:
|
||||||
config_text = f.read()
|
config_text = f.read()
|
||||||
node = NodeCollector()
|
node = NodeCollector()
|
||||||
@@ -135,6 +137,13 @@ def process_file(filename):
|
|||||||
|
|
||||||
# pylint: disable=exec-used
|
# pylint: disable=exec-used
|
||||||
exec(compile(config_text, filename, 'exec'), ns)
|
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)
|
return Config(node, mods)
|
||||||
|
|
||||||
|
|
||||||
@@ -177,7 +186,7 @@ def load_config(cfgfiles, log):
|
|||||||
for cfgfile in cfgfiles.split(','):
|
for cfgfile in cfgfiles.split(','):
|
||||||
filename = to_config_path(cfgfile, log)
|
filename = to_config_path(cfgfile, log)
|
||||||
log.debug('Parsing config file %s...', filename)
|
log.debug('Parsing config file %s...', filename)
|
||||||
cfg = process_file(filename)
|
cfg = process_file(filename, log)
|
||||||
if config:
|
if config:
|
||||||
config.merge_modules(cfg)
|
config.merge_modules(cfg)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user