mirror of
https://github.com/th3r00t/pyShelf.git
synced 2026-04-28 01:59:35 -04:00
On demand import functionality, held together with ductape and bubblegum.
This commit is contained in:
@@ -19,7 +19,8 @@ class Config:
|
||||
self._fp = "config.json"
|
||||
self._cp = pathlib.Path.joinpath(root, self._fp)
|
||||
self._data = self.open_file()
|
||||
self.logger = self.get_logger()
|
||||
try: self.logger
|
||||
except AttributeError: self.logger = self.get_logger()
|
||||
self.book_path = self._data["BOOKPATH"]
|
||||
self.TITLE = self._data["TITLE"]
|
||||
self.VERSION = self._data["VERSION"]
|
||||
@@ -30,11 +31,8 @@ class Config:
|
||||
self.password = self._data["PASSWORD"]
|
||||
self.db_host = self._data["DB_HOST"]
|
||||
self.db_port = self._data["DB_PORT"]
|
||||
self.file_array = [
|
||||
self.book_shelf,
|
||||
]
|
||||
self.file_array = [self.book_shelf]
|
||||
self.auto_scan = True
|
||||
|
||||
self.allowed_hosts = self._data["ALLOWED_HOSTS"]
|
||||
self.db_user = self._data["USER"]
|
||||
self.db_pass = self._data["PASSWORD"]
|
||||
@@ -42,8 +40,8 @@ class Config:
|
||||
|
||||
def get_logger(self):
|
||||
_logger = logger
|
||||
_logger.add(pathlib.PurePath(self.root, 'data','pyShelf_{time}.log'),
|
||||
rotation="10 MB", enqueue=True, colorize=True)
|
||||
_logger.add(pathlib.PurePath(self.root, 'data','{time}.log'),
|
||||
rotation="2 MB", enqueue=True, colorize=True)
|
||||
return _logger
|
||||
|
||||
def open_file(self):
|
||||
|
||||
@@ -36,15 +36,22 @@ class Server:
|
||||
:TODO: Document this
|
||||
"""
|
||||
|
||||
async def __init__(self, root):
|
||||
def __init__(self, root):
|
||||
self.root = root
|
||||
self.host = ("127.0.0.1", 1337)
|
||||
self.config = Config(self.root)
|
||||
self.instance = None
|
||||
self.serve = await websockets.serve(socketio, "127.0.0.1", 1337)
|
||||
self.loop = None
|
||||
self.serve = None
|
||||
|
||||
async def __aexit__(self, *args, **kwargs):
|
||||
await self.serve.__aexit__(*args, **kwargs)
|
||||
|
||||
async def initialize_server(self):
|
||||
self.config.logger.info("INITIALIZE")
|
||||
self.serve = await websockets.serve(self.socketio, self.host[0], self.host[1])
|
||||
await asyncio.sleep(.01)
|
||||
self.config.logger.info("Server Initialization Complete")
|
||||
|
||||
async def runImport(self):
|
||||
_start_time = time.time()
|
||||
InitFiles(self.config.file_array)
|
||||
@@ -55,21 +62,29 @@ class Server:
|
||||
_total_time = round(time.time() - _start_time)
|
||||
|
||||
async def socketio(self, websocket, path):
|
||||
self.config.logger.info("Listener Starting")
|
||||
async for message in websocket:
|
||||
if message == "ping":
|
||||
config.logger.info("<< Ping")
|
||||
self.config.logger.info("<< Ping")
|
||||
tx = self.pong()
|
||||
elif message == "importBooks":
|
||||
config.logger.info("Starting Import")
|
||||
self.config.logger.info("Starting Import")
|
||||
tx = "Starting Import . . ."
|
||||
await websocket.send(tx)
|
||||
await runImport()
|
||||
await asyncio.sleep(0.01)
|
||||
await self.runImport()
|
||||
await asyncio.sleep(0.01)
|
||||
tx = "complete"
|
||||
else:
|
||||
self.config.logger.info("Unhandled Message Rcvd :: {}".format(message))
|
||||
await websocket.send(tx)
|
||||
|
||||
def pong(self):
|
||||
self.config.logger.info(">> Pong")
|
||||
return "pong"
|
||||
|
||||
def start(self):
|
||||
asyncio.get_event_loop().run_until_complete(self.serve)
|
||||
async def start(self):
|
||||
self.loop = asyncio.get_running_loop()
|
||||
self.loop.set_debug(True)
|
||||
await websockets.serve(self.socketio, self.host[0], self.host[1])
|
||||
await asyncio.sleep(1)
|
||||
|
||||
Reference in New Issue
Block a user