lastest changes
This commit is contained in:
162
soleprint/run.py
162
soleprint/run.py
@@ -11,6 +11,7 @@ Usage:
|
||||
This is for soleprint development only, not for managed rooms (use docker for those).
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
@@ -27,8 +28,18 @@ app = FastAPI(title="Soleprint (dev)", version="0.1.0")
|
||||
|
||||
templates = Jinja2Templates(directory=Path(__file__).parent)
|
||||
|
||||
# Base path for systems
|
||||
SPR_ROOT = Path(__file__).parent.parent
|
||||
# Base path for systems (gen/ directory where this runs from)
|
||||
SPR_ROOT = Path(__file__).parent
|
||||
DATA_DIR = SPR_ROOT / "data"
|
||||
|
||||
|
||||
def load_data(filename: str) -> list[dict]:
|
||||
"""Load data from JSON file in data/ directory."""
|
||||
path = DATA_DIR / filename
|
||||
if path.exists():
|
||||
data = json.loads(path.read_text())
|
||||
return data.get("items", [])
|
||||
return []
|
||||
|
||||
|
||||
def scan_directory(base_path: Path, pattern: str = "*") -> list[dict]:
|
||||
@@ -68,16 +79,59 @@ def health():
|
||||
# === Artery ===
|
||||
|
||||
|
||||
@app.get("/artery")
|
||||
def artery_index():
|
||||
"""List installed veins."""
|
||||
@app.get("/artery", response_class=HTMLResponse)
|
||||
def artery_index(request: Request):
|
||||
"""Artery landing page."""
|
||||
html_path = SPR_ROOT / "artery" / "index.html"
|
||||
if html_path.exists():
|
||||
# Load from data files
|
||||
veins = load_data("veins.json")
|
||||
pulses = load_data("pulses.json")
|
||||
|
||||
# Scan directories for items not in data files
|
||||
shunts = scan_directory(SPR_ROOT / "artery" / "shunts")
|
||||
for s in shunts:
|
||||
s["slug"] = s["name"]
|
||||
s["title"] = s["name"].replace("-", " ").title()
|
||||
s["status"] = "ready"
|
||||
|
||||
depots = scan_directory(SPR_ROOT / "artery" / "depots")
|
||||
for d in depots:
|
||||
d["slug"] = d["name"]
|
||||
d["title"] = d["name"].replace("-", " ").title()
|
||||
d["status"] = "ready"
|
||||
|
||||
rooms = scan_directory(SPR_ROOT / "artery" / "room")
|
||||
for r in rooms:
|
||||
r["slug"] = r["name"]
|
||||
r["title"] = r["name"].replace("-", " ").title()
|
||||
r["status"] = "ready"
|
||||
|
||||
from jinja2 import Template
|
||||
|
||||
template = Template(html_path.read_text())
|
||||
return HTMLResponse(
|
||||
template.render(
|
||||
request=request,
|
||||
veins=veins,
|
||||
rooms=rooms,
|
||||
pulses=pulses,
|
||||
shunts=shunts,
|
||||
depots=depots,
|
||||
plexuses=[], # Placeholder - whatsapp planned
|
||||
soleprint_url="/",
|
||||
pawprint_url="/",
|
||||
)
|
||||
)
|
||||
veins_path = SPR_ROOT / "artery" / "veins"
|
||||
veins = scan_directory(veins_path)
|
||||
return {
|
||||
"system": "artery",
|
||||
"tagline": "Todo lo vital",
|
||||
"veins": veins,
|
||||
}
|
||||
return JSONResponse(
|
||||
{
|
||||
"system": "artery",
|
||||
"tagline": "Todo lo vital",
|
||||
"veins": veins,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@app.get("/artery/{path:path}")
|
||||
@@ -89,16 +143,35 @@ def artery_route(path: str):
|
||||
# === Atlas ===
|
||||
|
||||
|
||||
@app.get("/atlas")
|
||||
def atlas_index():
|
||||
"""List installed templates."""
|
||||
templates_path = SPR_ROOT / "atlas" / "templates"
|
||||
tpls = scan_directory(templates_path)
|
||||
return {
|
||||
"system": "atlas",
|
||||
"tagline": "Documentacion accionable",
|
||||
"templates": tpls,
|
||||
}
|
||||
@app.get("/atlas", response_class=HTMLResponse)
|
||||
def atlas_index(request: Request):
|
||||
"""Atlas landing page."""
|
||||
html_path = SPR_ROOT / "atlas" / "index.html"
|
||||
if html_path.exists():
|
||||
# Load books from data file (includes template info for templated vs original)
|
||||
books = load_data("books.json")
|
||||
templates = load_data("templates.json")
|
||||
depots = load_data("depots.json")
|
||||
|
||||
from jinja2 import Template
|
||||
|
||||
template = Template(html_path.read_text())
|
||||
return HTMLResponse(
|
||||
template.render(
|
||||
request=request,
|
||||
books=books,
|
||||
templates=templates,
|
||||
depots=depots,
|
||||
soleprint_url="/",
|
||||
)
|
||||
)
|
||||
return JSONResponse(
|
||||
{
|
||||
"system": "atlas",
|
||||
"tagline": "Documentacion accionable",
|
||||
"books": [],
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@app.get("/atlas/{path:path}")
|
||||
@@ -110,16 +183,49 @@ def atlas_route(path: str):
|
||||
# === Station ===
|
||||
|
||||
|
||||
@app.get("/station")
|
||||
def station_index():
|
||||
"""List installed tools."""
|
||||
@app.get("/station", response_class=HTMLResponse)
|
||||
def station_index(request: Request):
|
||||
"""Station landing page."""
|
||||
html_path = SPR_ROOT / "station" / "index.html"
|
||||
if html_path.exists():
|
||||
tools = scan_directory(SPR_ROOT / "station" / "tools")
|
||||
for t in tools:
|
||||
t["slug"] = t["name"]
|
||||
t["title"] = t["name"].replace("-", " ").title()
|
||||
t["status"] = "ready"
|
||||
monitors = scan_directory(SPR_ROOT / "station" / "monitors")
|
||||
for m in monitors:
|
||||
m["slug"] = m["name"]
|
||||
m["title"] = m["name"].replace("-", " ").title()
|
||||
m["status"] = "ready"
|
||||
desks = scan_directory(SPR_ROOT / "station" / "desks")
|
||||
for d in desks:
|
||||
d["slug"] = d["name"]
|
||||
d["title"] = d["name"].replace("-", " ").title()
|
||||
d["status"] = "ready"
|
||||
from jinja2 import Template
|
||||
|
||||
template = Template(html_path.read_text())
|
||||
return HTMLResponse(
|
||||
template.render(
|
||||
request=request,
|
||||
tools=tools,
|
||||
monitors=monitors,
|
||||
cabinets=desks,
|
||||
tables=[],
|
||||
soleprint_url="/",
|
||||
pawprint_url="/",
|
||||
)
|
||||
)
|
||||
tools_path = SPR_ROOT / "station" / "tools"
|
||||
tools = scan_directory(tools_path)
|
||||
return {
|
||||
"system": "station",
|
||||
"tagline": "Monitores, Entornos y Herramientas",
|
||||
"tools": tools,
|
||||
}
|
||||
return JSONResponse(
|
||||
{
|
||||
"system": "station",
|
||||
"tagline": "Monitores, Entornos y Herramientas",
|
||||
"tools": tools,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@app.get("/station/{path:path}")
|
||||
|
||||
Reference in New Issue
Block a user