diff --git a/Pipfile b/Pipfile index e4b8371..fe86960 100644 --- a/Pipfile +++ b/Pipfile @@ -30,6 +30,7 @@ Pillow = "*" Django = "*" uWSGI = "*" pudb = "*" +loguru = "*" [requires] python_version = "3.8" diff --git a/pyShelf.py b/pyShelf.py index e9daae7..f6f61e2 100644 --- a/pyShelf.py +++ b/pyShelf.py @@ -1,14 +1,29 @@ #!/usr/bin/env python3 import asyncio import websockets +import sys from pathlib import Path +from loguru import logger 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() 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: if message == "import": print("message from Con1 >> {}".format(message)) @@ -22,6 +37,10 @@ async def echo(websocket, path): elif message == "importBooks": print("<<[{} cmd rcvd]\n Starting import".format(message)) tx = "Starting Import . . ." + await websocket.send(tx) + await runImport() + tx = "complete" + await websocket.send(tx) @@ -30,7 +49,7 @@ def pong(message): 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_forever() diff --git a/requirements.txt b/requirements.txt index c14ff50..eaa8f3e 100755 --- a/requirements.txt +++ b/requirements.txt @@ -21,3 +21,4 @@ mobi-python uwsgi jsonpickle django-widget-tweaks +loguru diff --git a/src/backend/lib/config.py b/src/backend/lib/config.py index dfa3636..69acc6a 100755 --- a/src/backend/lib/config.py +++ b/src/backend/lib/config.py @@ -1,7 +1,6 @@ import json -import os import pathlib -import sys +from loguru import logger class Config: @@ -17,6 +16,8 @@ class Config: """ _cp = pathlib.Path.joinpath(root, self._fp) _data = self.open_file(_cp) + self.root = root + self.logger = self.get_logger() self.book_path = _data["BOOKPATH"] self.TITLE = _data["TITLE"] self.VERSION = _data["VERSION"] @@ -30,7 +31,6 @@ class Config: self.file_array = [ self.book_shelf, ] - self.root = root self.auto_scan = True self.allowed_hosts = _data["ALLOWED_HOSTS"] @@ -38,7 +38,13 @@ class Config: self.db_pass = _data["PASSWORD"] 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 """ @@ -48,4 +54,3 @@ class Config: def django_secret(self, _data): pass - diff --git a/src/backend/lib/library.py b/src/backend/lib/library.py index 2f3c8d5..353809f 100755 --- a/src/backend/lib/library.py +++ b/src/backend/lib/library.py @@ -13,7 +13,6 @@ from .api_hooks import DuckDuckGo from .config import Config from .storage import Storage -# config = Config() class Catalogue: @@ -51,6 +50,7 @@ class Catalogue: self.file_list.append(self.scan_folder(_path)) else: self.file_list.append(_path) + self.config.logger.info(_path) print(_path+"\n") def filter_books(self): @@ -73,6 +73,7 @@ class Catalogue: """ def process_by_filetype(self, book): + print(str(book), end='\r', flush=True) if book.endswith(".epub"): epub = self.process_epub(book) @@ -282,7 +283,6 @@ class Catalogue: with open(fsocket, 'w') as _socket: _socket.write(book[0]) _socket.close() - breakpoint() db.insert_book(book) inserted = db.commit() if inserted is not True: diff --git a/src/frontend/settings.py b/src/frontend/settings.py index 6dfdac1..0cb56e8 100755 --- a/src/frontend/settings.py +++ b/src/frontend/settings.py @@ -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! SECRET_KEY = CONFIG.SECRET # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = TEMPLATE_DEBUG = True +DEBUG = TEMPLATE_DEBUG = False if DEBUG is True: from pudb.remote import set_trace ALLOWED_HOSTS = CONFIG.allowed_hosts diff --git a/src/interface/static/css/main.css b/src/interface/static/css/main.css index 0e2d542..8e33bba 100644 --- a/src/interface/static/css/main.css +++ b/src/interface/static/css/main.css @@ -10758,4 +10758,14 @@ a.nav_link { .collection { 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; } \ No newline at end of file diff --git a/src/interface/static/css/main.scss b/src/interface/static/css/main.scss index d13398c..8bc025d 100755 --- a/src/interface/static/css/main.scss +++ b/src/interface/static/css/main.scss @@ -621,3 +621,11 @@ a.nav_link { .collection{ 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; +} diff --git a/src/interface/static/js/pyshelf_ux.js b/src/interface/static/js/pyshelf_ux.js index 3a85cbe..dd714f1 100755 --- a/src/interface/static/js/pyshelf_ux.js +++ b/src/interface/static/js/pyshelf_ux.js @@ -173,6 +173,17 @@ $(document).ready(function(){ $(document).on('click', '.logout-btn', function(){window.location.href = '/logout'}); $(document).on('click', '.import-btn', async function(){ let connection = await ImportBooks(server); + popover.html('
'); + let psout = $('#psout') + psout.append('
Importing Books
') + psout.append('
') + let i_container = $('.import_progress') + i_container.append('
'); + $('.progressbar').progressbar({ + classes: {"ui-progressbar": "highlight"}, + value: false + }); + $(".progressbar").append("
") }); $('#coll_button').on('click', function(){ var isopen = $('#pop_over_0').dialog("isOpen"); @@ -300,6 +311,11 @@ async function PyshelfServer(address){ } function sock_rx(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) } } function sock_tx(connection, msg) {