From fd202ffe09814c299dc3c6e884e8f639dc91de8f Mon Sep 17 00:00:00 2001 From: Christopher Teutsch Date: Wed, 26 Jun 2019 11:29:23 +0200 Subject: [PATCH] Allow specifying config file --- monitor.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/monitor.py b/monitor.py index bb3ed57..825b5ba 100755 --- a/monitor.py +++ b/monitor.py @@ -53,8 +53,10 @@ class Line: last_reply = None parser = argparse.ArgumentParser() parser.add_argument("-s", "--setup", help="Run the setup routine.", action="store_true", dest="setup") +parser.add_argument('-c', '--config', help='A configuration file', action='store', default='vrr.ini', dest='config') args = parser.parse_args() + if args.setup: import setup setup.setup() @@ -64,7 +66,7 @@ if args.setup: cfg = configparser.ConfigParser() try: - with open('vrr.ini') as f: + with open(args.config) as f: cfg.read_file(f) except IOError: sys.exit("Could not open the configuration file.") @@ -94,7 +96,7 @@ try: if cfg['crawl']['station_id'] is not None: USE_STATION_ID = cfg['crawl'].getint('station_id') else: - sys.exit("Please specify a station_id in the [crawl] section of vrr.ini") + sys.exit(f"Please specify a station_id in the [crawl] section of {args.config}") USE_LINES = cfg['crawl']['use_lines'].split(',') except (IndexError, configparser.NoOptionError, configparser.NoSectionError): sys.exit("There is something wrong with the configuration file. Exiting.")