reworked meanings / aliases
- add rotation_x to the list - allow to configure items creating an alias without entry in envlist
This commit is contained in:
51
commands.py
51
commands.py
@@ -26,7 +26,7 @@ from glob import glob
|
||||
from configparser import ConfigParser
|
||||
|
||||
from nicos import session, config
|
||||
from nicos.core import DeviceAlias
|
||||
from nicos.core import DeviceAlias, Moveable
|
||||
from nicos.utils import printTable
|
||||
from nicos.commands import helparglist, usercommand
|
||||
from nicos.commands.basic import AddSetup, CreateAllDevices, CreateDevice
|
||||
@@ -92,10 +92,8 @@ def remove_se_aliases():
|
||||
frappy_config = session.getDevice('frappy_config')
|
||||
configured = {}
|
||||
for meaning in frappy_config.meanings:
|
||||
try:
|
||||
aliasname, aliascfg = getattr(frappy_config, meaning)
|
||||
except TypeError:
|
||||
continue
|
||||
info = getattr(frappy_config, meaning)
|
||||
aliasname = info['alias']
|
||||
aliasdev = session.devices.get(aliasname)
|
||||
if aliasdev:
|
||||
session.destroyDevice(aliasname)
|
||||
@@ -123,21 +121,34 @@ def set_se_list():
|
||||
meaning = secnode.modules[secop_module]['properties'].get('meaning')
|
||||
if meaning:
|
||||
meaning_name, importance = meaning
|
||||
sample_devices.setdefault(meaning_name, []).append((importance * 10 + 5, devname))
|
||||
sample_devices.setdefault(meaning_name, []).append((importance, devname))
|
||||
|
||||
newlist = []
|
||||
previous = session.experiment.envlist[:]
|
||||
devset = set()
|
||||
newenv = {e: None for e in session.experiment.envlist} # use dict instead of set because of order
|
||||
drivables = {}
|
||||
for meaning in frappy_config.meanings:
|
||||
try:
|
||||
aliasname, aliascfg = getattr(frappy_config, meaning)
|
||||
except TypeError:
|
||||
continue
|
||||
info = getattr(frappy_config, meaning)
|
||||
aliasname = info['alias']
|
||||
envlistflag = info.get('envlist', True)
|
||||
aliascfg = info.get('targets', {})
|
||||
importance_list = sample_devices.get(meaning, [])
|
||||
importance_list.extend([(nr, nam) for nam, nr in aliascfg.items() if nam in session.devices])
|
||||
importance_list = sorted(importance_list, reverse=True)
|
||||
session.log.debug('%s: %r', meaning, importance_list)
|
||||
prefix, _, postfix = meaning.partition('_')
|
||||
if postfix == 'drivable':
|
||||
# append the previously collected drivables in the group to the importance_list
|
||||
group = drivables.get(prefix, {})
|
||||
for key in 'regulation', '':
|
||||
if key in group:
|
||||
importance_list.append((None, group[key]))
|
||||
for _, devname, in importance_list:
|
||||
dev = session.devices.get(devname)
|
||||
if isinstance(dev, Moveable):
|
||||
drivables.setdefault(prefix, {})[postfix] = devname
|
||||
elif postfix == 'drivable':
|
||||
# marked as xxx_drivable, but not really drivable: skip
|
||||
continue
|
||||
if dev:
|
||||
session.log.debug('create alias %r pointing to %r', aliasname, devname)
|
||||
devcfg = ('nicos.core.DeviceAlias', {})
|
||||
@@ -145,17 +156,19 @@ def set_se_list():
|
||||
session.dynamic_devices[aliasname] = 'frappy'
|
||||
aliasdev = session.createDevice(aliasname, recreate=True, explicit=True)
|
||||
aliasdev.alias = devname
|
||||
if aliasname not in previous:
|
||||
newlist.append(aliasname)
|
||||
if devname not in devset and envlistflag:
|
||||
# take only the first one
|
||||
devset.add(devname)
|
||||
newenv[aliasname] = None
|
||||
else:
|
||||
newenv.pop(aliasname, None)
|
||||
break
|
||||
else:
|
||||
if aliasname in previous:
|
||||
previous.remove(aliasname)
|
||||
newenv.pop(aliasname, None)
|
||||
|
||||
applyAliasConfig() # for other aliases
|
||||
newlist = previous + newlist
|
||||
if set(newlist) != set(session.experiment.envlist):
|
||||
session.experiment.setEnvironment(newlist)
|
||||
if set(newenv) != set(session.experiment.envlist):
|
||||
session.experiment.setEnvironment(list(newenv))
|
||||
session.log.info('changed environment to: %s', ', '.join(session.experiment.envlist))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user