From cdc72a30f4226c2864e3eddc9845ace819e7ba8f Mon Sep 17 00:00:00 2001 From: Darksider3 Date: Sat, 19 Oct 2019 14:25:43 +0200 Subject: [PATCH] Factor out REG_FILE --- private/Import.py | 5 +++-- private/ListUsers.py | 2 +- private/lib/CFG.py | 3 +-- private/lib/validator.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/private/Import.py b/private/Import.py index c44a31a..dc671ed 100644 --- a/private/Import.py +++ b/private/Import.py @@ -4,7 +4,8 @@ import os 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): print(f"File {fname} don't exist") return None @@ -24,7 +25,7 @@ def ImportFromFile(fname: str = CFG.args.file, db: str = CFG.REG_FILE, userids: import lib.sqlitedb import lib.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 for row in reader: if row["status"] == "1": diff --git a/private/ListUsers.py b/private/ListUsers.py index 05f21a6..1c311d8 100644 --- a/private/ListUsers.py +++ b/private/ListUsers.py @@ -9,7 +9,7 @@ class ListUsers: usersFetch = None 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 query = "SELECT * FROM `applications` WHERE status = '0'" elif app: # Approved users diff --git a/private/lib/CFG.py b/private/lib/CFG.py index bb10f35..bfab52c 100644 --- a/private/lib/CFG.py +++ b/private/lib/CFG.py @@ -8,5 +8,4 @@ config = configparser.ConfigParser() config.read(CONF_FILE) logging.basicConfig(format="%(asctime)s: %(message)s", level=int(config['LOG_LEVEL']['log_level']) - ) -REG_FILE = config['DEFAULT']['applications_db'] + ) \ No newline at end of file diff --git a/private/lib/validator.py b/private/lib/validator.py index f00b60b..1431239 100644 --- a/private/lib/validator.py +++ b/private/lib/validator.py @@ -34,7 +34,7 @@ def checkUserExists(username: str): def checkUserInDB(username: str): 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])) if fetched: return True