From 88c0eff293bf00f3b4385bf749fe6ad0069dcb47 Mon Sep 17 00:00:00 2001 From: th3r00t Date: Thu, 10 Sep 2020 14:11:55 -0400 Subject: [PATCH] Adjusted logging to avoid max recursion errors --- configure | 15 +++++++++++++-- src/backend/lib/storage.py | 21 ++++++++++----------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/configure b/configure index 1b03abc..e0ab28c 100755 --- a/configure +++ b/configure @@ -6,7 +6,6 @@ from pathlib import Path from django.core.management.utils import get_random_secret_key from src.backend.lib.pyShelf import Admin - def load_config(): with open('config.json',"r") as file: config = json.load(file) @@ -26,8 +25,20 @@ def set_secret(config=load_config()): write_config(config) print(config["SECRET"]) else: - print(config["SECRET"]) + print("Secret already set, skipping.") +def init_django_database(): + cmds = [ + 'python manage.py makemigrations', + 'python manage.py makemigrations interface', + 'python manage.py migrate', + 'python manage.py migrate interface', + ] + os.chdir("src") + for cmd in cmds: + os.system(cmd) + os.chdir("../") set_secret() +init_django_database() Admin(Path.cwd()).createsuperuser() diff --git a/src/backend/lib/storage.py b/src/backend/lib/storage.py index 6052f32..8feaf0c 100755 --- a/src/backend/lib/storage.py +++ b/src/backend/lib/storage.py @@ -7,16 +7,16 @@ import psycopg2 class Storage: """Contains all methods for system storage""" - def __init__(self, config): self.sql = config.catalogue_db self.user = config.user self.password = config.password self.db_host = config.db_host self.db_port = config.db_port - self.db = psycopg2.connect( - database=self.sql, user=self.user, password=self.password, host=self.db_host - ) + self.db = psycopg2.connect(database=self.sql, + user=self.user, + password=self.password, + host=self.db_host) self.config = config self.cursor = self.db.cursor() @@ -77,7 +77,7 @@ class Storage: book[9], # tags ), ) - self.config.logger.info(book[0]) + self.config.logger.info(book[0][0:80]) return True except Exception as e: if e.pgcode == '22007': # psycopg2's error code for invalid date @@ -143,12 +143,11 @@ class Storage: try: self.cursor.execute(_q_x) if len(self.cursor.fetchall()) < 1: - self.cursor.execute( - """INSERT INTO collections\ - (collection, book_id_id) VALUES ('%s',%s)""" - % (_s, book[0]) - ) - self.config.logger.info("Collection {} Added".format(_s)) + self.cursor.execute("""INSERT INTO collections\ + (collection, book_id_id) VALUES ('%s',%s)""" % + (_s, book[0])) + self.config.logger.info( + "Collection {} Added".format(_s)) except Exception as e: self.config.logger.error(e) _collections.append(_p)