removed TUI and others
This commit is contained in:
+120
-37
@@ -16,7 +16,7 @@ def add_startup_check(
|
||||
name: str,
|
||||
*,
|
||||
provider: str = "",
|
||||
store: str = "",
|
||||
instance: str = "",
|
||||
files: int | str | None = None,
|
||||
detail: str = "",
|
||||
) -> None:
|
||||
@@ -24,11 +24,82 @@ def add_startup_check(
|
||||
row.add_column("STATUS", upper_text(status))
|
||||
row.add_column("NAME", upper_text(name))
|
||||
row.add_column("PLUGIN", upper_text(provider or ""))
|
||||
row.add_column("STORE", upper_text(store or ""))
|
||||
row.add_column("INSTANCE", upper_text(instance or ""))
|
||||
row.add_column("FILES", "" if files is None else str(files))
|
||||
row.add_column("DETAIL", upper_text(detail or ""))
|
||||
|
||||
|
||||
def _provider_config_map(config: dict) -> dict[str, Any]:
|
||||
if not isinstance(config, dict):
|
||||
return {}
|
||||
|
||||
provider_cfg = config.get("plugin")
|
||||
if not isinstance(provider_cfg, dict):
|
||||
provider_cfg = config.get("provider")
|
||||
return provider_cfg if isinstance(provider_cfg, dict) else {}
|
||||
|
||||
|
||||
def _iter_registered_plugin_infos() -> tuple[Any, ...]:
|
||||
try:
|
||||
from ProviderCore.registry import REGISTRY
|
||||
|
||||
return tuple(
|
||||
sorted(
|
||||
REGISTRY.iter_plugins(),
|
||||
key=lambda info: str(
|
||||
getattr(info, "canonical_name", "") or ""
|
||||
).lower(),
|
||||
)
|
||||
)
|
||||
except Exception:
|
||||
return ()
|
||||
|
||||
|
||||
def _extract_configured_instance_names(raw_entry: Any) -> list[str]:
|
||||
if not isinstance(raw_entry, dict) or not raw_entry:
|
||||
return []
|
||||
if not all(isinstance(value, dict) for value in raw_entry.values()):
|
||||
return []
|
||||
|
||||
names: list[str] = []
|
||||
for key in raw_entry.keys():
|
||||
name = str(key or "").strip()
|
||||
if not name or name.lower() == "default":
|
||||
continue
|
||||
names.append(name)
|
||||
return names
|
||||
|
||||
|
||||
def _resolve_startup_instance_text(
|
||||
plugin: Any,
|
||||
summary: dict[str, Any],
|
||||
configured_entry: Any,
|
||||
) -> str:
|
||||
instance_text = str(summary.get("instance") or "").strip()
|
||||
if instance_text:
|
||||
return instance_text
|
||||
|
||||
raw_instances = summary.get("instances")
|
||||
if isinstance(raw_instances, (list, tuple, set)):
|
||||
values = [str(value).strip() for value in raw_instances if str(value).strip()]
|
||||
if values:
|
||||
return ", ".join(values)
|
||||
elif raw_instances is not None:
|
||||
instance_text = str(raw_instances).strip()
|
||||
if instance_text:
|
||||
return instance_text
|
||||
|
||||
try:
|
||||
configured_instances = plugin.configured_instances() if plugin is not None else []
|
||||
except Exception:
|
||||
configured_instances = []
|
||||
|
||||
if configured_instances:
|
||||
return ", ".join(str(value).strip() for value in configured_instances if str(value).strip())
|
||||
|
||||
return ", ".join(_extract_configured_instance_names(configured_entry))
|
||||
|
||||
|
||||
def has_store_subtype(cfg: dict, subtype: str) -> bool:
|
||||
store_cfg = cfg.get("store")
|
||||
if not isinstance(store_cfg, dict):
|
||||
@@ -113,61 +184,73 @@ def ping_first(urls: list[str]) -> tuple[bool, str]:
|
||||
|
||||
|
||||
def collect_plugin_startup_checks(config: dict) -> list[dict[str, Any]]:
|
||||
provider_cfg = None
|
||||
if isinstance(config, dict):
|
||||
provider_cfg = config.get("plugin")
|
||||
if not isinstance(provider_cfg, dict):
|
||||
provider_cfg = config.get("provider")
|
||||
if not isinstance(provider_cfg, dict) or not provider_cfg:
|
||||
return []
|
||||
|
||||
try:
|
||||
from ProviderCore.registry import get_plugin_class
|
||||
except Exception:
|
||||
return []
|
||||
provider_cfg = _provider_config_map(config)
|
||||
|
||||
checks: list[dict[str, Any]] = []
|
||||
for plugin_name in provider_cfg.keys():
|
||||
plugin_key = str(plugin_name or "").strip().lower()
|
||||
seen_plugin_keys: set[str] = set()
|
||||
|
||||
for info in _iter_registered_plugin_infos():
|
||||
plugin_key = str(getattr(info, "canonical_name", "") or "").strip().lower()
|
||||
if not plugin_key:
|
||||
continue
|
||||
seen_plugin_keys.add(plugin_key)
|
||||
|
||||
plugin_class = None
|
||||
try:
|
||||
plugin_class = get_plugin_class(plugin_key)
|
||||
except Exception:
|
||||
plugin_class = None
|
||||
|
||||
if plugin_class is None:
|
||||
checks.append(
|
||||
{
|
||||
"status": "UNKNOWN",
|
||||
"name": provider_display_name(plugin_key),
|
||||
"plugin": plugin_key,
|
||||
"detail": "Not registered",
|
||||
}
|
||||
)
|
||||
continue
|
||||
plugin = None
|
||||
summary: dict[str, Any]
|
||||
display_name = provider_display_name(plugin_key)
|
||||
configured_entry: Any = None
|
||||
|
||||
try:
|
||||
plugin = plugin_class(config)
|
||||
plugin = info.plugin_class(config)
|
||||
configured_entry = plugin.plugin_config_root()
|
||||
summary = plugin.status_summary()
|
||||
except Exception as exc:
|
||||
summary = {
|
||||
"status": "DISABLED",
|
||||
"name": provider_display_name(plugin_key),
|
||||
"name": display_name,
|
||||
"plugin": plugin_key,
|
||||
"detail": str(exc),
|
||||
}
|
||||
|
||||
status = str(summary.get("status") or "UNKNOWN").strip().upper() or "UNKNOWN"
|
||||
name = str(summary.get("name") or display_name)
|
||||
detail = str(summary.get("detail") or "").strip()
|
||||
if detail.lower() == "configured" and not configured_entry:
|
||||
detail = "Available"
|
||||
if not detail:
|
||||
if status == "ENABLED":
|
||||
detail = "Configured" if configured_entry else "Available"
|
||||
else:
|
||||
detail = "Not configured" if not configured_entry else "Unavailable"
|
||||
|
||||
checks.append(
|
||||
{
|
||||
"status": str(summary.get("status") or "UNKNOWN"),
|
||||
"name": str(summary.get("name") or provider_display_name(plugin_key)),
|
||||
"status": status,
|
||||
"name": name,
|
||||
"plugin": str(summary.get("plugin") or plugin_key),
|
||||
"detail": str(summary.get("detail") or ""),
|
||||
"instance": _resolve_startup_instance_text(
|
||||
plugin,
|
||||
summary,
|
||||
configured_entry if configured_entry else provider_cfg.get(plugin_key),
|
||||
),
|
||||
"detail": detail,
|
||||
"files": summary.get("files"),
|
||||
}
|
||||
)
|
||||
|
||||
for plugin_name, raw_entry in sorted(provider_cfg.items()):
|
||||
plugin_key = str(plugin_name or "").strip().lower()
|
||||
if not plugin_key or plugin_key in seen_plugin_keys:
|
||||
continue
|
||||
checks.append(
|
||||
{
|
||||
"status": "UNKNOWN",
|
||||
"name": provider_display_name(plugin_key),
|
||||
"plugin": plugin_key,
|
||||
"instance": ", ".join(_extract_configured_instance_names(raw_entry)),
|
||||
"detail": "Not registered",
|
||||
"files": None,
|
||||
}
|
||||
)
|
||||
|
||||
return checks
|
||||
Reference in New Issue
Block a user