From 389b614de97909bce966a1b15cb412b539aec200 Mon Sep 17 00:00:00 2001 From: Darksider3 Date: Tue, 22 Oct 2019 15:52:00 +0200 Subject: [PATCH] Revert "ListUsers: UAP and APP renamed, function updates /home/users.txt" This reverts commit 84cc83db3c4bd1e7afcc0f50c1518a77a7eb880e. --- private/Backup.py | 2 +- private/Import.py | 2 +- private/ListUsers.py | 21 +++++++++++---------- private/editUsers.py | 2 +- private/lib/System.py | 13 +------------ 5 files changed, 15 insertions(+), 25 deletions(-) diff --git a/private/Backup.py b/private/Backup.py index 97e10f6..bd324e2 100755 --- a/private/Backup.py +++ b/private/Backup.py @@ -53,7 +53,7 @@ class Backup: if __name__ == "__main__": try: - L = ListUsers.ListUsers(config['DEFAULT']['applications_db'], unapproved=args.unapproved, approved=args.approved) + L = ListUsers.ListUsers(config['DEFAULT']['applications_db'], uap=args.unapproved, app=args.approved) fetch = L.getFetch() B = Backup(args.file) B.BackupToFile(fetch) diff --git a/private/Import.py b/private/Import.py index 28f15c7..5e266ba 100755 --- a/private/Import.py +++ b/private/Import.py @@ -37,7 +37,7 @@ def ImportFromFile(fname: str, db: str, userids: tuple = tuple([])): exit(0) import lib.sqlitedb import lib.System - sysctl = lib.System.System(db) + sysctl = lib.System.System() reader = csv.DictReader(f) # @TODO csv.Sniffer to compare? When yes, give force-accept option for row in reader: if row["status"] == "1": diff --git a/private/ListUsers.py b/private/ListUsers.py index e7c5e7b..2b96b7d 100755 --- a/private/ListUsers.py +++ b/private/ListUsers.py @@ -4,16 +4,23 @@ from lib.sqlitedb import SQLitedb import configparser import lib.uis.default as default_cmd # Follows -u, -a, -f flags +default_cmd.argparser.description += " - Lists Users from the Tilde database." +default_cmd.argparser.add_argument('--list', default=False, action="store_true", + help='Output a newline seperated list of users', required=False) +args = default_cmd.argparser.parse_args() +config = configparser.ConfigParser() +config.read(args.config) + class ListUsers: db = None usersFetch = None - def __init__(self, db: str, unapproved: bool = False, approved: bool = True): + def __init__(self, db: str, uap: bool = False, app: bool = True): self.db = SQLitedb(db) - if unapproved: # only unapproved users + if uap: # only unapproved users query = "SELECT * FROM `applications` WHERE `status` = '0'" - elif approved: # Approved users + elif app: # Approved users query = "SELECT * FROM `applications` WHERE `status` = '1'" else: # All users query = "SELECT * FROM `applications`" @@ -62,15 +69,9 @@ print(t.draw()) )) """ if __name__ == "__main__": - default_cmd.argparser.description += " - Lists Users from the Tilde database." - default_cmd.argparser.add_argument('--list', default=False, action="store_true", - help='Output a newline seperated list of users', required=False) - args = default_cmd.argparser.parse_args() - config = configparser.ConfigParser() - config.read(args.config) try: ret = "" - L = ListUsers(config['DEFAULT']['applications_db'], unapproved=args.unapproved, approved=args.approved) + L = ListUsers(config['DEFAULT']['applications_db'], uap=args.unapproved, app=args.approved) if args.list: ret = L.outputaslist() else: diff --git a/private/editUsers.py b/private/editUsers.py index 76e0d6f..36bf62e 100755 --- a/private/editUsers.py +++ b/private/editUsers.py @@ -47,7 +47,7 @@ if __name__ == "__main__": print(f"User {args.user} doesn't exist in the database.") exit(1) DB = lib.sqlitedb.SQLitedb(db) - Sysctl = lib.System.System(db) + Sysctl = lib.System.System() if not DB: print("Couldn't establish connection to database") exit(1) diff --git a/private/lib/System.py b/private/lib/System.py index fa8dcd6..17de845 100644 --- a/private/lib/System.py +++ b/private/lib/System.py @@ -10,9 +10,8 @@ class System: dry = False create_command = [] home = "" - db = None - def __init__(self, db: str, dryrun: bool = False, home: str = "/home/"): + def __init__(self, dryrun: bool = False, home: str = "/home/"): """Creates an objects. Can set dry run. :param dryrun: Run all command in a dry-run? When enabled, doesn't make any changes to the system (defaults to @@ -22,7 +21,6 @@ class System: :type home: str """ - self.db = db self.dry = dryrun if not home.endswith("/"): home += "/" @@ -49,7 +47,6 @@ class System: rt = subprocess.call(cc) if rt != 0: raise lib.UserExceptions.UserExistsAlready(f"User {username} exists already") - self._createUserIndex() return True def unregister(self, username: str): @@ -187,16 +184,8 @@ class System: if ret != 0 and ret != 6: raise lib.UserExceptions.UnknownReturnCode( f"Could not delete user with command {cc}. Return code: {ret}") - self._createUserIndex() return True - def _createUserIndex(self, index_file: str = "/home/users.txt"): - import ListUsers - L = ListUsers.ListUsers(self.db, unapproved=False, approved=True) - user_list = L.outputaslist() - with open(index_file, "w") as f: - print(user_list, file=f) - def AIO(username, pubkey, group="tilde"): syst = System(dryrun=False)