Increase discoverability by telling user both the filename and the directories searched if config file is missing
This commit is contained in:
@ -324,6 +324,7 @@ def main():
|
|||||||
logging.debug('Starting as PID %s', os.getpid())
|
logging.debug('Starting as PID %s', os.getpid())
|
||||||
|
|
||||||
found = False
|
found = False
|
||||||
|
config_dirs = ('/etc/routerstats/', '/usr/local/etc/routerstats/', '/opt/routerstats/', './')
|
||||||
if args.config:
|
if args.config:
|
||||||
if os.path.isfile(args.config):
|
if os.path.isfile(args.config):
|
||||||
config.read(args.config)
|
config.read(args.config)
|
||||||
@ -333,14 +334,14 @@ def main():
|
|||||||
else:
|
else:
|
||||||
logging.debug('Trying to find config')
|
logging.debug('Trying to find config')
|
||||||
#Try to find in "usual" places
|
#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'
|
trytoread = directory + 'routerstats.config'
|
||||||
if os.path.isfile(trytoread):
|
if os.path.isfile(trytoread):
|
||||||
logging.debug('Reading config file %s', trytoread)
|
logging.debug('Reading config file %s', trytoread)
|
||||||
config.read(trytoread)
|
config.read(trytoread)
|
||||||
found = True
|
found = True
|
||||||
if not found:
|
if not found:
|
||||||
logging.error('No config file found')
|
logging.error('routerstats.config not found in %s', config_dirs)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
|||||||
@ -450,6 +450,7 @@ def main():
|
|||||||
logging.debug('Starting as PID %s' ,os.getpid())
|
logging.debug('Starting as PID %s' ,os.getpid())
|
||||||
|
|
||||||
found = False
|
found = False
|
||||||
|
config_dirs = ('/etc/routerstats/', '/usr/local/etc/routerstats/', '/opt/routerstats/', './')
|
||||||
if args.config:
|
if args.config:
|
||||||
if os.path.isfile(args.config):
|
if os.path.isfile(args.config):
|
||||||
config.read(args.config)
|
config.read(args.config)
|
||||||
@ -459,14 +460,14 @@ def main():
|
|||||||
else:
|
else:
|
||||||
logging.debug('Trying to find config')
|
logging.debug('Trying to find config')
|
||||||
#Try to find in "usual" places
|
#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'
|
trytoread = directory + 'routerstats.config'
|
||||||
if os.path.isfile(trytoread):
|
if os.path.isfile(trytoread):
|
||||||
logging.debug('Reading config file %s', trytoread)
|
logging.debug('Reading config file %s', trytoread)
|
||||||
config.read(trytoread)
|
config.read(trytoread)
|
||||||
found = True
|
found = True
|
||||||
if not found:
|
if not found:
|
||||||
logging.error('No config file found')
|
logging.error('routerstats.config not found in %s', config_dirs)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
|||||||
@ -136,6 +136,7 @@ def main():
|
|||||||
logging.debug('Starting as PID %s', os.getpid())
|
logging.debug('Starting as PID %s', os.getpid())
|
||||||
|
|
||||||
found = False
|
found = False
|
||||||
|
config_dirs = ('/etc/routerstats/', '/usr/local/etc/routerstats/', '/opt/routerstats/', './')
|
||||||
if args.config:
|
if args.config:
|
||||||
if os.path.isfile(args.config):
|
if os.path.isfile(args.config):
|
||||||
config.read(args.config)
|
config.read(args.config)
|
||||||
@ -145,14 +146,14 @@ def main():
|
|||||||
else:
|
else:
|
||||||
logging.debug('Trying to find config')
|
logging.debug('Trying to find config')
|
||||||
#Try to find in "usual" places
|
#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'
|
trytoread = directory + 'routerstats.config'
|
||||||
if os.path.isfile(trytoread):
|
if os.path.isfile(trytoread):
|
||||||
logging.debug('Reading config file %s', trytoread)
|
logging.debug('Reading config file %s', trytoread)
|
||||||
config.read(trytoread)
|
config.read(trytoread)
|
||||||
found = True
|
found = True
|
||||||
if not found:
|
if not found:
|
||||||
logging.error('No config file found')
|
logging.error('routerstats.config not found in %s', config_dirs)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
|||||||
Reference in New Issue
Block a user