From 96837cebe305f9ae4172d5cb7413ecc4ad533805 Mon Sep 17 00:00:00 2001 From: Darksider3 Date: Sat, 12 Oct 2019 11:39:19 +0200 Subject: [PATCH] Externalize CFG-Handling into lib/CFG.py. Never write this code again! --- private/lib/CFG.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 private/lib/CFG.py diff --git a/private/lib/CFG.py b/private/lib/CFG.py new file mode 100644 index 0000000..b957d8a --- /dev/null +++ b/private/lib/CFG.py @@ -0,0 +1,22 @@ +import configparser, logging, argparse, os + +cwd = os.environ.get('TILDE_CONF') +if cwd is None: + cwd = os.getcwd() + "/applicationsconfig.ini" +else: + if os.path.isfile(cwd) is False: + cwd = os.getcwd() + "/applicationsconfig.ini" +# cwd is now either cwd/applicationsconfig or $TILDE_CONF +argparser = argparse.ArgumentParser(description='interactive registration formular for tilde platforms') +argparser.add_argument('-c', '--config', default=cwd, + type=str, help='Path to configuration file', required=False) +args = argparser.parse_args() + +CONF_FILE = args.config +config = configparser.ConfigParser() +config.read(CONF_FILE) +logging.basicConfig(format="%(asctime)s: %(message)s", + level=int(config['LOG_LEVEL']['log_level']) + ) +del cwd +REG_FILE = config['DEFAULT']['applications_db'] \ No newline at end of file