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

View File

@ -247,6 +247,10 @@ class FrappyNode(SecNodeDevice, Moveable):
super().doInit(mode)
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:
self._cfgvalue = self._cache.get(self, 'value')
return self._cfgvalue
@ -264,12 +268,14 @@ class FrappyNode(SecNodeDevice, Moveable):
@classmethod
def config_dirs(cls, ins, service):
# TODO: no more needed after allowing ~cfg in FrappyManager.do_start
sm = cls._service_manager
sm.get_info()
return sm.config_dirs(ins, service)
@classmethod
def available_cfg(cls, service):
# TODO: no more needed after allowing ~cfg in FrappyManager.do_start
ins = config.instrument
available_cfg = set()
for d in cls.config_dirs(ins, service):