server: better handling of cfgfile argument

No reason to keep stringly-typed data on that level

Change-Id: Iba8d88301bf36ef6051031d1916d1bac84ede546
Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/34893
Reviewed-by: Georg Brandl <g.brandl@fz-juelich.de>
Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de>
Reviewed-by: Alexander Zaft <a.zaft@fz-juelich.de>
Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de>
This commit is contained in:
Georg Brandl 2024-10-29 14:03:19 +01:00 committed by Markus Zolliker
parent 8e05090795
commit aee99df2d0
7 changed files with 20 additions and 16 deletions

View File

@ -68,9 +68,9 @@ def parseArgv(argv):
action='store',
help="comma separated list of cfg files,\n"
"defaults to <name_of_the_instance>.\n"
"cfgfiles given without '.cfg' extension are searched"
" in the configuration directory,"
" else they are treated as path names",
"If a config file contains a slash, it is treated as a"
"path, otherwise the file is searched for in the "
"configuration directory.",
default=None)
parser.add_argument('-g',
'--gencfg',
@ -104,7 +104,9 @@ def main(argv=None):
generalConfig.init(args.gencfg)
logger.init(loglevel)
srv = Server(args.name, logger.log, cfgfiles=args.cfgfiles,
cfgfiles = [s.strip() for s in args.cfgfiles.split(',')]
srv = Server(args.name, logger.log, cfgfiles=cfgfiles,
interface=args.port, testonly=args.test)
if args.daemonize:

View File

@ -172,8 +172,8 @@ def load_config(cfgfiles, log):
Only the node-section of the first config file will be returned.
The others will be discarded.
Arguments
- cfgfiles : str
Comma separated list of config-files
- cfgfiles : list
List of config file paths
- log : frappy.logging.Mainlogger
Logger aquired from frappy.logging
Returns
@ -181,8 +181,8 @@ def load_config(cfgfiles, log):
merged configuration
"""
config = None
for cfgfile in cfgfiles.split(','):
filename = to_config_path(cfgfile, log)
for cfgfile in cfgfiles:
filename = to_config_path(str(cfgfile), log)
log.debug('Parsing config file %s...', filename)
cfg = process_file(filename, log)
if config:

View File

@ -218,8 +218,9 @@ def write_config(file_name, tree_widget):
with open(file_name, 'w', encoding='utf-8') as configfile:
configfile.write('\n'.join(lines))
def read_config(file_path, log):
config = load_config(file_path, log)
config = load_config([file_path], log)
node = TreeWidgetItem(NODE)
ifs = TreeWidgetItem(name='Interfaces')
mods = TreeWidgetItem(name='Modules')

View File

@ -108,6 +108,7 @@ class Playground(Server):
if cfgfiles:
if not generalConfig.initialized:
generalConfig.init()
cfgfiles = [s.strip() for s in cfgfiles.split(',')]
merged_cfg = load_config(cfgfiles, self.log)
merged_cfg.pop('node', None)
self.module_cfg = merged_cfg

View File

@ -69,9 +69,9 @@ class Server:
- name: the node name
- parent_logger: the logger to inherit from. a handler is installed by
the server to provide remote logging
- cfgfiles: if not given, defaults to name
may be a comma separated list of cfg files
items ending with .cfg are taken as paths, else .cfg is appended and
- cfgfiles: if not given, defaults to [name]
may be a list of cfg files
items ending with .py are taken as paths, else _cfg.py is appended and
files are looked up in the config path retrieved from the general config
- interface: an uri of the from tcp://<port> or a bare port number for tcp
if not given, the interface is taken from the config file. In case of
@ -95,7 +95,7 @@ class Server:
self._testonly = testonly
if not cfgfiles:
cfgfiles = name
cfgfiles = [name]
# sanitize name (in case it is a cfgfile)
name = os.path.splitext(os.path.basename(name))[0]
if isinstance(parent_logger, mlzlog.MLZLogger):

View File

@ -137,5 +137,5 @@ def test_process_file(direc, log):
def test_full(direc, log):
ret = load_config('pyfile_cfg.py', log)
ret = load_config(['pyfile_cfg.py'], log)
do_asserts(ret)

View File

@ -57,13 +57,13 @@ def test_name_only(direc, log):
def test_file(direc, log):
"""only see that this does not throw. get config from cfgfiles."""
s = Server('foo', log, cfgfiles='pyfile_cfg.py')
s = Server('foo', log, cfgfiles=['pyfile_cfg.py'])
s._processCfg()
def test_basic_description(direc, log):
"""only see that this does not throw. get config from cfgfiles."""
s = Server('foo', log, cfgfiles='pyfile_cfg.py')
s = Server('foo', log, cfgfiles=['pyfile_cfg.py'])
s._processCfg()
desc = s.secnode.get_descriptive_data('')
# secnode properties correctly exported