From 5c6ecaf627a256e5b7015341ec3e885d502fa879 Mon Sep 17 00:00:00 2001 From: Darksider3 Date: Sat, 19 Oct 2019 13:50:30 +0200 Subject: [PATCH] Modularize CFG.py into CWD, default_cmd and cmd ui --- private/lib/CFG.py | 28 ++-------------------------- private/lib/cwd.py | 9 +++++++++ private/lib/default_cmd.py | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 26 deletions(-) create mode 100644 private/lib/cwd.py create mode 100644 private/lib/default_cmd.py diff --git a/private/lib/CFG.py b/private/lib/CFG.py index a8f79c7..dd5c1fa 100644 --- a/private/lib/CFG.py +++ b/private/lib/CFG.py @@ -1,37 +1,13 @@ import argparse import configparser import logging -import 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='Tilde administration tools') -argparser.add_argument('-c', '--config', default=cwd, - type=str, help='Path to configuration file', required=False) -# store_true just stores true when the command is supplied, so it doesn't need choices nor types -argparser.add_argument('-u', '--unapproved', default=False, action="store_true", - help='only unapproved users. Default is only approved.', required=False) -argparser.add_argument('-a', '--approved', default=False, action="store_true", - help="Only approved Users.", required=False) -argparser.add_argument('-f', '--file', default="stdout", - type=str, help='write to file instead of stdout', required=False) -argparser.add_argument('--Import', default=False, action="store_true", - help="Import Users from file. Affects currently only Import.py.\n" - "Setting this to true will result in -f being interpreted as the input file to import " - "users from. The file MUST be a comma separated CSV file being readable having it's " - "defined columns written in the first line.") -args = argparser.parse_args() +import lib.default_cmd as default_cmd +args = default_cmd.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'] diff --git a/private/lib/cwd.py b/private/lib/cwd.py new file mode 100644 index 0000000..09f0056 --- /dev/null +++ b/private/lib/cwd.py @@ -0,0 +1,9 @@ +import 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 diff --git a/private/lib/default_cmd.py b/private/lib/default_cmd.py new file mode 100644 index 0000000..7572b68 --- /dev/null +++ b/private/lib/default_cmd.py @@ -0,0 +1,19 @@ +import argparse +import configparser +import logging +import lib.cwd +argparser = argparse.ArgumentParser(description='Tilde administration tools') +argparser.add_argument('-c', '--config', default=lib.cwd.cwd, + type=str, help='Path to configuration file', required=False) +# store_true just stores true when the command is supplied, so it doesn't need choices nor types +argparser.add_argument('-u', '--unapproved', default=False, action="store_true", + help='only unapproved users. Default is only approved.', required=False) +argparser.add_argument('-a', '--approved', default=False, action="store_true", + help="Only approved Users.", required=False) +argparser.add_argument('-f', '--file', default="stdout", + type=str, help='write to file instead of stdout', required=False) +argparser.add_argument('--Import', default=False, action="store_true", + help="Import Users from file. Affects currently only Import.py.\n" + "Setting this to true will result in -f being interpreted as the input file to import " + "users from. The file MUST be a comma separated CSV file being readable having it's " + "defined columns written in the first line.") \ No newline at end of file