Files
2026-05-27 12:15:11 +02:00

52 lines
1.5 KiB
Python

from pathlib import Path
from .config import CATALOG_FILE
def load_apps():
apps = []
current = {}
path = Path(CATALOG_FILE)
if not path.exists():
return apps
for raw_line in path.read_text(encoding="utf-8").splitlines():
line = raw_line.strip()
if line.startswith("- id:"):
if current:
apps.append(current)
current = {"id": line.split(":", 1)[1].strip()}
elif ":" in line and current:
key, value = line.split(":", 1)
current[key.strip()] = value.strip().strip('"')
if current:
apps.append(current)
return apps
def save_apps(apps):
lines = ["apps:"]
for item in apps:
app_id = item.get("id", "")
lines.append("")
lines.append(f" - id: {app_id}")
lines.append(f" name: {item.get('name', app_id)}")
lines.append(f" language: {item.get('language', 'python')}")
lines.append(f" version: {item.get('version', '1.0.0')}")
lines.append(f" base_path: /apps/{app_id}")
lines.append(f" docs: /apps/{app_id}/docs")
lines.append(f" health: /apps/{app_id}/health")
lines.append(f" status: {item.get('status', 'deployed')}")
if item.get("memory"):
lines.append(f" memory: {item.get('memory')}")
if item.get("cpus"):
lines.append(f" cpus: \"{item.get('cpus')}\"")
Path(CATALOG_FILE).write_text("\n".join(lines) + "\n", encoding="utf-8")