Factor out REG_FILE

pull/4/head
Darksider3 5 years ago
parent 77efb4b339
commit cdc72a30f4

@ -4,7 +4,8 @@ import os
import lib.UserExceptions import lib.UserExceptions
def ImportFromFile(fname: str = CFG.args.file, db: str = CFG.REG_FILE, userids: tuple = tuple([])): def ImportFromFile(fname: str = CFG.args.file, db: str = CFG.config['DEFAULT']['applications_db'],
userids: tuple = tuple([])):
if not os.path.isfile(fname): if not os.path.isfile(fname):
print(f"File {fname} don't exist") print(f"File {fname} don't exist")
return None return None
@ -24,7 +25,7 @@ def ImportFromFile(fname: str = CFG.args.file, db: str = CFG.REG_FILE, userids:
import lib.sqlitedb import lib.sqlitedb
import lib.System import lib.System
sysctl = lib.System.System() sysctl = lib.System.System()
sql = lib.sqlitedb.SQLitedb(CFG.REG_FILE) sql = lib.sqlitedb.SQLitedb(CFG.config['DEFAULT']['applications_db'])
reader = csv.DictReader(f) # @TODO csv.Sniffer to compare? When yes, give force-accept option reader = csv.DictReader(f) # @TODO csv.Sniffer to compare? When yes, give force-accept option
for row in reader: for row in reader:
if row["status"] == "1": if row["status"] == "1":

@ -9,7 +9,7 @@ class ListUsers:
usersFetch = None usersFetch = None
def __init__(self, uap: bool = CFG.args.unapproved, app: bool = CFG.args.approved): def __init__(self, uap: bool = CFG.args.unapproved, app: bool = CFG.args.approved):
self.db = SQLitedb(CFG.REG_FILE) self.db = SQLitedb(CFG.config['DEFAULT']['applications_db'])
if uap: # only unapproved users if uap: # only unapproved users
query = "SELECT * FROM `applications` WHERE status = '0'" query = "SELECT * FROM `applications` WHERE status = '0'"
elif app: # Approved users elif app: # Approved users

@ -9,4 +9,3 @@ config.read(CONF_FILE)
logging.basicConfig(format="%(asctime)s: %(message)s", logging.basicConfig(format="%(asctime)s: %(message)s",
level=int(config['LOG_LEVEL']['log_level']) level=int(config['LOG_LEVEL']['log_level'])
) )
REG_FILE = config['DEFAULT']['applications_db']

@ -34,7 +34,7 @@ def checkUserExists(username: str):
def checkUserInDB(username: str): def checkUserInDB(username: str):
try: try:
L = lib.sqlitedb.SQLitedb(CFG.REG_FILE) L = lib.sqlitedb.SQLitedb(CFG.config['DEFAULT']['applications_db'])
fetched = L.safequery("SELECT * FROM 'applications' WHERE username = ?", tuple([username])) fetched = L.safequery("SELECT * FROM 'applications' WHERE username = ?", tuple([username]))
if fetched: if fetched:
return True return True

Loading…
Cancel
Save