allow multiple names for SE aliases

This commit is contained in:
2022-05-02 15:56:19 +02:00
parent 70cf0b6715
commit b9370eb206
2 changed files with 24 additions and 16 deletions

View File

@ -97,7 +97,10 @@ class FrappyConfig(Device):
def remove_aliases(self): def remove_aliases(self):
for meaning in self.meanings: for meaning in self.meanings:
info = getattr(self, meaning) info = getattr(self, meaning)
aliasname = info['alias'] aliasnames = info['alias']
if isinstance(aliasname, str):
aliasnames = [aliasnames]
for aliasname in aliasnames:
aliasdev = session.devices.get(aliasname) aliasdev = session.devices.get(aliasname)
if aliasdev: if aliasdev:
session.destroyDevice(aliasname) session.destroyDevice(aliasname)
@ -129,7 +132,9 @@ class FrappyConfig(Device):
drivables = {} drivables = {}
for meaning in self.meanings: for meaning in self.meanings:
info = getattr(self, meaning) info = getattr(self, meaning)
aliasname = info['alias'] aliasnames = info['alias']
if isinstance(aliasnames, str):
aliasnames = [aliasnames]
envlistflag = info.get('envlist', True) envlistflag = info.get('envlist', True)
aliascfg = info.get('targets', {}) aliascfg = info.get('targets', {})
importance_list = sample_devices.get(meaning, []) importance_list = sample_devices.get(meaning, [])
@ -151,12 +156,14 @@ class FrappyConfig(Device):
# marked as xxx_drivable, but not really drivable: skip # marked as xxx_drivable, but not really drivable: skip
continue continue
if dev: if dev:
for aliasname in aliasnames:
session.log.debug('create alias %r pointing to %r', aliasname, devname) session.log.debug('create alias %r pointing to %r', aliasname, devname)
devcfg = ('nicos.core.DeviceAlias', {}) devcfg = ('nicos.core.DeviceAlias', {})
session.configured_devices[aliasname] = devcfg session.configured_devices[aliasname] = devcfg
session.dynamic_devices[aliasname] = 'frappy' session.dynamic_devices[aliasname] = 'frappy'
aliasdev = session.createDevice(aliasname, recreate=True, explicit=True) aliasdev = session.createDevice(aliasname, recreate=True, explicit=True)
aliasdev.alias = devname aliasdev.alias = devname
aliasname = aliasnames[0]
if devname not in devset and envlistflag: if devname not in devset and envlistflag:
# take only the first one # take only the first one
devset.add(devname) devset.add(devname)
@ -165,6 +172,7 @@ class FrappyConfig(Device):
newenv.pop(aliasname, None) newenv.pop(aliasname, None)
break break
else: else:
for aliasname in aliasnames:
newenv.pop(aliasname, None) newenv.pop(aliasname, None)
applyAliasConfig() # for other aliases applyAliasConfig() # for other aliases

View File

@ -20,7 +20,7 @@ devices = dict(
# device, using the given importance number, with similar values as # device, using the given importance number, with similar values as
# given by the SECoP standard (10: instrument, 20: cryostat, 30: insert) # given by the SECoP standard (10: instrument, 20: cryostat, 30: insert)
temperature = { # the SECoP meaning temperature = { # the SECoP meaning
'alias': 'Ts', # the name to be given to the alias 'alias': ['Ts', 'temperature'], # the name(s) to be given to the alias
'targets': # possible devices in addition with importance 'targets': # possible devices in addition with importance
{'se_ts': 20, 'se_tt': 19, 'se_tm': 18}, {'se_ts': 20, 'se_tt': 19, 'se_tm': 18},
}, },
@ -33,7 +33,7 @@ devices = dict(
'envlist': False, 'envlist': False,
}, },
magneticfield = { magneticfield = {
'alias': 'B', 'alias': ['B', 'magfield'],
'targets': {'se_mf': 20}, 'targets': {'se_mf': 20},
}, },
rotation_z = { rotation_z = {