Files
Medios-Macina/cmdnat/status.py
T

71 lines
2.4 KiB
Python
Raw Normal View History

2026-01-11 00:39:17 -08:00
from __future__ import annotations
import shutil
2026-01-19 03:14:30 -08:00
from typing import Any, Dict, List
2026-01-11 00:39:17 -08:00
2026-02-11 19:06:38 -08:00
from SYS.cmdlet_spec import Cmdlet
2026-01-11 00:39:17 -08:00
from SYS import pipeline as ctx
2026-01-18 10:50:42 -08:00
from SYS.result_table import Table
2026-05-14 20:47:20 -07:00
from SYS.logger import set_debug
2026-03-25 22:39:30 -07:00
from cmdnat._status_shared import (
add_startup_check as _add_startup_check,
collect_plugin_startup_checks as _collect_plugin_startup_checks,
2026-03-25 22:39:30 -07:00
)
2026-01-11 00:39:17 -08:00
CMDLET = Cmdlet(
name=".status",
2026-04-26 16:49:23 -07:00
summary="Check and display service/plugin status",
2026-01-11 00:39:17 -08:00
usage=".status",
arg=[],
)
def _run(result: Any, args: List[str], config: Dict[str, Any]) -> int:
2026-01-18 10:50:42 -08:00
startup_table = Table(
2026-01-11 00:39:17 -08:00
"*********<IGNITIO>*********<NOUSEMPEH>*********<RUGRAPOG>*********<OMEGHAU>*********"
)
2026-01-18 10:50:42 -08:00
startup_table._interactive(True)._perseverance(True)
2026-01-11 00:39:17 -08:00
startup_table.set_value_case("upper")
debug_enabled = bool(config.get("debug", False))
2026-01-18 10:50:42 -08:00
try:
# Ensure global debug state follows config so HTTPClient and other helpers
# emit debug-level information during the status check.
set_debug(debug_enabled)
except Exception:
pass
2026-01-11 00:39:17 -08:00
_add_startup_check(startup_table, "ENABLED" if debug_enabled else "DISABLED", "DEBUGGING")
try:
# MPV check
try:
2026-04-30 18:56:22 -07:00
from plugins.mpv.mpv_ipc import MPV
2026-01-11 00:39:17 -08:00
MPV()
mpv_path = shutil.which("mpv")
_add_startup_check(startup_table, "ENABLED", "MPV", detail=mpv_path or "Available")
except Exception as exc:
_add_startup_check(startup_table, "DISABLED", "MPV", detail=str(exc))
for check in _collect_plugin_startup_checks(config):
_add_startup_check(
startup_table,
str(check.get("status") or "UNKNOWN"),
str(check.get("name") or "Plugin"),
provider=str(check.get("plugin") or ""),
2026-05-14 20:47:20 -07:00
instance=str(check.get("instance") or ""),
files=check.get("files"),
detail=str(check.get("detail") or ""),
)
2026-01-11 00:39:17 -08:00
except Exception as exc:
2026-05-14 20:47:20 -07:00
_add_startup_check(startup_table, "ERROR", "STATUS", detail=str(exc))
2026-01-11 00:39:17 -08:00
if startup_table.rows:
# Mark as rendered to prevent CLI.py from auto-printing it to stdout
# (avoiding duplication in TUI logs, while keeping it in TUI Results)
setattr(startup_table, "_rendered_by_cmdlet", True)
ctx.set_current_stage_table(startup_table)
return 0
CMDLET.exec = _run