From 65c7bb6b3fdf920282c1c3f8005dca0853142890 Mon Sep 17 00:00:00 2001 From: Darksider3 Date: Tue, 22 Oct 2019 16:13:57 +0200 Subject: [PATCH] Move argparser into mains function body --- private/Backup.py | 10 ++++----- private/Import.py | 20 ++++++++--------- private/editUsers.py | 51 ++++++++++++++++++++++---------------------- 3 files changed, 39 insertions(+), 42 deletions(-) diff --git a/private/Backup.py b/private/Backup.py index 21d131c..9b69299 100755 --- a/private/Backup.py +++ b/private/Backup.py @@ -7,12 +7,6 @@ import configparser import lib.uis.default as default_cmd # Follows -u, -a, -f flags -default_cmd.argparser.description += " - Backups Tilde Users to stdout or a file." -args = default_cmd.argparser.parse_args() -config = configparser.ConfigParser() -config.read(args.config) - - class Backup: filename: str quoting: int @@ -52,6 +46,10 @@ class Backup: if __name__ == "__main__": + default_cmd.argparser.description += " - Backups Tilde Users to stdout or a file." + args = default_cmd.argparser.parse_args() + config = configparser.ConfigParser() + config.read(args.config) try: L = ListUsers.ListUsers(config['DEFAULT']['applications_db'], unapproved=args.unapproved, approved=args.approved) diff --git a/private/Import.py b/private/Import.py index 5e266ba..39e0c2e 100755 --- a/private/Import.py +++ b/private/Import.py @@ -6,16 +6,6 @@ import configparser import lib.UserExceptions import lib.uis.config_ui # dont go to default, just following -c flag -ArgParser = lib.uis.config_ui.argparser -ArgParser.description += "- Imports a CSV file consisting of user specific details to the database" -ArgParser.add_argument('-f', '--file', default="stdout", - type=str, help='Import from CSV file', required=True) -ArgParser.add_argument('--Import', default=False, action="store_true", - help="Import Users.", required=True) -args = ArgParser.parse_args() -config = configparser.ConfigParser() -config.read(args.config) - def ImportFromFile(fname: str, db: str, userids: tuple = tuple([])): if not os.path.isfile(fname): @@ -75,6 +65,16 @@ def ImportFromFile(fname: str, db: str, userids: tuple = tuple([])): if __name__ == "__main__": + + ArgParser = lib.uis.config_ui.argparser + ArgParser.description += "- Imports a CSV file consisting of user specific details to the database" + ArgParser.add_argument('-f', '--file', default="stdout", + type=str, help='Import from CSV file', required=True) + ArgParser.add_argument('--Import', default=False, action="store_true", + help="Import Users.", required=True) + args = ArgParser.parse_args() + config = configparser.ConfigParser() + config.read(args.config) try: if not args.Import: print("Error, need the import flag") diff --git a/private/editUsers.py b/private/editUsers.py index 36bf62e..9d7f6a6 100755 --- a/private/editUsers.py +++ b/private/editUsers.py @@ -8,35 +8,34 @@ import lib.System import lib.UserExceptions import sqlite3 -lib.uis.config_ui.argparser.description += " - Edit Tilde Users" -ArgParser = lib.uis.config_ui.argparser -ArgParser.add_argument('--user', type=str, - help='Tilde users name to edit', required=True) -Mutually = ArgParser.add_mutually_exclusive_group() -Mutually.add_argument('-r', '--remove', default=False, action="store_true", - help='Remove an approved/unapproved User from the system(and DB). Effectively purges him.', - required=False) -Mutually.add_argument("--verify", default=True, action="store_false", - help="Turns off value checks", - required=False) - -ArgParser.add_argument('--sshpubkey', type=str, default=None, - help="Stores the new given SSH-Key in given user", required=False) -ArgParser.add_argument('--name', type=str, default=None, - help="Sets the stored name of the given user") -ArgParser.add_argument('--username', type=str, default=None, - help="Rename given User") -ArgParser.add_argument('--email', type=str, default=None, - help="Set new email address for given user") -ArgParser.add_argument('--status', type=int, default=None, - help="Set status of given user") -args = ArgParser.parse_args() -config = configparser.ConfigParser() -config.read(args.config) +if __name__ == "__main__": + lib.uis.config_ui.argparser.description += " - Edit Tilde Users" + ArgParser = lib.uis.config_ui.argparser + ArgParser.add_argument('--user', type=str, + help='Tilde users name to edit', required=True) + Mutually = ArgParser.add_mutually_exclusive_group() + Mutually.add_argument('-r', '--remove', default=False, action="store_true", + help='Remove an approved/unapproved User from the system(and DB). Effectively purges him.', + required=False) + Mutually.add_argument("--verify", default=True, action="store_false", + help="Turns off value checks", + required=False) -if __name__ == "__main__": + ArgParser.add_argument('--sshpubkey', type=str, default=None, + help="Stores the new given SSH-Key in given user", required=False) + ArgParser.add_argument('--name', type=str, default=None, + help="Sets the stored name of the given user") + ArgParser.add_argument('--username', type=str, default=None, + help="Rename given User") + ArgParser.add_argument('--email', type=str, default=None, + help="Set new email address for given user") + ArgParser.add_argument('--status', type=int, default=None, + help="Set status of given user") + args = ArgParser.parse_args() + config = configparser.ConfigParser() + config.read(args.config) try: db = config['DEFAULT']['applications_db'] if not args.sshpubkey and not args.name and not args.username and not args.email and args.status is None \