Refactor some variable names

feature-admin-split
Darksider3 5 years ago
parent 7ebabbb5f6
commit f204a74f98

@ -7,46 +7,47 @@ import lib.UserExceptions
import lib.uis.config_ui # dont go to default, just following -c flag import lib.uis.config_ui # dont go to default, just following -c flag
def import_from_file(fname: str, db: str, userids: tuple = tuple([])) -> bool: def import_from_file(file_path: str, db: str, user_ids: tuple = tuple([])) -> bool:
""" Imports Users from a given CSV-file to the system and DB """ Imports Users from a given CSV-file to the system and DB
:param fname: :param file_path:
:type fname: str :type file_path: str
:param db: Path to the sqlite db :param db: Path to the sqlite db
:type db: str :type db: str
:param userids: FIXME: Tuple which userids should we write :param user_ids: FIXME: Tuple which user_ids should we write
:type userids: tuple :type user_ids: tuple
:return: True on success, False when not :return: True on success, False when not
:rtype: bool :rtype: bool
""" """
if not os.path.isfile(fname): if not os.path.isfile(file_path):
print(f"File {fname} don't exist") print(f"File {file_path} don't exist")
return False return False
if not os.path.isfile(db): if not os.path.isfile(db):
print(f"The database file {db} don't exist") print(f"The database file {db} don't exist")
return False return False
if userids: if user_ids:
pass # empty tuple means everything pass # empty tuple means everything
# noinspection PyBroadException # noinspection PyBroadException
try: try:
with open(fname, 'r', newline='') as f: with open(file_path, 'r', newline='') as f:
import lib.validator import lib.validator
sql = lib.sqlitedb.SQLitedb(db) sql = lib.sqlitedb.SQLitedb(db)
err = lib.validator.checkImportFile(fname, db) err = lib.validator.checkImportFile(file_path, db)
if err is not True: if err is not True:
print(err) print(err)
exit(0) exit(0)
import lib.sqlitedb import lib.sqlitedb
import lib.System import lib.System
sysctl = lib.System.System() sys_ctl = lib.System.System("root")
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":
try: try:
sysctl.register(row["username"]) sys_ctl.setUser(row["username"])
sysctl.lock_user_pw(row["username"]) sys_ctl.register()
sysctl.add_to_usergroup(row["username"]) sys_ctl.lock_user_pw()
sysctl.make_ssh_usable(row["username"], row["pubkey"]) sys_ctl.add_to_usergroup()
sys_ctl.make_ssh_usable(row["pubkey"])
print(row['username'], "====> Registered.") print(row['username'], "====> Registered.")
except lib.UserExceptions.UserExistsAlready as UEA: except lib.UserExceptions.UserExistsAlready as UEA:
pass # @TODO User was determined to exists already, shouldn't happen but is possible pass # @TODO User was determined to exists already, shouldn't happen but is possible
@ -69,7 +70,7 @@ def import_from_file(fname: str, db: str, userids: tuple = tuple([])) -> bool:
row["email"], row["pubkey"], row["status"]])) row["email"], row["pubkey"], row["status"]]))
except OSError as E: except OSError as E:
pass pass
print(f"UUFFF, something went WRONG with the file {fname}: {E}") print(f"UUFFF, something went WRONG with the file {file_path}: {E}")
except Exception as didntCatch: except Exception as didntCatch:
print(f"Exception! UNCATCHED! {type(didntCatch)}: {didntCatch}") print(f"Exception! UNCATCHED! {type(didntCatch)}: {didntCatch}")
return True return True

Loading…
Cancel
Save