avoid KeyError when frappy is used with an invalid instrument

This commit is contained in:
2025-05-02 11:54:00 +02:00
parent dbd7a0433a
commit 09d7d016e1
2 changed files with 7 additions and 4 deletions

View File

@ -155,9 +155,9 @@ class ServiceManager:
if cmd.startswith('PY '): if cmd.startswith('PY '):
cmd = env.get('PY', 'python3') + cmd[2:] cmd = env.get('PY', 'python3') + cmd[2:]
self.commands[ins] = cmd self.commands[ins] = cmd
self.info = result
if len(self.info) == 1: if len(self.info) == 1:
self.single_ins = list(self.info)[0] self.single_ins = list(self.info)[0]
self.info = result
#def get_cmdpats(self, groups): #def get_cmdpats(self, groups):
# return self.cmdpats # return self.cmdpats

View File

@ -114,16 +114,19 @@ class FrappyManager(ServiceManager):
cfgpaths = [] cfgpaths = []
cfgparser = ConfigParser() cfgparser = ConfigParser()
cfgparser.optionxform = str cfgparser.optionxform = str
cfgfile = self.env[ins].get('FRAPPY_CONFIG_FILE') env = self.env.get(ins, {})
confdir = self.env[ins].get('FRAPPY_CONFDIR') cfgfile = env.get('FRAPPY_CONFIG_FILE')
confdir = env.get('FRAPPY_CONFDIR')
if cfgfile: if cfgfile:
cfgfile = self.env[ins]['FRAPPY_CONFIG_FILE'].replace('<SERV>', service) cfgfile = cfgfile.replace('<SERV>', service)
cfgparser.read(cfgfile) cfgparser.read(cfgfile)
try: try:
section = cfgparser['FRAPPY'] section = cfgparser['FRAPPY']
except KeyError: except KeyError:
raise ValueError('%s does not exist or has no FRAPPY section' % cfgfile) raise ValueError('%s does not exist or has no FRAPPY section' % cfgfile)
confdir = section.get('confdir', confdir) confdir = section.get('confdir', confdir)
if not confdir:
return []
for cfgpath in confdir.split(os.pathsep): for cfgpath in confdir.split(os.pathsep):
if cfgpath.endswith('<SERV>'): if cfgpath.endswith('<SERV>'):
cfgpaths.append(expanduser(cfgpath[:-6] + service)) cfgpaths.append(expanduser(cfgpath[:-6] + service))