frappy() indicates also if frappy server is not running

+ improvements in the envlist creation
This commit is contained in:
2022-08-25 14:15:39 +02:00
parent cbbec5647c
commit 7b076458bc
2 changed files with 27 additions and 21 deletions

View File

@ -26,6 +26,7 @@ from glob import glob
from configparser import ConfigParser
from nicos import session, config
from nicos.core import status
from nicos.utils import printTable
from nicos.commands import helparglist, usercommand
from nicos.commands.basic import AddSetup, CreateAllDevices, CreateDevice
@ -98,17 +99,16 @@ def frappy_start(**services):
cfginfo = services.get(service)
if cfginfo is None:
if not secnode:
continue
continue
cfginfo = secnode() or ''
all_cfg[service] = cfginfo
else:
if cfginfo:
new_cfg.append((service, secnode, cfginfo))
else:
remove_cfg.append(secnode)
all_cfg[service] = cfginfo
if secnode:
secnode('')
all_cfg[service] = secnode.get_info()
# check cfg is not used twice
for cfg in cfginfo.split(','):
@ -126,6 +126,7 @@ def frappy_start(**services):
AddSetup('frappy_' + service)
secnode = session.devices[nodename]
secnode(cfginfo)
all_cfg[service] = secnode.get_info()
CreateDevice(nodename)
cleanup_defunct()
CreateAllDevices()

View File

@ -133,13 +133,8 @@ class FrappyConfig(Device):
meaning_name, importance = meaning
sample_devices.setdefault(meaning_name, []).append((importance, devname))
envlist = list(session.experiment.envlist)
prev_env_alias = {} # dict [devname] of aliasname of previous aliases in envlist
for devname in envlist:
dev = session.device.get(devname)
if isinstance(dev, DeviceAlias):
prev_env_alias[devname] = dev.alias
newenv = {}
newenv = {} # to be added to envlist (dict [devname] of aliasname)
to_remove = set() # items to be removed from previous envlist, if present
for meaning in self.meanings:
info = getattr(self, meaning)
aliasnames = info.get('alias')
@ -162,26 +157,23 @@ class FrappyConfig(Device):
session.dynamic_devices[aliasname] = 'frappy' # assign to frappy setup
aliasdev = previous_aliases.pop(aliasname, None)
if aliasdev:
session.log.debug('change alias %r -> %r', aliasname, devname)
if aliasdev.alias != devname:
session.log.debug('change alias %r -> %r', aliasname, devname)
else:
session.log.debug('create alias %r -> %r', aliasname, devname)
aliasdev = session.createDevice(aliasname, recreate=True, explicit=True)
aliasdev.alias = devname
# only the first item of aliasnames is added to the envlist
aliasname = aliasnames[0]
if devname in envlist:
envlist.remove(devname)
else:
prev_alias = prev_env_alias[devname]
if prev_alias in envlist:
envlist.remove(prev_alias)
to_remove.add(devname)
to_remove.add(aliasname)
if devname not in newenv and info.get('envlist', True):
# example: when 'temperature' and 'temperature_regulation' are the
# same device, the first one is kept
newenv[devname] = aliasname
break
else:
envlist = [k for k in envlist if k not in aliasnames]
to_remove.union(aliasnames)
for aliasname in previous_aliases:
session.destroyDevice(aliasname)
@ -190,10 +182,14 @@ class FrappyConfig(Device):
applyAliasConfig() # for other aliases
envlist.extend(newenv.values())
if set(envlist) != set(session.experiment.envlist):
envlist = [k for k in session.experiment.envlist if k not in to_remove] + list(newenv.values())
if envlist != session.experiment.envlist:
removed = set(session.experiment.envlist).difference(envlist)
session.experiment.setEnvironment(envlist)
session.log.info('changed environment to: %s', ', '.join(session.experiment.envlist))
if removed:
session.log.info('removed %s from environment', ', '.join(removed))
if newenv:
session.log.info('added %s to environment', ', '.join(newenv.values()))
class FrappyNode(SecNodeDevice, Moveable):
@ -313,3 +309,12 @@ class FrappyNode(SecNodeDevice, Moveable):
if self._cache:
self._cache.put(self, 'value', cfg)
self._setROParam('target', cfg)
def get_info(self):
result = self.doRead() or ''
code, text = self.status()
if code == status.OK:
return result
if (code, text) == (status.ERROR, 'reconnecting'):
return '%s (frappy not running)' % result
return '%s (%s)' % (result, text)