Allow specifying config file

This commit is contained in:
Christopher Teutsch 2019-06-26 11:29:23 +02:00
parent da0d8b886f
commit fd202ffe09
Signed by: iwonder
GPG Key ID: 0EE33D788D50130D

View File

@ -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.")