Increase discoverability by telling user both the filename and the directories searched if config file is missing

This commit is contained in:
2024-07-06 16:47:03 +02:00
parent 6f36d49215
commit ebbf066707
3 changed files with 9 additions and 6 deletions

View File

@ -324,6 +324,7 @@ def main():
logging.debug('Starting as PID %s', os.getpid())
found = False
config_dirs = ('/etc/routerstats/', '/usr/local/etc/routerstats/', '/opt/routerstats/', './')
if args.config:
if os.path.isfile(args.config):
config.read(args.config)
@ -333,14 +334,14 @@ def main():
else:
logging.debug('Trying to find config')
#Try to find in "usual" places
for directory in ('/etc/routerstats/', '/usr/local/etc/routerstats/', '/opt/routerstats/', './'):
for directory in config_dirs:
trytoread = directory + 'routerstats.config'
if os.path.isfile(trytoread):
logging.debug('Reading config file %s', trytoread)
config.read(trytoread)
found = True
if not found:
logging.error('No config file found')
logging.error('routerstats.config not found in %s', config_dirs)
sys.exit(0)
parser.add_argument(

View File

@ -450,6 +450,7 @@ def main():
logging.debug('Starting as PID %s' ,os.getpid())
found = False
config_dirs = ('/etc/routerstats/', '/usr/local/etc/routerstats/', '/opt/routerstats/', './')
if args.config:
if os.path.isfile(args.config):
config.read(args.config)
@ -459,14 +460,14 @@ def main():
else:
logging.debug('Trying to find config')
#Try to find in "usual" places
for directory in ('/etc/routerstats/', '/usr/local/etc/routerstats/', '/opt/routerstats/', './'):
for directory in config_dirs:
trytoread = directory + 'routerstats.config'
if os.path.isfile(trytoread):
logging.debug('Reading config file %s', trytoread)
config.read(trytoread)
found = True
if not found:
logging.error('No config file found')
logging.error('routerstats.config not found in %s', config_dirs)
sys.exit(0)
parser.add_argument(

View File

@ -136,6 +136,7 @@ def main():
logging.debug('Starting as PID %s', os.getpid())
found = False
config_dirs = ('/etc/routerstats/', '/usr/local/etc/routerstats/', '/opt/routerstats/', './')
if args.config:
if os.path.isfile(args.config):
config.read(args.config)
@ -145,14 +146,14 @@ def main():
else:
logging.debug('Trying to find config')
#Try to find in "usual" places
for directory in ('/etc/routerstats/', '/usr/local/etc/routerstats/', '/opt/routerstats/', './'):
for directory in config_dirs:
trytoread = directory + 'routerstats.config'
if os.path.isfile(trytoread):
logging.debug('Reading config file %s', trytoread)
config.read(trytoread)
found = True
if not found:
logging.error('No config file found')
logging.error('routerstats.config not found in %s', config_dirs)
sys.exit(0)
parser.add_argument(