[WIP] consider SEA config in frappy(..) command

This commit is contained in:
2023-09-11 08:24:29 +02:00
parent 59eaa39cd4
commit 9d6baa191e
2 changed files with 42 additions and 14 deletions

View File

@ -39,7 +39,7 @@ 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 servicemanager import FrappyManager from servicemanager import FrappyManager, SeaManager
def cleanup_defunct(): def cleanup_defunct():
@ -86,7 +86,7 @@ def frappy_start(**services):
frappy_config = session.devices.get('frappy_config') frappy_config = session.devices.get('frappy_config')
for service in SERVICES: for service in SERVICES:
if services.get(service) == '': if services.get(service) == '':
seaconn = session.devices.get('seaconn') seaconn = session.devices.get(f'se_sea_{service}')
if seaconn and seaconn._attached_secnode: if seaconn and seaconn._attached_secnode:
seaconn.communicate('frappy_remove %s' % service) seaconn.communicate('frappy_remove %s' % service)
used_cfg = {} used_cfg = {}
@ -96,12 +96,7 @@ def frappy_start(**services):
for service in reversed(SERVICES): for service in reversed(SERVICES):
secnode = session.devices.get('se_' + service) secnode = session.devices.get('se_' + service)
cfginfo = services.get(service) cfginfo = services.get(service)
if cfginfo is None: if cfginfo is not None:
if not secnode:
continue
cfginfo = secnode() or ''
secnode.restart(secnode.read(), False) # restart when needed only
else:
if cfginfo: if cfginfo:
new_cfg.append((service, secnode, cfginfo)) new_cfg.append((service, secnode, cfginfo))
else: else:
@ -157,6 +152,7 @@ def frappy(*args, main=None, stick=None, addons=None):
- addons are not changed when not given - addons are not changed when not given
- frappy(main='<cfg>') # main cfg is changed, but stick is kept - frappy(main='<cfg>') # main cfg is changed, but stick is kept
""" """
seacfg = SeaManager().guess_frappy_cfg(config.instrument)
if args: if args:
if main is not None: if main is not None:
raise TypeError('got multiple values for main') raise TypeError('got multiple values for main')
@ -166,10 +162,13 @@ def frappy(*args, main=None, stick=None, addons=None):
if main == '': if main == '':
stick = '' # remove stick with main stick = '' # remove stick with main
else: else:
stickcfg = main + 'stick' allsticks = FrappyManager().all_cfg(config.instruments, 'stick')
if stickcfg in FrappyNode.available_cfg('stick'): if seacfg.get('main') != main:
# if a default stick is available, start this also # main sea device has changed
stick = stickcfg stickcfg = main + 'stick'
if stickcfg in allsticks:
# if a default stick is available, start this also
stick = stickcfg
else: else:
if stick is not None: if stick is not None:
raise TypeError('got multiple values for stick') raise TypeError('got multiple values for stick')
@ -178,8 +177,30 @@ def frappy(*args, main=None, stick=None, addons=None):
if addons is not None: if addons is not None:
raise TypeError('got multiple values for addons') raise TypeError('got multiple values for addons')
addons = ','.join(alist) addons = ','.join(alist)
all_cfg = frappy_start(main=main, stick=stick, addons=addons) allcfg = frappy_start(main=main, stick=stick, addons=addons)
session.log.info(all_info(all_cfg)) session.log.info(all_info(allcfg))
else:
allcfg = frappy_start(main=main, stick=stick, addons=addons)
session.log.info(all_info(allcfg))
guess1 = {}
guess2 = {}
for s in SERVICES:
info = allcfg.get(s, '')
prev = info.split()[0]
if prev != info:
guess1[s] = prev
guess2[s] = prev
fromsea = seacfg.get(s)
if fromsea and fromsea != prev:
guess2[s] = fromsea
if guess1 and guess2:
session.log.info('please consider to call one of:')
elif guess1 or guess2:
session.log.info('please consider to call:')
if guess1:
session.log.info(all_info(guess1))
if guess2:
session.log.info(all_info(guess2))
@usercommand @usercommand
@ -224,6 +245,7 @@ def frappy_list(service=None):
def prt(line): def prt(line):
content.append(line) content.append(line)
# TODO: remove next 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:
prt('Available configuration files') prt('Available configuration files')

View File

@ -247,6 +247,10 @@ class FrappyNode(SecNodeDevice, Moveable):
super().doInit(mode) super().doInit(mode)
def doRead(self, maxage=0): def doRead(self, maxage=0):
try:
return self.secnode.descriptive_data['_frappy_config']
except (KeyError, AttributeError):
pass
if self._cfgvalue is None and self._cache: if self._cfgvalue is None and self._cache:
self._cfgvalue = self._cache.get(self, 'value') self._cfgvalue = self._cache.get(self, 'value')
return self._cfgvalue return self._cfgvalue
@ -264,12 +268,14 @@ class FrappyNode(SecNodeDevice, Moveable):
@classmethod @classmethod
def config_dirs(cls, ins, service): def config_dirs(cls, ins, service):
# TODO: no more needed after allowing ~cfg in FrappyManager.do_start
sm = cls._service_manager sm = cls._service_manager
sm.get_info() sm.get_info()
return sm.config_dirs(ins, service) return sm.config_dirs(ins, service)
@classmethod @classmethod
def available_cfg(cls, service): def available_cfg(cls, service):
# TODO: no more needed after allowing ~cfg in FrappyManager.do_start
ins = config.instrument ins = config.instrument
available_cfg = set() available_cfg = set()
for d in cls.config_dirs(ins, service): for d in cls.config_dirs(ins, service):