Import Books now working in ui, Working on logging.

This commit is contained in:
Raelon Masters
2020-08-15 01:09:28 -04:00
parent 3f99c15038
commit 5429b7ee00
9 changed files with 70 additions and 10 deletions

View File

@@ -30,6 +30,7 @@ Pillow = "*"
Django = "*" Django = "*"
uWSGI = "*" uWSGI = "*"
pudb = "*" pudb = "*"
loguru = "*"
[requires] [requires]
python_version = "3.8" python_version = "3.8"

View File

@@ -1,14 +1,29 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import asyncio import asyncio
import websockets import websockets
import sys
from pathlib import Path from pathlib import Path
from loguru import logger
from src.backend.lib.config import Config from src.backend.lib.config import Config
from src.backend.pyShelf_ScanLibrary import execute_scan
from src.backend.pyShelf_MakeCollections import MakeCollections
root = Path.cwd() root = Path.cwd()
config = Config(root) config = Config(root)
PRG_PATH = Path.cwd().__str__()
sys.path.insert(0, PRG_PATH)
tx = None
async def echo(websocket, path): async def runImport():
execute_scan(PRG_PATH)
MakeCollections(PRG_PATH)
return "Import Complete"
async def socketio(websocket, path):
async for message in websocket: async for message in websocket:
if message == "import": if message == "import":
print("message from Con1 >> {}".format(message)) print("message from Con1 >> {}".format(message))
@@ -22,6 +37,10 @@ async def echo(websocket, path):
elif message == "importBooks": elif message == "importBooks":
print("<<[{} cmd rcvd]\n Starting import".format(message)) print("<<[{} cmd rcvd]\n Starting import".format(message))
tx = "Starting Import . . ." tx = "Starting Import . . ."
await websocket.send(tx)
await runImport()
tx = "complete"
await websocket.send(tx) await websocket.send(tx)
@@ -30,7 +49,7 @@ def pong(message):
return "pong" return "pong"
start_server = websockets.serve(echo, "127.0.0.1", 1337) start_server = websockets.serve(socketio, "127.0.0.1", 1337)
asyncio.get_event_loop().run_until_complete(start_server) asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever() asyncio.get_event_loop().run_forever()

View File

@@ -21,3 +21,4 @@ mobi-python
uwsgi uwsgi
jsonpickle jsonpickle
django-widget-tweaks django-widget-tweaks
loguru

View File

@@ -1,7 +1,6 @@
import json import json
import os
import pathlib import pathlib
import sys from loguru import logger
class Config: class Config:
@@ -17,6 +16,8 @@ class Config:
""" """
_cp = pathlib.Path.joinpath(root, self._fp) _cp = pathlib.Path.joinpath(root, self._fp)
_data = self.open_file(_cp) _data = self.open_file(_cp)
self.root = root
self.logger = self.get_logger()
self.book_path = _data["BOOKPATH"] self.book_path = _data["BOOKPATH"]
self.TITLE = _data["TITLE"] self.TITLE = _data["TITLE"]
self.VERSION = _data["VERSION"] self.VERSION = _data["VERSION"]
@@ -30,7 +31,6 @@ class Config:
self.file_array = [ self.file_array = [
self.book_shelf, self.book_shelf,
] ]
self.root = root
self.auto_scan = True self.auto_scan = True
self.allowed_hosts = _data["ALLOWED_HOSTS"] self.allowed_hosts = _data["ALLOWED_HOSTS"]
@@ -38,7 +38,13 @@ class Config:
self.db_pass = _data["PASSWORD"] self.db_pass = _data["PASSWORD"]
self.SECRET = _data["SECRET"] self.SECRET = _data["SECRET"]
def open_file(self, _cp): def get_logger(self):
_logger = logger
_logger.add(pathlib.PurePath(self.root, 'data','pyShelf_{time}.log'), rotation="10 MB", loop=None)
return _logger
@staticmethod
def open_file(_cp):
""" """
Opens config.json and reads in configuration options Opens config.json and reads in configuration options
""" """
@@ -48,4 +54,3 @@ class Config:
def django_secret(self, _data): def django_secret(self, _data):
pass pass

View File

@@ -13,7 +13,6 @@ from .api_hooks import DuckDuckGo
from .config import Config from .config import Config
from .storage import Storage from .storage import Storage
# config = Config()
class Catalogue: class Catalogue:
@@ -51,6 +50,7 @@ class Catalogue:
self.file_list.append(self.scan_folder(_path)) self.file_list.append(self.scan_folder(_path))
else: else:
self.file_list.append(_path) self.file_list.append(_path)
self.config.logger.info(_path)
print(_path+"\n") print(_path+"\n")
def filter_books(self): def filter_books(self):
@@ -73,6 +73,7 @@ class Catalogue:
""" """
def process_by_filetype(self, book): def process_by_filetype(self, book):
print(str(book), end='\r', flush=True) print(str(book), end='\r', flush=True)
if book.endswith(".epub"): if book.endswith(".epub"):
epub = self.process_epub(book) epub = self.process_epub(book)
@@ -282,7 +283,6 @@ class Catalogue:
with open(fsocket, 'w') as _socket: with open(fsocket, 'w') as _socket:
_socket.write(book[0]) _socket.write(book[0])
_socket.close() _socket.close()
breakpoint()
db.insert_book(book) db.insert_book(book)
inserted = db.commit() inserted = db.commit()
if inserted is not True: if inserted is not True:

View File

@@ -32,7 +32,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# SECURITY WARNING: keep the secret key used in production secret! # SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = CONFIG.SECRET SECRET_KEY = CONFIG.SECRET
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = TEMPLATE_DEBUG = True DEBUG = TEMPLATE_DEBUG = False
if DEBUG is True: if DEBUG is True:
from pudb.remote import set_trace from pudb.remote import set_trace
ALLOWED_HOSTS = CONFIG.allowed_hosts ALLOWED_HOSTS = CONFIG.allowed_hosts

View File

@@ -10758,4 +10758,14 @@ a.nav_link {
.collection { .collection {
cursor: pointer; cursor: pointer;
}
.progressbar {
ui-progressbar: "ui-corner-all";
ui-progressbar-complete: "ui-corner-right";
ui-progressbar-value: "ui-corner-left";
}
.progress_container {
min-width: 300px !important;
} }

View File

@@ -621,3 +621,11 @@ a.nav_link {
.collection{ .collection{
cursor: pointer; cursor: pointer;
} }
.progressbar{
ui-progressbar: "ui-corner-all";
ui-progressbar-complete: "ui-corner-right";
ui-progressbar-value: "ui-corner-left";
}
.progress_container{
min-width: 300px !important;
}

View File

@@ -173,6 +173,17 @@ $(document).ready(function(){
$(document).on('click', '.logout-btn', function(){window.location.href = '/logout'}); $(document).on('click', '.logout-btn', function(){window.location.href = '/logout'});
$(document).on('click', '.import-btn', async function(){ $(document).on('click', '.import-btn', async function(){
let connection = await ImportBooks(server); let connection = await ImportBooks(server);
popover.html('<div id="psout" class="container">');
let psout = $('#psout')
psout.append('<div class="rox"><div class="col import_status">Importing Books</div></div>')
psout.append('<div class="row import_progress"></div>')
let i_container = $('.import_progress')
i_container.append('<div class="col progress_container"><div class="progressbar"></div>');
$('.progressbar').progressbar({
classes: {"ui-progressbar": "highlight"},
value: false
});
$(".progressbar").append("</div>")
}); });
$('#coll_button').on('click', function(){ $('#coll_button').on('click', function(){
var isopen = $('#pop_over_0').dialog("isOpen"); var isopen = $('#pop_over_0').dialog("isOpen");
@@ -300,6 +311,11 @@ async function PyshelfServer(address){
} }
function sock_rx(rcvd) { function sock_rx(rcvd) {
if (rcvd.data == 'pong') { pong(rcvd) } if (rcvd.data == 'pong') { pong(rcvd) }
else if (rcvd.data == 'complete') {
$('.progressbar').progressbar("option", "value", "True");
$('.import_status').html('Import Complete')
console.log(rcvd.data)
}
else { console.log("<<[rx] :"+rcvd.data) } else { console.log("<<[rx] :"+rcvd.data) }
} }
function sock_tx(connection, msg) { function sock_tx(connection, msg) {