#!/usr/bin/env python3 """ List available scenarios and open one in the browser. Usage: python tests/detect/manual/list_scenarios.py # list all python tests/detect/manual/list_scenarios.py --open 1 # open scenario #1 python tests/detect/manual/list_scenarios.py --open chelsea_edges_default # by label Prerequisites: kubectl port-forward svc/postgres 5432:5432 & """ from __future__ import annotations import argparse import logging import os import sys import webbrowser parser = argparse.ArgumentParser(description="List and open scenarios") parser.add_argument("--open", type=str, default=None, help="Open scenario by number (1-based) or label") parser.add_argument("--db-url", default=os.environ.get("DATABASE_URL", "postgresql://mpr:mpr@localhost:5432/mpr")) parser.add_argument("--base-url", default="http://mpr.local.ar/detection/") args = parser.parse_args() os.environ["DATABASE_URL"] = args.db_url sys.path.insert(0, ".") logging.basicConfig(level=logging.INFO, format="%(levelname)-7s %(name)s — %(message)s") logger = logging.getLogger(__name__) def main(): from core.db import list_scenarios from core.db.connection import get_session with get_session() as session: scenarios = list_scenarios(session) if not scenarios: logger.info("No scenarios found. Create one with:") logger.info(" python tests/detect/manual/seed_scenario.py") return logger.info("") logger.info("%3s %-35s %-12s %6s %s", "#", "Label", "Timeline", "Stages", "Created") logger.info("─" * 80) for i, s in enumerate(scenarios, 1): created = str(s.created_at)[:19] if s.created_at else "—" tid_short = str(s.timeline_id)[:8] stage_count = len(s.stage_outputs or {}) logger.info("%3d %-35s %-12s %6d %s", i, s.scenario_label, tid_short, stage_count, created) logger.info("") if args.open: target = None try: idx = int(args.open) - 1 if 0 <= idx < len(scenarios): target = scenarios[idx] except ValueError: for s in scenarios: if s.scenario_label == args.open: target = s break if not target: logger.error("Scenario not found: %s", args.open) return url = f"{args.base_url}?job={target.timeline_id}#/editor/detect_edges" logger.info("Opening: %s", url) webbrowser.open(url) else: logger.info("To open a scenario:") logger.info(" python tests/detect/manual/list_scenarios.py --open 1") logger.info(" python tests/detect/manual/list_scenarios.py --open chelsea_edges_default") if __name__ == "__main__": main()