refactor: update documentation server implementation and improve semester class logic

This commit is contained in:
2026-02-10 14:59:34 +01:00
parent 2e5cda6689
commit 29824e8c04
5 changed files with 79 additions and 59 deletions

View File

@@ -1,8 +1,7 @@
import logging
import os
from wsgiref.simple_server import WSGIRequestHandler
from flask import Flask, send_from_directory
import subprocess
import sys
from src import LOG_DIR
@@ -20,29 +19,34 @@ logger = logging.getLogger(__name__) # inherits the same file handler
docport = 8000
class QuietHandler(WSGIRequestHandler):
# suppress “GET /…” access log
def log_request(self, code="-", size="-"):
logger.info("Request: {} {}".format(self.requestline, code))
pass
# suppress all other messages (errors, etc.)
def log_message(self, fmt, *args):
logger.error("Error: {}, Args: {}".format(fmt, args))
pass
def website() -> object:
app = Flask(__name__, static_folder=os.path.join(os.getcwd(), "docs", "public"))
# Serve the main index.html at root
@app.route("/")
def index():
return send_from_directory(app.static_folder, "index.html")
# Serve all other static files
@app.route("/<path:path>")
def serve_static(path):
return send_from_directory(app.static_folder, path)
return app
def start_documentation_server():
"""
Start the Zensical documentation server as a subprocess.
Returns:
subprocess.Popen: The subprocess object, or None if startup failed.
"""
try:
# Prepare subprocess arguments
creationflags = 0
if sys.platform == "win32":
# Hide console window on Windows
creationflags = subprocess.CREATE_NO_WINDOW
# Start subprocess with all output suppressed
process = subprocess.Popen(
["uv", "run", "zensical", "serve"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
stdin=subprocess.DEVNULL,
creationflags=creationflags,
cwd=os.getcwd(),
)
logger.info(f"Documentation server started with PID {process.pid}")
return process
except Exception as e:
logger.error(f"Failed to start documentation server: {e}")
return None