# Copyright (C) 2020 by Thomas Lindner # Copyright (C) 2020 by Cathy Hu # Copyright (C) 2020 by Martin Rey # # SPDX-License-Identifier: 0BSD """ Configuration file and command line argument parser. Gives a dictionary named `config` with configuration parsed either from `/etc/kibicara.conf` or from a file given by command line argument `-f`. If no configuration was found at all, the defaults are used. Example: ``` from kibicara.config import config print(config) ``` """ from argparse import ArgumentParser from pytoml import load from sys import argv config = { 'database_connection': 'sqlite:////tmp/kibicara.sqlite', 'frontend_path': None, 'root_url': 'http://localhost:8000/', } """ Default configuration. The default configuration gets overwritten by a configuration file if one exists. """ if argv[0].endswith('kibicara'): parser = ArgumentParser() parser.add_argument( '-f', '--config', dest='configfile', default='/etc/kibicara.conf', help='path to config file', ) args = parser.parse_args() try: with open(args.configfile) as configfile: config.update(load(configfile)) except FileNotFoundError: # run with default config pass