fix a3 alias assignment
rotation_z and stick_rotation need seperate entries in frappy_config
This commit is contained in:
44
devices.py
44
devices.py
@ -78,9 +78,14 @@ class FrappyConfig(Device):
|
||||
'magneticfield': Param(
|
||||
'config for magnetic field', type=anytype, default={}),
|
||||
'rotation_z': Param(
|
||||
'config for sample rotation', type=anytype, default={}),
|
||||
'config for sample rotation (to be used as a3)',
|
||||
type=anytype, default={}),
|
||||
'stick_rotation': Param(
|
||||
'config for stick rotation (not necessarily to be used as a3)',
|
||||
type=anytype, default={}),
|
||||
'nodes': Param(
|
||||
'list of names of potential SEC nodes', type=listof(str), default=[]),
|
||||
'list of names of potential SEC nodes',
|
||||
type=listof(str), default=[]),
|
||||
}
|
||||
|
||||
meanings = list(parameters)
|
||||
@ -89,7 +94,7 @@ class FrappyConfig(Device):
|
||||
def remove_aliases(self):
|
||||
for meaning in self.meanings:
|
||||
info = getattr(self, meaning)
|
||||
aliasnames = info['alias']
|
||||
aliasnames = info.get('alias', [])
|
||||
if isinstance(aliasnames, str):
|
||||
aliasnames = [aliasnames]
|
||||
for aliasname in aliasnames:
|
||||
@ -103,7 +108,7 @@ class FrappyConfig(Device):
|
||||
result = {}
|
||||
for meaning in self.meanings:
|
||||
info = getattr(self, meaning)
|
||||
aliasnames = info['alias']
|
||||
aliasnames = info.get('alias', [])
|
||||
if isinstance(aliasnames, str):
|
||||
aliasnames = [aliasnames]
|
||||
for aliasname in aliasnames:
|
||||
@ -139,19 +144,22 @@ class FrappyConfig(Device):
|
||||
info = getattr(self, meaning)
|
||||
aliasnames = info.get('alias')
|
||||
if aliasnames is None:
|
||||
continue
|
||||
if isinstance(aliasnames, str):
|
||||
aliasnames = []
|
||||
elif isinstance(aliasnames, str):
|
||||
aliasnames = [aliasnames]
|
||||
aliascfg = info.get('targets', {})
|
||||
unique = info.get('unique')
|
||||
if unique:
|
||||
aliases = [a for a in unique
|
||||
predefined_alias = info.get('predefined_alias')
|
||||
if predefined_alias:
|
||||
aliases = [a for a in predefined_alias
|
||||
if isinstance(session.devices.get(a), DeviceAlias)]
|
||||
if aliases:
|
||||
if len(aliases) > 1:
|
||||
raise TypeError(f'do know to which of {aliases} {meaning} to assign to')
|
||||
alias_config = session.alias_config.setdefault(aliases[0], [])
|
||||
alias_config.extend(list(aliascfg.items()))
|
||||
elif not aliasnames:
|
||||
session.log.warn("neither 'predefined_alias' nor 'alias' configured. skip %s", meaning)
|
||||
continue
|
||||
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)
|
||||
@ -172,14 +180,15 @@ class FrappyConfig(Device):
|
||||
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]
|
||||
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
|
||||
if aliasnames:
|
||||
# only the first item of aliasnames is added to the envlist
|
||||
aliasname = aliasnames[0]
|
||||
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:
|
||||
to_remove.union(aliasnames)
|
||||
@ -299,6 +308,7 @@ class FrappyNode(SecNodeDevice, Moveable):
|
||||
else:
|
||||
self.disable()
|
||||
if running_cfg:
|
||||
self._disconnect()
|
||||
self._service_manager.do_stop(ins, self.service)
|
||||
is_cfg = cfg and ':' not in cfg
|
||||
if is_cfg:
|
||||
|
Reference in New Issue
Block a user