mirror of
https://github.com/th3r00t/pyShelf.git
synced 2026-04-28 01:59:35 -04:00
Added method to compile sass files pre run.
This commit is contained in:
10
pyShelf.py
vendored
10
pyShelf.py
vendored
@@ -4,11 +4,10 @@ import asyncio
|
|||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
from src.backend.lib.config import Config
|
from src.backend.lib.config import Config
|
||||||
from src.backend.pyShelf_MakeCollections import MakeCollections
|
from src.backend.pyShelf_MakeCollections import MakeCollections
|
||||||
from src.backend.pyShelf_ScanLibrary import execute_scan
|
from src.backend.pyShelf_ScanLibrary import execute_scan
|
||||||
from src.frontend.lib.frontend import FrontendServer
|
from src.frontend.lib.FastAPIServer import FastAPIServer
|
||||||
# import websockets
|
# import websockets
|
||||||
|
|
||||||
|
|
||||||
@@ -17,7 +16,8 @@ config = Config(root)
|
|||||||
PRG_PATH = Path.cwd().__str__()
|
PRG_PATH = Path.cwd().__str__()
|
||||||
sys.path.insert(0, PRG_PATH)
|
sys.path.insert(0, PRG_PATH)
|
||||||
|
|
||||||
def RunImport():
|
|
||||||
|
def run_import():
|
||||||
"""Begin live import of books."""
|
"""Begin live import of books."""
|
||||||
config.logger.info("Begining book import.")
|
config.logger.info("Begining book import.")
|
||||||
execute_scan(PRG_PATH, config=config)
|
execute_scan(PRG_PATH, config=config)
|
||||||
@@ -28,9 +28,9 @@ def RunImport():
|
|||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
"""Program entrypoint."""
|
"""Program entrypoint."""
|
||||||
_import_thread = Thread(target=RunImport)
|
_import_thread = Thread(target=run_import)
|
||||||
_import_thread.start()
|
_import_thread.start()
|
||||||
fe_server = FrontendServer(config)
|
fe_server = FastAPIServer(config)
|
||||||
_task = await asyncio.create_task(fe_server.run())
|
_task = await asyncio.create_task(fe_server.run())
|
||||||
return [_task, _import_thread]
|
return [_task, _import_thread]
|
||||||
|
|
||||||
|
|||||||
58
src/frontend/lib/frontend.py
vendored
58
src/frontend/lib/frontend.py
vendored
@@ -1,58 +0,0 @@
|
|||||||
"""pyShelf's main frontend library."""
|
|
||||||
import uvicorn
|
|
||||||
from fastapi import FastAPI, Request
|
|
||||||
from fastapi.responses import HTMLResponse
|
|
||||||
from fastapi.routing import APIRoute
|
|
||||||
from fastapi.staticfiles import StaticFiles
|
|
||||||
from fastapi.templating import Jinja2Templates
|
|
||||||
|
|
||||||
app = FastAPI()
|
|
||||||
templates = Jinja2Templates(directory="src/frontend/templates")
|
|
||||||
class FrontendServer():
|
|
||||||
|
|
||||||
def __init__(self, config):
|
|
||||||
self.config = config
|
|
||||||
app.mount("/static", StaticFiles(directory="src/frontend/static"), name="static")
|
|
||||||
|
|
||||||
|
|
||||||
def use_route_names_as_operation_ids(self, app: FastAPI) -> None:
|
|
||||||
"""Use route name as operation id."""
|
|
||||||
for route in app.routes:
|
|
||||||
if isinstance(route, APIRoute):
|
|
||||||
route.operation_id = route.name
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/", response_class=HTMLResponse)
|
|
||||||
async def index(request: Request):
|
|
||||||
"""Home page responder."""
|
|
||||||
return templates.TemplateResponse(
|
|
||||||
"index.html",
|
|
||||||
{"request": request})
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/users/me")
|
|
||||||
async def about_me():
|
|
||||||
"""About me page responder."""
|
|
||||||
return {"user_id": "CurrentUser"}
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/users/{user_id}")
|
|
||||||
async def about_user(user_id: int):
|
|
||||||
"""About user page responder."""
|
|
||||||
return {"user_id": user_id}
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/dev/test/echo/{_test_item_}")
|
|
||||||
async def echo_test(_test_item_):
|
|
||||||
"""Test echo responder function."""
|
|
||||||
return {"Test Object": _test_item_}
|
|
||||||
|
|
||||||
|
|
||||||
async def run(self):
|
|
||||||
"""Front end server entrypoint."""
|
|
||||||
self.config.logger.info("Starting FastAPI server.")
|
|
||||||
self.use_route_names_as_operation_ids(app)
|
|
||||||
self.fe_config = uvicorn.Config(app, port=8080,
|
|
||||||
log_level="info", reload=True)
|
|
||||||
self.fe_server = uvicorn.Server(self.fe_config)
|
|
||||||
await self.fe_server.serve()
|
|
||||||
Reference in New Issue
Block a user