fix behaviour on machines with 1 single instrument

- complain when instrument name is MAIN in servicemanager.cfg
- set self.main_ins also on single instrument machines
This commit is contained in:
2026-05-20 10:42:32 +02:00
parent 1980971ec9
commit 1838902c99
+11 -10
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# *****************************************************************************
#
# This program is free software; you can redistribute it and/or modify it under
@@ -140,13 +139,17 @@ class ServiceManager:
value = value.replace('<INS>', ins)
return ':'.join(expanduser(p % dict(ins=ins)) for p in value.split(':'))
this_ins = os.environ.get('Instrument') or basename(expanduser('~'))
for ins in parser.sections():
hostname = socket.gethostname().split('.')[0]
self.is_remote = hostname != section.get('host', hostname)
all_ins = [k for k in parser.sections() if parser.has_option(k, self.group)]
if len(all_ins) == 1:
self.main_ins = self.single_ins = all_ins[0]
else:
self.main_ins = os.environ.get('Instrument') or hostname
for ins in all_ins:
if ins == 'MAIN':
raise ValueError('error in ~/servicemanager.cfg: replace [MAIN] by [<instrument name>]')
section = dict(parser[ins])
if ins == this_ins:
self.main_ins = this_ins
hostname = socket.gethostname().split('.')[0]
self.is_remote = hostname != section.get('host', hostname)
command = section.get('%s_command' % self.group)
self.revcmd[command] = self.group
nr = section.get(self.group)
@@ -161,8 +164,6 @@ class ServiceManager:
cmd = env.get('PY', 'python3') + cmd[2:]
self.commands[ins] = cmd
self.info = result
if len(self.info) == 1:
self.single_ins = list(self.info)[0]
return result
#def get_cmdpats(self, groups):
@@ -219,7 +220,7 @@ class ServiceManager:
match = cmdpat.match(cmd)
if match:
gdict = match.groupdict()
ins = gdict.get('ins', self.main_ins) or self.single_ins
ins = gdict.get('ins', self.main_ins)
serv = gdict.get('serv', '')
if cfginfo is not None and 'cfg' in gdict:
cfginfo[ins, serv] = gdict['cfg']