Revert "ListUsers: UAP and APP renamed, function updates /home/users.txt"

This reverts commit 84cc83db3c.
pull/4/head
Darksider3 5 years ago
parent 84cc83db3c
commit 389b614de9

@ -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)

@ -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":

@ -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:

@ -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)

@ -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)

Loading…
Cancel
Save