Merge pull request #35 from th3r00t/0.5.0-collections

0.5.0 collections
This commit is contained in:
th3r00t
2020-03-25 16:19:01 -04:00
committed by GitHub
267 changed files with 749 additions and 355 deletions

3
.gitignore vendored
View File

@@ -129,3 +129,6 @@ create_db.sql
uwsgi.ini uwsgi.ini
installer.log installer.log
pyshelf_nginx.conf pyshelf_nginx.conf
tags
TAGS
config.json

0
LICENSE vendored Normal file → Executable file
View File

0
README.md vendored Normal file → Executable file
View File

2
config.json vendored Normal file → Executable file
View File

@@ -1 +1 @@
{"TITLE": "pyShelf E-Book Server", "VERSION": "0.4.1", "BOOKPATH": "", "DB_HOST": "localhost", "DB_PORT": "5432", "DATABASE": "pyshelf", "USER": "pyshelf", "PASSWORD": "pyshelf", "BOOKSHELF": "data/shelf.json", "ALLOWED_HOSTS": "*", "hostname": "localhost", "webport": "8000", "wsgiport": "8001"} {"TITLE": "pyShelf E-Book Server", "VERSION": "0.5.0", "BOOKPATH": "/home/raelon/Books", "DB_HOST": "localhost", "DB_PORT": "5432", "DATABASE": "pyshelf", "USER": "pyshelf", "PASSWORD": "pyshelf", "BOOKSHELF": "data/shelf.json", "ALLOWED_HOSTS": "*", "hostname": "localhost", "webport": "8000", "wsgiport": "8001"}

0
data/.track_this_folder vendored Normal file → Executable file
View File

0
docs/html/annotated.html vendored Normal file → Executable file
View File

0
docs/html/bc_s.png vendored Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 676 B

After

Width:  |  Height:  |  Size: 676 B

0
docs/html/bdwn.png vendored Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 147 B

After

Width:  |  Height:  |  Size: 147 B

0
docs/html/classes.html vendored Normal file → Executable file
View File

0
docs/html/closed.png vendored Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 132 B

After

Width:  |  Height:  |  Size: 132 B

View File

View File

View File

View File

Before

Width:  |  Height:  |  Size: 853 B

After

Width:  |  Height:  |  Size: 853 B

View File

View File

View File

Before

Width:  |  Height:  |  Size: 966 B

After

Width:  |  Height:  |  Size: 966 B

View File

View File

View File

View File

View File

View File

0
docs/html/d8/dfe/classsrc_1_1backend_1_1lib_1_1config_1_1Config.png vendored Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 858 B

After

Width:  |  Height:  |  Size: 858 B

View File

View File

View File

View File

Before

Width:  |  Height:  |  Size: 962 B

After

Width:  |  Height:  |  Size: 962 B

View File

View File

0
docs/html/dir_1c7294442ce83d360610449d04c9d7fc.html vendored Normal file → Executable file
View File

0
docs/html/dir_3f615ade772d23cefe5e20dcb18424a2.html vendored Normal file → Executable file
View File

0
docs/html/dir_68267d1309a1af8e8297ef4c3efbcdba.html vendored Normal file → Executable file
View File

0
docs/html/dir_9020577e2da81c4cf5a5554c26431f94.html vendored Normal file → Executable file
View File

0
docs/html/doc.png vendored Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 746 B

After

Width:  |  Height:  |  Size: 746 B

1
docs/html/doxygen.css vendored Normal file → Executable file
View File

@@ -1768,4 +1768,3 @@ tt, code, kbd, samp
u { u {
text-decoration: underline; text-decoration: underline;
} }

0
docs/html/doxygen.png vendored Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

0
docs/html/dynsections.js vendored Normal file → Executable file
View File

0
docs/html/files.html vendored Normal file → Executable file
View File

0
docs/html/folderclosed.png vendored Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 616 B

After

Width:  |  Height:  |  Size: 616 B

0
docs/html/folderopen.png vendored Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 597 B

After

Width:  |  Height:  |  Size: 597 B

0
docs/html/functions.html vendored Normal file → Executable file
View File

0
docs/html/functions_func.html vendored Normal file → Executable file
View File

0
docs/html/hierarchy.html vendored Normal file → Executable file
View File

0
docs/html/index.hhc vendored Normal file → Executable file
View File

0
docs/html/index.hhk vendored Normal file → Executable file
View File

0
docs/html/index.hhp vendored Normal file → Executable file
View File

0
docs/html/index.html vendored Normal file → Executable file
View File

0
docs/html/jquery.js vendored Normal file → Executable file
View File

0
docs/html/menu.js vendored Normal file → Executable file
View File

0
docs/html/menudata.js vendored Normal file → Executable file
View File

0
docs/html/nav_f.png vendored Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 153 B

After

Width:  |  Height:  |  Size: 153 B

0
docs/html/nav_g.png vendored Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 95 B

After

Width:  |  Height:  |  Size: 95 B

0
docs/html/nav_h.png vendored Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 98 B

After

Width:  |  Height:  |  Size: 98 B

0
docs/html/open.png vendored Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 123 B

After

Width:  |  Height:  |  Size: 123 B

0
docs/html/splitbar.png vendored Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 314 B

After

Width:  |  Height:  |  Size: 314 B

0
docs/html/sync_off.png vendored Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 853 B

After

Width:  |  Height:  |  Size: 853 B

0
docs/html/sync_on.png vendored Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 845 B

After

Width:  |  Height:  |  Size: 845 B

0
docs/html/tab_a.png vendored Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 142 B

After

Width:  |  Height:  |  Size: 142 B

0
docs/html/tab_b.png vendored Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 169 B

After

Width:  |  Height:  |  Size: 169 B

0
docs/html/tab_h.png vendored Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 177 B

After

Width:  |  Height:  |  Size: 177 B

0
docs/html/tab_s.png vendored Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 184 B

After

Width:  |  Height:  |  Size: 184 B

0
docs/html/tabs.css vendored Normal file → Executable file
View File

0
docs/man/man3/src_backend_lib_api_hooks_DuckDuckGo.3 vendored Normal file → Executable file
View File

0
docs/man/man3/src_backend_lib_config_Config.3 vendored Normal file → Executable file
View File

0
docs/man/man3/src_backend_lib_display_TerminalDisplay.3 vendored Normal file → Executable file
View File

0
docs/man/man3/src_backend_lib_library_Catalogue.3 vendored Normal file → Executable file
View File

0
docs/man/man3/src_backend_lib_pyShelf_BookDisplay.3 vendored Normal file → Executable file
View File

0
docs/man/man3/src_backend_lib_pyShelf_InitFiles.3 vendored Normal file → Executable file
View File

0
docs/man/man3/src_backend_lib_storage_Storage.3 vendored Normal file → Executable file
View File

0
docs/man/man3/src_backend_tests_config_test_TestConfig.3 vendored Normal file → Executable file
View File

0
docs/man/man3/src_backend_tests_library_test_TestCatalogue.3 vendored Normal file → Executable file
View File

0
docs/man/man3/src_backend_tests_library_test_Test_Catalogue.3 vendored Normal file → Executable file
View File

0
docs/man/man3/src_backend_tests_library_test_Test_Config.3 vendored Normal file → Executable file
View File

0
docs/warn.log vendored Normal file → Executable file
View File

0
doxygen.conf vendored Normal file → Executable file
View File

2
importBooks vendored
View File

@@ -1,4 +1,4 @@
#!/usr/bin/python #!python
import pathlib import pathlib
import sys import sys

51
installer vendored Normal file → Executable file
View File

@@ -1,4 +1,4 @@
#!/usr/bin/python3 #!python
import json import json
import os import os
import pathlib import pathlib
@@ -136,6 +136,9 @@ class SystemInstaller:
if os.path.isdir(_dirs[1]): if os.path.isdir(_dirs[1]):
ln_string = str(_dirs[0] + outfile + " " + _dirs[1] + outfile) ln_string = str(_dirs[0] + outfile + " " + _dirs[1] + outfile)
os.system("sudo ln -s %s" % ln_string) os.system("sudo ln -s %s" % ln_string)
""" TODO check for sites-enabled, create it if it doesnt exist,
then symlink the config """
except Exception as e: except Exception as e:
pass pass
return True return True
@@ -152,7 +155,7 @@ class SystemInstaller:
wsgiport = r["answer"] wsgiport = r["answer"]
nginx_conf_str = """ nginx_conf_str = """
# pyshelf_nginx.conf # pyshelf_nginx.conf
upstream django {server unix://%s/pyshelf_wsgi.sock;} upstream django {server unix:///tmp/pyshelf_wsgi.sock;}
server { server {
listen %s; listen %s;
server_name %s; server_name %s;
@@ -166,7 +169,6 @@ class SystemInstaller:
location / {uwsgi_pass django; include %s/uwsgi_params;} location / {uwsgi_pass django; include %s/uwsgi_params;}
} }
""" % ( """ % (
root,
port, port,
hostname, hostname,
root, root,
@@ -194,11 +196,10 @@ class SystemInstaller:
master=True master=True
pidfile=/tmp/pyShelf.pid pidfile=/tmp/pyShelf.pid
vacuum=True vacuum=True
socket=%s/pyshelf_wsgi.sock socket=/tmp/pyshelf_wsgi.sock
chmod-socket=666 chmod-socket=666
""" % ( """ % (
root, root,
root
) )
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 +224,7 @@ 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"] # config["USER"] = os.environ["USER"]
config["USER"] = 'pyshelf' config["USER"] = "pyshelf"
# Write configuration # Write configuration
Configuration().write_file(config) Configuration().write_file(config)
@@ -300,23 +301,29 @@ 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"] == "PASSWORD": sql_pass = r["answer"] if r["name"] == "PASSWORD":
sql_pass = r["answer"]
# sql_user = config["USER"] # sql_user = config["USER"]
sql_user = "pyshelf" sql_user = "pyshelf"
db_name = "pyshelf" db_name = "pyshelf"
psql_cmd = """ import pudb
CREATE DATABASE %s;
CREATE USER %s WITH PASSWORD \'%s\'; pudb.set_trace()
GRANT ALL PRIVILEGES ON DATABASE %s TO %s; psql_cmd = (
""" % (db_name, sql_user, sql_pass, db_name, sql_user) "CREATE DATABASE %s; CREATE USER %s WITH PASSWORD '%s'; GRANT ALL PRIVILEGES ON DATABASE %s TO %s;"
_sql_file = "create_db.sql" % (db_name, sql_user, sql_pass, db_name, sql_user)
)
_sql_file = "/tmp/create_db.sql"
with open(_sql_file, "w") as sql_file_open: with open(_sql_file, "w") as sql_file_open:
sql_file_open.write(psql_cmd) sql_file_open.write(psql_cmd)
sql_file_open.close() sql_file_open.close()
os.system("sudo -u postgres initdb --locale=en_US.UTF-8 -E UTF8 -D /var/lib/postgres/data") os.system(
"sudo -u postgres initdb --locale=en_US.UTF-8 -E UTF8 -D /var/lib/postgres/data"
)
os.system("sudo systemctl start postgresql") os.system("sudo systemctl start postgresql")
os.system("sudo -u postgres psql -f %s" % _sql_file) os.system("sudo -u postgres psql -f %s" % _sql_file)
# os.system("sudo -u postgres psql -c \'%s\'"%psql_cmd)
messages = messages + [ messages = messages + [
"PostgreSQL installed and started", "PostgreSQL installed and started",
"To enable autostart you must run", "To enable autostart you must run",
@@ -324,7 +331,7 @@ if RequiredServices().db_server_found(req) is False:
"\n", "\n",
"Database cluster initialized at /var/lib/postgres", "Database cluster initialized at /var/lib/postgres",
"pyShelf database and user created", "pyShelf database and user created",
psql_cmd psql_cmd,
] ]
# Post install configurations # Post install configurations
@@ -342,11 +349,19 @@ except Exception as e:
try: try:
copy_config = sysinstall.copy_config() copy_config = sysinstall.copy_config()
if copy_config: if copy_config:
messages = messages + ["pyShelf site config copied to sites-available, and symlinked to sites-enabled"] messages = messages + [
"pyShelf site config copied to sites-available, and symlinked to sites-enabled"
]
except Exception as e: except Exception as e:
messages = messages + ["nginx site config not copied", "A nginx config for your install has been created \"pyshelf_nginx.conf\""] messages = messages + [
"nginx site config not copied",
'A nginx config for your install has been created "pyshelf_nginx.conf"',
]
sysinstall.make_wsgi_config(install_answers) sysinstall.make_wsgi_config(install_answers)
messages = messages + ["You should now import your books by running importBooks", "You can then start the interface with uwsgi --ini uwsgi.ini"] messages = messages + [
"You should now import your books by running importBooks",
"You can then start the interface with uwsgi --ini uwsgi.ini",
]
# Display end screen # Display end screen
sysinstall.log() sysinstall.log()

13
makeCollections vendored Executable file
View File

@@ -0,0 +1,13 @@
#!/usr/bin/python
import pathlib
import sys
from src.backend.lib.storage import Storage
from src.backend.pyShelf_MakeCollections import MakeCollections
PRG_PATH = pathlib.Path.cwd()
LIB_PATH = pathlib.Path.joinpath(PRG_PATH, "src", "backend", "lib")
sys.path.insert(0, PRG_PATH)
print("\n")
MakeCollections(PRG_PATH)

0
pyproject.toml vendored Normal file → Executable file
View File

5
requirements.txt vendored Normal file → Executable file
View File

@@ -12,9 +12,12 @@ pre-commit
isort isort
django django
toml toml
uwsgi :close
q
django-debug-toolbar django-debug-toolbar
psycopg2-binary psycopg2-binary
prompt_toolkit prompt_toolkit
psutil psutil
pyfiglet pyfiglet
psycopg2

0
src/__init__.py Normal file → Executable file
View File

0
src/backend/empty_bookshelf.sql vendored Normal file → Executable file
View File

0
src/backend/lib/display.py Normal file → Executable file
View File

View File

@@ -1,12 +1,7 @@
#!/usr/bin/python #!/usr/bin/python
import sqlite3 import re
import psycopg2 import psycopg2
from psycopg2 import Error
from .config import Config
# db_pointer = Config().catalogue_db
class Storage: class Storage:
@@ -31,7 +26,6 @@ class Storage:
try: try:
self.cursor.execute(_q) self.cursor.execute(_q)
except Exception as e: except Exception as e:
breakpoint()
if e.pgcode == "42501": if e.pgcode == "42501":
_q = """ALTER TABLE public.books OWNER to pyshelf;""" _q = """ALTER TABLE public.books OWNER to pyshelf;"""
self.close() self.close()
@@ -102,3 +96,38 @@ class Storage:
""" """
self.db.close() self.db.close()
return True return True
def make_collections(self):
_title_regx = re.compile(r"^[0-9][0-9]*|-|\ \B")
_q = "SELECT id,file_name FROM books"
self.cursor.execute(_q)
_set = self.cursor.fetchall()
for book in _set:
path = self.config.book_path + "/"
_collections = []
_pathing = book[1].split(path)[1].split("/")
_pathing.pop(0)
_pathing.pop(-1)
for _p in _pathing:
_s = _p.replace("'", "")
_x = re.sub(_title_regx, "", _s)
_s = _x.strip()
breakpoint()
_q_x = """
SELECT id FROM collections where collection='%s' AND book_id_id=%s
""" % (
_s,
book[0],
)
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])
)
except Exception as e:
print(e)
_collections.append(_p)
self.db.commit()
self.close()

View File

@@ -0,0 +1,23 @@
#!/usr/bin/python
import os
import sys
import time
from .lib.config import Config
from .lib.library import Catalogue
from .lib.pyShelf import InitFiles
from .lib.storage import Storage
sys.path.append(os.path.abspath("."))
def MakeCollections(root):
_t1 = time.time()
config = Config(root) # Get configuration settings
# InitFiles(config.file_array) # Initialize file system
_storage = Storage(config)
_storage.make_collections()
_t2 = time.time()
scan_time = round(_t2 - _t1)
print("Collections Made.")
print("Time %s seconds" % scan_time)

View File

@@ -19,7 +19,6 @@ 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() Storage(config).check_ownership()
catalogue = Catalogue(config) # Open the Catalogue catalogue = Catalogue(config) # Open the Catalogue
catalogue.import_books() catalogue.import_books()

View File

@@ -33,8 +33,9 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = "@(9b9jslgg41u1u=mr)-2*-n2x0vef0zsy39*z@sz18&tvow18" SECRET_KEY = "@(9b9jslgg41u1u=mr)-2*-n2x0vef0zsy39*z@sz18&tvow18"
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False DEBUG = TEMPLATE_DEBUG = True
if DEBUG is True:
from pudb.remote import set_trace
ALLOWED_HOSTS = CONFIG.allowed_hosts ALLOWED_HOSTS = CONFIG.allowed_hosts

View File

@@ -27,6 +27,11 @@ urlpatterns = [
path("search/", views.search, name="search"), path("search/", views.search, name="search"),
path("search/<query>", views.search, name="search"), path("search/<query>", views.search, name="search"),
path("search/<query>/<_set>", views.search, name="search"), path("search/<query>/<_set>", views.search, name="search"),
path(
"show_collection/<_collection>/<_colset>",
views.show_collection,
name="show_collection",
),
] ]
if settings.DEBUG: if settings.DEBUG:
import debug_toolbar import debug_toolbar

0
src/interface/migrations/0001_initial.py Normal file → Executable file
View File

0
src/interface/migrations/0002_auto_20200101_0445.py Normal file → Executable file
View File

0
src/interface/migrations/0003_auto_20200101_0447.py Normal file → Executable file
View File

View File

@@ -0,0 +1,37 @@
# Generated by Django 3.0.2 on 2020-02-04 20:22
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("interface", "0003_auto_20200101_0447"),
]
operations = [
migrations.CreateModel(
name="Collections",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("collection", models.CharField(max_length=255)),
(
"book_id",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
to="interface.Books",
),
),
],
options={"db_table": "collections",},
),
]

View File

@@ -30,15 +30,35 @@ class Books(models.Model):
progress = models.IntegerField(null=True) progress = models.IntegerField(null=True)
file_name = models.CharField(max_length=255, null=False) file_name = models.CharField(max_length=255, null=False)
def generic_search(self, query):
try:
results = Books.objects.annotate(
search=SearchVector("title", "file_name", "author"),
).filter(search=query)
except Exception as e:
raise
return results
class Collections(models.Model):
class Meta:
db_table = "collections"
def __str__(self):
return self.collection
collection = models.CharField(max_length=255)
book_id = models.ForeignKey(Books, on_delete=models.PROTECT)
def get_absolute_url(self): def get_absolute_url(self):
"""Returns the url to access a particular instance of MyModelName.""" """Returns the url to access a particular instance of MyModelName."""
return reverse("model-detail-view", args=[str(self.id)]) return reverse("model-detail-view", args=[str(self.id)])
def generic_search(self, query): def generic_search(self, query):
try: try:
results = Books.objects.annotate( results = Books.objects.annotate(search=SearchVector("collection"),).filter(
search=SearchVector("author", "title", "file_name"), search=query
).filter(search=query) )
except Exception as e: except Exception as e:
raise raise
return results return results

Some files were not shown because too many files have changed in this diff Show More