Factor out 'as CFG'

feature-admin-split
Darksider3 5 years ago
parent 670aa3d9c3
commit 934b6bf75a

@ -3,10 +3,7 @@
import ListUsers
import csv
import io
import lib.CFG as CFG
import lib.validator
import lib.UserExceptions
import os
import lib.CFG
class Backup:
@ -15,7 +12,7 @@ class Backup:
dialect: str
field_names: tuple
def __init__(self, fname: str = CFG.args.file, quoting: int = csv.QUOTE_NONNUMERIC, dialect: str = "excel"):
def __init__(self, fname: str = lib.CFG.args.file, quoting: int = csv.QUOTE_NONNUMERIC, dialect: str = "excel"):
self.setFilename(fname)
self.setQuoting(quoting)
self.setDialect(dialect)
@ -52,7 +49,7 @@ if __name__ == "__main__":
L = ListUsers.ListUsers()
fetch = L.getFetch()
B = Backup()
if CFG.args.Import:
if lib.CFG.args.Import:
print("For importing please call the ./Import.py file with the --Import flag")
else:
B.BackupToFile(fetch)

@ -1,10 +1,10 @@
import lib.CFG as CFG
import lib.CFG
import csv
import os
import lib.UserExceptions
def ImportFromFile(fname: str = CFG.args.file, db: str = CFG.config['DEFAULT']['applications_db'],
def ImportFromFile(fname: str = lib.CFG.args.file, db: str = lib.CFG.config['DEFAULT']['applications_db'],
userids: tuple = tuple([])):
if not os.path.isfile(fname):
print(f"File {fname} don't exist")
@ -25,7 +25,7 @@ def ImportFromFile(fname: str = CFG.args.file, db: str = CFG.config['DEFAULT']['
import lib.sqlitedb
import lib.System
sysctl = lib.System.System()
sql = lib.sqlitedb.SQLitedb(CFG.config['DEFAULT']['applications_db'])
sql = lib.sqlitedb.SQLitedb(lib.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":
@ -64,11 +64,11 @@ def ImportFromFile(fname: str = CFG.args.file, db: str = CFG.config['DEFAULT']['
if __name__ == "__main__":
try:
if not CFG.args.Import:
if not lib.CFG.args.Import:
print("Error, need the import flag")
if not CFG.args.file:
if not lib.CFG.args.file:
print("Error, need the import file")
if not CFG.args.file:
if not lib.CFG.args.file:
print("You MUST set a CSV-file with the -f/--file flag that already exist")
exit(1)
ImportFromFile()

@ -1,15 +1,15 @@
#!/usr/bin/env python3
from lib.sqlitedb import SQLitedb
import lib.CFG as CFG
import lib.CFG
class ListUsers:
db = None
usersFetch = None
def __init__(self, uap: bool = CFG.args.unapproved, app: bool = CFG.args.approved):
self.db = SQLitedb(CFG.config['DEFAULT']['applications_db'])
def __init__(self, uap: bool = lib.CFG.args.unapproved, app: bool = lib.CFG.args.approved):
self.db = SQLitedb(lib.CFG.config['DEFAULT']['applications_db'])
if uap: # only unapproved users
query = "SELECT * FROM `applications` WHERE status = '0'"
elif app: # Approved users
@ -64,8 +64,8 @@ print(t.draw())
ret += "%-4i| %-14s| %-25s| %-22s| %-8s | %-5i |\n" % (
user["id"], user["username"], user["email"], user["name"], user["timestamp"], user["status"]
)
if CFG.args.file != "stdout":
with open(CFG.args.file, 'w') as f:
if lib.CFG.args.file != "stdout":
with open(lib.CFG.args.file, 'w') as f:
print(ret, file=f)
else:
print(ret)

@ -1,7 +1,7 @@
import re
import pwd
import lib.sqlitedb
import lib.CFG as CFG
import lib.CFG
def checkUsernameCharacters(username: str):
@ -34,8 +34,8 @@ def checkUserExists(username: str):
def checkUserInDB(username: str):
try:
L = lib.sqlitedb.SQLitedb(CFG.config['DEFAULT']['applications_db'])
fetched = L.safequery("SELECT * FROM 'applications' WHERE username = ?", tuple([username]))
ldb = lib.sqlitedb.SQLitedb(lib.CFG.config['DEFAULT']['applications_db'])
fetched = ldb.safequery("SELECT * FROM 'applications' WHERE username = ?", tuple([username]))
if fetched:
return True
except lib.sqlitedb.sqlite3.Error as e:

Loading…
Cancel
Save