mirror of
https://github.com/th3r00t/pyShelf.git
synced 2026-04-28 01:59:35 -04:00
Fixed database access issues, and installer question list
This commit is contained in:
1
importBooks
vendored
1
importBooks
vendored
@@ -3,6 +3,7 @@
|
|||||||
import pathlib
|
import pathlib
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from src.backend.lib.storage import Storage
|
||||||
from src.backend.pyShelf_ScanLibrary import execute_scan
|
from src.backend.pyShelf_ScanLibrary import execute_scan
|
||||||
|
|
||||||
PRG_PATH = pathlib.Path.cwd()
|
PRG_PATH = pathlib.Path.cwd()
|
||||||
|
|||||||
16
installer
vendored
16
installer
vendored
@@ -152,7 +152,7 @@ class SystemInstaller:
|
|||||||
wsgiport = r["answer"]
|
wsgiport = r["answer"]
|
||||||
nginx_conf_str = """
|
nginx_conf_str = """
|
||||||
# pyshelf_nginx.conf
|
# pyshelf_nginx.conf
|
||||||
upstream django {server %s:%s;}
|
upstream django {server unix:///tmp/pyshelf_wsgi.sock;}
|
||||||
server {
|
server {
|
||||||
listen %s;
|
listen %s;
|
||||||
server_name %s;
|
server_name %s;
|
||||||
@@ -166,8 +166,6 @@ class SystemInstaller:
|
|||||||
location / {uwsgi_pass django; include %s/uwsgi_params;}
|
location / {uwsgi_pass django; include %s/uwsgi_params;}
|
||||||
}
|
}
|
||||||
""" % (
|
""" % (
|
||||||
hostname,
|
|
||||||
wsgiport,
|
|
||||||
port,
|
port,
|
||||||
hostname,
|
hostname,
|
||||||
root,
|
root,
|
||||||
@@ -195,11 +193,10 @@ class SystemInstaller:
|
|||||||
master=True
|
master=True
|
||||||
pidfile=/tmp/pyShelf.pid
|
pidfile=/tmp/pyShelf.pid
|
||||||
vacuum=True
|
vacuum=True
|
||||||
socket=%s:%s
|
socket=/tmp/pyshelf_wsgi.sock
|
||||||
|
chmod-socket=777
|
||||||
""" % (
|
""" % (
|
||||||
root,
|
root,
|
||||||
hostname,
|
|
||||||
wsgiport
|
|
||||||
)
|
)
|
||||||
with open(_fp, "w") as write_file:
|
with open(_fp, "w") as write_file:
|
||||||
write_file.write(wsgi_conf_str)
|
write_file.write(wsgi_conf_str)
|
||||||
@@ -223,7 +220,7 @@ installer = sysinstall.bin
|
|||||||
install_answers = TerminalDisplay().installer()
|
install_answers = TerminalDisplay().installer()
|
||||||
for key in install_answers:
|
for key in install_answers:
|
||||||
config[key["name"]] = key["answer"]
|
config[key["name"]] = key["answer"]
|
||||||
|
config["USER"] = os.environ["USER"]
|
||||||
# Write configuration
|
# Write configuration
|
||||||
Configuration().write_file(config)
|
Configuration().write_file(config)
|
||||||
|
|
||||||
@@ -300,8 +297,9 @@ if RequiredServices().db_server_found(req) is False:
|
|||||||
)
|
)
|
||||||
install_status = os.system(cmd)
|
install_status = os.system(cmd)
|
||||||
for r in install_answers:
|
for r in install_answers:
|
||||||
if r["name"] == "USER": sql_user = r["answer"]
|
if r["name"] == "PASSWORD": sql_pass = r["answer"]
|
||||||
elif r["name"] == "PASSWORD": sql_pass = r["answer"]
|
|
||||||
|
sql_user = config["USER"]
|
||||||
db_name = "pyshelf"
|
db_name = "pyshelf"
|
||||||
psql_cmd = """
|
psql_cmd = """
|
||||||
CREATE DATABASE %s;
|
CREATE DATABASE %s;
|
||||||
|
|||||||
@@ -44,13 +44,6 @@ class TerminalDisplay:
|
|||||||
"answer": None,
|
"answer": None,
|
||||||
"default": "5432",
|
"default": "5432",
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"message": ' Input your PostgreSQL user name\n Enter for default "pyshelf" > ',
|
|
||||||
"options": "pyshelf",
|
|
||||||
"name": "USER",
|
|
||||||
"answer": None,
|
|
||||||
"default": "pyshelf",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"message": ' Input your PostgreSQL password\n Enter for default "pyshelf" > ',
|
"message": ' Input your PostgreSQL password\n Enter for default "pyshelf" > ',
|
||||||
"options": "pyshelf",
|
"options": "pyshelf",
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ class Catalogue:
|
|||||||
"""
|
"""
|
||||||
Calls storage system, gets list of books stored and compares against files on disk
|
Calls storage system, gets list of books stored and compares against files on disk
|
||||||
"""
|
"""
|
||||||
db = Storage(self.db_pointer, self.config)
|
db = Storage(self.config)
|
||||||
stored = db.book_paths_list()
|
stored = db.book_paths_list()
|
||||||
db.close()
|
db.close()
|
||||||
if self.books is None:
|
if self.books is None:
|
||||||
@@ -162,7 +162,7 @@ class Catalogue:
|
|||||||
Iterates over list and inserts new books into database.
|
Iterates over list and inserts new books into database.
|
||||||
"""
|
"""
|
||||||
book_list = self.compare_shelf_current()
|
book_list = self.compare_shelf_current()
|
||||||
db = Storage(self.db_pointer, self.config)
|
db = Storage(self.config)
|
||||||
for book in book_list:
|
for book in book_list:
|
||||||
book = self.process_book(book)
|
book = self.process_book(book)
|
||||||
extracted = self.extract_metadata(book)
|
extracted = self.extract_metadata(book)
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ from .config import Config
|
|||||||
class Storage:
|
class Storage:
|
||||||
"""Contains all methods for system storage"""
|
"""Contains all methods for system storage"""
|
||||||
|
|
||||||
def __init__(self, db_pointer, config):
|
def __init__(self, config):
|
||||||
# self.db_file = db_pointer
|
|
||||||
self.sql = config.catalogue_db
|
self.sql = config.catalogue_db
|
||||||
self.user = config.user
|
self.user = config.user
|
||||||
self.password = config.password
|
self.password = config.password
|
||||||
@@ -22,8 +21,27 @@ class Storage:
|
|||||||
self.db = psycopg2.connect(
|
self.db = psycopg2.connect(
|
||||||
database=self.sql, user=self.user, password=self.password, host=self.db_host
|
database=self.sql, user=self.user, password=self.password, host=self.db_host
|
||||||
)
|
)
|
||||||
|
self.config = config
|
||||||
self.cursor = self.db.cursor()
|
self.cursor = self.db.cursor()
|
||||||
# self.create_tables()
|
|
||||||
|
def check_ownership(self, table=None):
|
||||||
|
if table is None:
|
||||||
|
table = "books"
|
||||||
|
_q = "SELECT * FROM books"
|
||||||
|
try:
|
||||||
|
self.cursor.execute(_q)
|
||||||
|
except Exception as e:
|
||||||
|
breakpoint()
|
||||||
|
if e.pgcode == "42501":
|
||||||
|
_q = """ALTER TABLE public.books OWNER to pyshelf;"""
|
||||||
|
self.close()
|
||||||
|
set_perms = Storage(self.config)
|
||||||
|
try:
|
||||||
|
set_perms.cursor.execute(_q)
|
||||||
|
set_perms.close()
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
set_perms.close()
|
||||||
|
|
||||||
def create_tables(self):
|
def create_tables(self):
|
||||||
"""Create table structure"""
|
"""Create table structure"""
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import time
|
|||||||
from .lib.config import Config
|
from .lib.config import Config
|
||||||
from .lib.library import Catalogue
|
from .lib.library import Catalogue
|
||||||
from .lib.pyShelf import InitFiles
|
from .lib.pyShelf import InitFiles
|
||||||
|
from .lib.storage import Storage
|
||||||
|
|
||||||
sys.path.append(os.path.abspath("."))
|
sys.path.append(os.path.abspath("."))
|
||||||
|
|
||||||
@@ -18,6 +19,8 @@ def execute_scan(root):
|
|||||||
_t1 = time.time()
|
_t1 = time.time()
|
||||||
config = Config(root) # Get configuration settings
|
config = Config(root) # Get configuration settings
|
||||||
InitFiles(config.file_array) # Initialize file system
|
InitFiles(config.file_array) # Initialize file system
|
||||||
|
|
||||||
|
Storage(config).check_ownership()
|
||||||
catalogue = Catalogue(config) # Open the Catalogue
|
catalogue = Catalogue(config) # Open the Catalogue
|
||||||
catalogue.import_books()
|
catalogue.import_books()
|
||||||
_t2 = time.time()
|
_t2 = time.time()
|
||||||
|
|||||||
@@ -107,8 +107,8 @@ DATABASES = {
|
|||||||
DATABASES = {
|
DATABASES = {
|
||||||
"default": {
|
"default": {
|
||||||
"ENGINE": "django.db.backends.postgresql",
|
"ENGINE": "django.db.backends.postgresql",
|
||||||
"NAME": CONFIG.user,
|
"NAME": CONFIG.DATABASE,
|
||||||
"PASSWORD": CONFIG.password,
|
"PASSWORD": CONFIG.PASSWORD,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ class Books(models.Model):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = "books"
|
db_table = "books"
|
||||||
|
managed = False
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|||||||
Reference in New Issue
Block a user