From 1838902c99b3f0c9835fed90aa6b7bc2a5e85cd9 Mon Sep 17 00:00:00 2001 From: pc16470 Date: Wed, 20 May 2026 10:42:32 +0200 Subject: [PATCH] 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 --- base.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/base.py b/base.py index 99de9b7..d343927 100644 --- a/base.py +++ b/base.py @@ -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) 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 []') 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']