use servicemanager.FrappyManager.do_listcfg for frappy_list()

This commit is contained in:
2023-06-06 16:21:14 +02:00
parent dd113a2da0
commit 0ca4dae4f5

View File

@ -22,7 +22,6 @@
import sys import sys
from os.path import expanduser, basename, join from os.path import expanduser, basename, join
from glob import glob
from configparser import ConfigParser from configparser import ConfigParser
from nicos import session, config from nicos import session, config
@ -31,8 +30,7 @@ from nicos.utils import printTable
from nicos.commands import helparglist, usercommand from nicos.commands import helparglist, usercommand
from nicos.commands.basic import AddSetup, CreateAllDevices, CreateDevice from nicos.commands.basic import AddSetup, CreateAllDevices, CreateDevice
from nicos.devices.secop.devices import get_attaching_devices from nicos.devices.secop.devices import get_attaching_devices
from nicos_sinq.frappy_sinq.devices import applyAliasConfig from nicos_sinq.frappy_sinq.devices import applyAliasConfig, FrappyNode
from servicemanager import FrappyManager
home = expanduser('~') home = expanduser('~')
@ -41,7 +39,6 @@ if home not in sys.path:
# for newer Frappy installations this should be home (= /home/<instrument>) # for newer Frappy installations this should be home (= /home/<instrument>)
# the following line fixes this in case nicos.conf is not yet updated # the following line fixes this in case nicos.conf is not yet updated
sys.path.append(home) sys.path.append(home)
from nicos_sinq.frappy_sinq.devices import FrappyNode
from servicemanager import FrappyManager from servicemanager import FrappyManager
@ -222,36 +219,22 @@ def frappy_addons(cfg=None):
@helparglist('') @helparglist('')
def frappy_list(service=None): def frappy_list(service=None):
"""list available configuration files""" """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'))) bases = list(dict.fromkeys(expanduser(p) for p in FrappyNode.config_dirs(config.instrument, service or 'main')))
if service is None: if service is None:
session.log.info('Available configuration files') prt('Available configuration files')
session.log.info(' ') prt('')
session.log.info('Hint: if no config file can be found which matches your needs exactly') prt('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') prt('make a copy of an existing one, and change the description accordingly')
session.log.info(' ') prt('')
session.log.info('Usage (default argument "main"):') prt('Usage (default argument "main"):')
session.log.info(' ') prt('')
printTable(['command'], [['frappy_list(%r)' % s] for s in SERVICES], session.log.info) printTable(['command'], [['frappy_list(%r)' % s] for s in SERVICES], prt)
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)
FrappyManager().do_listcfg(config.instrument, service or 'main', prt)
session.log.info('\n%s', '\n'.join(content))