better error message when cfg file does not exist

This commit is contained in:
zolliker 2022-06-08 16:34:28 +02:00
parent 5640c4ea08
commit ac9e35123c

View File

@ -23,7 +23,7 @@
import sys
import os
from glob import glob
from os.path import join, isdir, basename, expanduser
from os.path import join, isdir, basename, expanduser, exists
from configparser import ConfigParser
from servicemanager.base import ServiceManager, ServiceDown, UsageError
@ -51,7 +51,13 @@ class FrappyManager(ServiceManager):
cfgparser.optionxform = str
cfgfile = self.env[ins]['FRAPPY_CONFIG_FILE'].replace('<SERV>', service)
cfgparser.read(cfgfile)
for cfgpath in cfgparser['FRAPPY']['confdir'].split(os.pathsep):
try:
section = cfgparser['FRAPPY']
except KeyError:
if exists(cfgfile):
raise KeyError('%s has no FRAPPY section' % cfgfile)
raise FileNotFoundError('%s does not exist' % cfgfile)
for cfgpath in section['confdir'].split(os.pathsep):
if cfgpath.endswith('<SERV>'):
cfgpaths.append(cfgpath[:-6] + service)
else: