39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
Plugin-Adapter für den Trainingsplan- und Rezept-Editor.
|
|
|
|
Das Original ist eine Flask-Anwendung (app.py) und bleibt vollständig
|
|
unverändert. Hier wird sie lediglich
|
|
|
|
* auf ihren eigenen Datenordner data/trainingsplan/ gezeigt und
|
|
* als WSGI-App in die ASGI-Suite eingehängt.
|
|
|
|
Das Tool läuft dadurch weiterhin auch allein:
|
|
cd plugins/trainingsplan && python app.py
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
|
|
from a2wsgi import WSGIMiddleware
|
|
|
|
from core.loader import load_module
|
|
|
|
|
|
def create_app(ctx):
|
|
# app.py liest DATA_DIR beim Import und legt dort die Phasen an.
|
|
previous = os.environ.get("DATA_DIR")
|
|
os.environ["DATA_DIR"] = str(ctx.data_dir)
|
|
try:
|
|
module = load_module(ctx.path("app.py"), f"btp_{ctx.id}_app")
|
|
finally:
|
|
if previous is None:
|
|
os.environ.pop("DATA_DIR", None)
|
|
else:
|
|
os.environ["DATA_DIR"] = previous
|
|
|
|
# Flask erzeugt seine URLs anhand von SCRIPT_NAME; a2wsgi übernimmt dafür
|
|
# den root_path des Mounts. Damit funktionieren alle Routen unter
|
|
# /plugins/trainingsplan genauso wie vorher unter /.
|
|
return WSGIMiddleware(module.app)
|