-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprometheus.py
More file actions
113 lines (80 loc) · 3.05 KB
/
Copy pathprometheus.py
File metadata and controls
113 lines (80 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env python3
"""
Prometheus — Unified Platform Entry Point (thin shim)
Delegates to the ``prometheus_cli`` package. Preserves the original CLI
interface so existing scripts and documentation remain valid.
"""
from __future__ import annotations
import os
import sys
_REPO_ROOT = os.path.dirname(os.path.abspath(__file__))
if _REPO_ROOT not in sys.path:
sys.path.insert(0, _REPO_ROOT)
def _prepend_runtime_paths() -> None:
default_windows_paths = [
r"C:\msys64\ucrt64\bin",
]
configured = os.environ.get("PROMETHEUS_EXTRA_PATHS", "")
configured_paths = [p.strip() for p in configured.split(os.pathsep) if p.strip()]
candidates = configured_paths + default_windows_paths
current_parts = os.environ.get("PATH", "").split(os.pathsep)
normalized = {os.path.normcase(os.path.normpath(p)) for p in current_parts if p}
to_prepend: list[str] = []
for path in candidates:
if not os.path.isdir(path):
continue
key = os.path.normcase(os.path.normpath(path))
if key in normalized:
continue
to_prepend.append(path)
normalized.add(key)
if to_prepend:
os.environ["PATH"] = os.pathsep.join(to_prepend + current_parts)
_prepend_runtime_paths()
from core.bootstrap import boot
from core.config import config
from core.database import SessionLocal, create_engine, sessionmaker
from prometheus_cli import commands as _commands
from prometheus_cli.main import main
def _run_plugin(container, db) -> None:
_commands._run_plugin(container, db)
def _run_agent(container, db) -> None:
_commands._run_agent(container, db)
def _create_device(container, db) -> None:
_commands._create_device(container, db)
def _store_memory(container, db) -> None:
_commands._store_memory(container, db)
def _query_knowledge_graph(container, db) -> None:
_commands._query_knowledge_graph(container, db)
def _build_twin(container, db) -> None:
_commands._build_twin(container, db)
def _generate_report(container, db) -> dict:
return _commands._generate_report(container, db)
def run_demo(db_path: str | None = None) -> dict:
container = boot(_commands._heartbeat_job)
if db_path:
engine = create_engine(
f"sqlite:///{db_path}",
connect_args={"check_same_thread": False},
)
SessionFactory = sessionmaker(autocommit=False, autoflush=False, bind=engine)
else:
engine = None
SessionFactory = SessionLocal
try:
with SessionFactory() as db:
_run_plugin(container, db)
_run_agent(container, db)
_create_device(container, db)
_store_memory(container, db)
_query_knowledge_graph(container, db)
_build_twin(container, db)
report = _generate_report(container, db)
report["db_path"] = db_path or str(config.db_path)
finally:
container.get("scheduler").stop()
if engine is not None:
engine.dispose()
return report
if __name__ == "__main__":
raise SystemExit(main())