From 09d7d016e13be57306c696eb352089bbee58f14b Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Fri, 2 May 2025 11:54:00 +0200 Subject: [PATCH] avoid KeyError when frappy is used with an invalid instrument --- base.py | 2 +- frappyman.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/base.py b/base.py index dd76ed6..2730503 100644 --- a/base.py +++ b/base.py @@ -155,9 +155,9 @@ class ServiceManager: if cmd.startswith('PY '): 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] - self.info = result #def get_cmdpats(self, groups): # return self.cmdpats diff --git a/frappyman.py b/frappyman.py index 44f2e8a..0ea4be6 100644 --- a/frappyman.py +++ b/frappyman.py @@ -114,16 +114,19 @@ class FrappyManager(ServiceManager): cfgpaths = [] cfgparser = ConfigParser() cfgparser.optionxform = str - cfgfile = self.env[ins].get('FRAPPY_CONFIG_FILE') - confdir = self.env[ins].get('FRAPPY_CONFDIR') + env = self.env.get(ins, {}) + cfgfile = env.get('FRAPPY_CONFIG_FILE') + confdir = env.get('FRAPPY_CONFDIR') if cfgfile: - cfgfile = self.env[ins]['FRAPPY_CONFIG_FILE'].replace('', service) + cfgfile = cfgfile.replace('', service) cfgparser.read(cfgfile) try: section = cfgparser['FRAPPY'] except KeyError: raise ValueError('%s does not exist or has no FRAPPY section' % cfgfile) confdir = section.get('confdir', confdir) + if not confdir: + return [] for cfgpath in confdir.split(os.pathsep): if cfgpath.endswith(''): cfgpaths.append(expanduser(cfgpath[:-6] + service))