From 0ca4dae4f5e4b0bbfc3120bb5f264c6e90851583 Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Tue, 6 Jun 2023 16:21:14 +0200 Subject: [PATCH] use servicemanager.FrappyManager.do_listcfg for frappy_list() --- commands.py | 49 ++++++++++++++++--------------------------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/commands.py b/commands.py index 47c1d06..7dc823d 100644 --- a/commands.py +++ b/commands.py @@ -22,7 +22,6 @@ import sys from os.path import expanduser, basename, join -from glob import glob from configparser import ConfigParser from nicos import session, config @@ -31,8 +30,7 @@ from nicos.utils import printTable from nicos.commands import helparglist, usercommand from nicos.commands.basic import AddSetup, CreateAllDevices, CreateDevice from nicos.devices.secop.devices import get_attaching_devices -from nicos_sinq.frappy_sinq.devices import applyAliasConfig -from servicemanager import FrappyManager +from nicos_sinq.frappy_sinq.devices import applyAliasConfig, FrappyNode home = expanduser('~') @@ -41,7 +39,6 @@ if home not in sys.path: # for newer Frappy installations this should be home (= /home/) # the following line fixes this in case nicos.conf is not yet updated sys.path.append(home) -from nicos_sinq.frappy_sinq.devices import FrappyNode from servicemanager import FrappyManager @@ -222,36 +219,22 @@ def frappy_addons(cfg=None): @helparglist('') def frappy_list(service=None): """list available configuration files""" - table = [] + content = [] + + def prt(line): + content.append(line) + bases = list(dict.fromkeys(expanduser(p) for p in FrappyNode.config_dirs(config.instrument, service or 'main'))) if service is None: - session.log.info('Available configuration files') - session.log.info(' ') - session.log.info('Hint: if no config file can be found which matches your needs exactly') - session.log.info('make a copy of an existing one, and change the description accordingly') - session.log.info(' ') - session.log.info('Usage (default argument "main"):') - session.log.info(' ') - printTable(['command'], [['frappy_list(%r)' % s] for s in SERVICES], session.log.info) - session.log.info(' ') - - def dummy(*args, **kwds): - pass - - class Node: - description = '' - - def __call__(id, desc, *args, **kwds): - self.description = desc - - namespace = {k: dummy for k in ('Mod', 'Param', 'Command', 'Group')} - node = Node() - namespace['Node'] = node - for cfgdir, name in bases: - table.append(['---\n', cfgdir]) - for cfgfile in glob(join(cfgdir, '*_cfg.py')): - exec(cfgfile, namespace) - table.append([basename(cfgfile)[:-7], node.description]) - printTable(['cfg file', 'description'], table, session.log.info) + prt('Available configuration files') + prt('') + prt('Hint: if no config file can be found which matches your needs exactly') + prt('make a copy of an existing one, and change the description accordingly') + prt('') + prt('Usage (default argument "main"):') + prt('') + printTable(['command'], [['frappy_list(%r)' % s] for s in SERVICES], prt) + FrappyManager().do_listcfg(config.instrument, service or 'main', prt) + session.log.info('\n%s', '\n'.join(content))