mirror of
https://github.com/th3r00t/pyShelf.git
synced 2026-04-28 01:59:35 -04:00
Pre Refactor of main loop
This commit is contained in:
29
configure
vendored
29
configure
vendored
@@ -4,7 +4,9 @@ import json
|
||||
from src.backend.lib.storage import Storage
|
||||
from src.backend.lib.config import Config
|
||||
|
||||
|
||||
def load_config():
|
||||
"""Load program configuration."""
|
||||
with open('config.json', "r") as file:
|
||||
config = json.load(file)
|
||||
file.close()
|
||||
@@ -12,20 +14,14 @@ def load_config():
|
||||
|
||||
|
||||
def write_config(config):
|
||||
"""Write program configuration."""
|
||||
with open('config.json', "w") as file:
|
||||
json.dump(config, file)
|
||||
file.close()
|
||||
|
||||
|
||||
def set_secret(config=load_config()):
|
||||
if config["SECRET"] == "":
|
||||
config["SECRET"] = get_random_secret_key()
|
||||
print(config["SECRET"])
|
||||
else:
|
||||
print("Secret already set, skipping.")
|
||||
|
||||
|
||||
def set_book_directory(config=load_config(), *args):
|
||||
"""Set book directory."""
|
||||
if config["BOOKPATH"] == "":
|
||||
try:
|
||||
config["BOOKPATH"] = args[0]
|
||||
@@ -33,26 +29,9 @@ def set_book_directory(config=load_config(), *args):
|
||||
config["BOOKPATH"] = input("Input Book Directory ")
|
||||
|
||||
|
||||
def init_django_database():
|
||||
cmds = [
|
||||
'python3 manage.py makemigrations',
|
||||
'python3 manage.py makemigrations interface',
|
||||
'python3 manage.py migrate',
|
||||
'python3 manage.py migrate interface',
|
||||
]
|
||||
os.chdir("src")
|
||||
for cmd in cmds:
|
||||
os.system(cmd)
|
||||
os.chdir("../")
|
||||
|
||||
|
||||
config_file = load_config()
|
||||
config = Config(os.path.split(os.path.realpath(__file__))[0])
|
||||
set_secret(config_file)
|
||||
set_book_directory(config_file)
|
||||
write_config(config_file)
|
||||
# TODO:: Refactor here to enable backend to handle database operations.
|
||||
storage = Storage(config)
|
||||
storage.create_tables()
|
||||
# init_django_database()
|
||||
# Admin(Path.cwd()).createsuperuser()
|
||||
|
||||
Reference in New Issue
Block a user