mirror of
https://github.com/th3r00t/pyShelf.git
synced 2026-04-28 01:59:35 -04:00
Updated config calls, and error handling
This commit is contained in:
19
configure
vendored
19
configure
vendored
@@ -1,10 +1,10 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import json
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from django.core.management.utils import get_random_secret_key
|
from django.core.management.utils import get_random_secret_key
|
||||||
from src.backend.lib.pyShelf import Admin
|
from src.backend.lib.pyShelf import Admin
|
||||||
|
from src.backend.lib.storage import Storage
|
||||||
|
|
||||||
|
|
||||||
def load_config():
|
def load_config():
|
||||||
@@ -27,10 +27,14 @@ def set_secret(config=load_config()):
|
|||||||
else:
|
else:
|
||||||
print("Secret already set, skipping.")
|
print("Secret already set, skipping.")
|
||||||
|
|
||||||
|
|
||||||
def set_book_directory(config=load_config(), *args):
|
def set_book_directory(config=load_config(), *args):
|
||||||
if config["BOOKPATH"] == "":
|
if config["BOOKPATH"] == "":
|
||||||
try: config["BOOKPATH"] = args[0]
|
try:
|
||||||
except IndexError: config["BOOKPATH"] = input("Input Book Directory ")
|
config["BOOKPATH"] = args[0]
|
||||||
|
except IndexError:
|
||||||
|
config["BOOKPATH"] = input("Input Book Directory ")
|
||||||
|
|
||||||
|
|
||||||
def init_django_database():
|
def init_django_database():
|
||||||
cmds = [
|
cmds = [
|
||||||
@@ -44,10 +48,15 @@ def init_django_database():
|
|||||||
os.system(cmd)
|
os.system(cmd)
|
||||||
os.chdir("../")
|
os.chdir("../")
|
||||||
|
|
||||||
|
|
||||||
config = load_config()
|
config = load_config()
|
||||||
|
|
||||||
set_secret(config)
|
set_secret(config)
|
||||||
set_book_directory(config)
|
set_book_directory(config)
|
||||||
write_config(config)
|
write_config(config)
|
||||||
init_django_database()
|
# TODO:: Refactor here to enable backend to handle database operations.
|
||||||
Admin(Path.cwd()).createsuperuser()
|
breakpoint
|
||||||
|
storage = Storage(config)
|
||||||
|
storage.create_tables()
|
||||||
|
# init_django_database()
|
||||||
|
# Admin(Path.cwd()).createsuperuser()
|
||||||
|
|||||||
12
src/backend/lib/storage.py
vendored
12
src/backend/lib/storage.py
vendored
@@ -8,11 +8,11 @@ import psycopg2
|
|||||||
class Storage:
|
class Storage:
|
||||||
"""Contains all methods for system storage"""
|
"""Contains all methods for system storage"""
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.sql = config.catalogue_db
|
self.sql = config["DATABASE"]
|
||||||
self.user = config.user
|
self.user = config["USER"]
|
||||||
self.password = config.password
|
self.password = config["PASSWORD"]
|
||||||
self.db_host = config.db_host
|
self.db_host = config["DB_HOST"]
|
||||||
self.db_port = config.db_port
|
self.db_port = config["DB_PORT"]
|
||||||
self.db = psycopg2.connect(database=self.sql,
|
self.db = psycopg2.connect(database=self.sql,
|
||||||
user=self.user,
|
user=self.user,
|
||||||
password=self.password,
|
password=self.password,
|
||||||
@@ -46,7 +46,7 @@ class Storage:
|
|||||||
file_name text)"""
|
file_name text)"""
|
||||||
try:
|
try:
|
||||||
self.cursor.execute(q_check)
|
self.cursor.execute(q_check)
|
||||||
except Exception as e:
|
except psycopg2.errors.UndefinedTable:
|
||||||
self.cursor.execute(q_create)
|
self.cursor.execute(q_create)
|
||||||
|
|
||||||
def insert_book(self, book):
|
def insert_book(self, book):
|
||||||
|
|||||||
Reference in New Issue
Block a user