79 lines
2.9 KiB
Python
79 lines
2.9 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from .models import Lockfile, Registry
|
|
|
|
|
|
def installed_plugins_report(
|
|
*,
|
|
installed_state: dict[str, Any],
|
|
registry: Registry,
|
|
lockfile: Lockfile,
|
|
) -> dict[str, Any]:
|
|
locked_by_id = {plugin.id: plugin for plugin in lockfile.plugins}
|
|
plugins: list[dict[str, Any]] = []
|
|
state_plugins = [
|
|
(plugin_id, plugin_state, "enabled")
|
|
for plugin_id, plugin_state in installed_state.get("plugins", {}).items()
|
|
]
|
|
state_plugins.extend(
|
|
(plugin_id, plugin_state, "disabled")
|
|
for plugin_id, plugin_state in installed_state.get("disabledPlugins", {}).items()
|
|
)
|
|
for plugin_id, plugin_state, status in sorted(state_plugins):
|
|
registry_plugin = registry.get(plugin_id)
|
|
locked = locked_by_id.get(plugin_id)
|
|
files = plugin_state.get("files", [])
|
|
plugins.append(
|
|
{
|
|
"id": plugin_id,
|
|
"name": registry_plugin.name if registry_plugin else plugin_id,
|
|
"version": locked.tag if locked and locked.tag else "(not locked)",
|
|
"asset": locked.asset if locked and locked.asset else "(unknown)",
|
|
"repo": (locked.repo if locked and locked.repo else None)
|
|
or (registry_plugin.repo if registry_plugin else None)
|
|
or "(unknown)",
|
|
"installedAt": plugin_state.get("installedAt", "(unknown)"),
|
|
"disabledAt": plugin_state.get("disabledAt"),
|
|
"status": status,
|
|
"fileCount": len(files),
|
|
"files": files,
|
|
}
|
|
)
|
|
return {
|
|
"instance": installed_state.get("instance", lockfile.instance),
|
|
"beatSaberVersion": installed_state.get("beatSaberVersion", lockfile.beat_saber_version),
|
|
"plugins": plugins,
|
|
}
|
|
|
|
|
|
def print_installed_plugins(report: dict[str, Any]) -> None:
|
|
plugins = report["plugins"]
|
|
print(f"{report['instance']} managed plugins ({len(plugins)})")
|
|
if not plugins:
|
|
print("No plugins have been installed by plugin-helper yet.")
|
|
return
|
|
|
|
headers = ("Plugin", "Status", "Version", "Asset", "Files", "Installed")
|
|
rows = [
|
|
(
|
|
f"{plugin['name']} ({plugin['id']})",
|
|
plugin["status"],
|
|
plugin["version"],
|
|
plugin["asset"],
|
|
str(plugin["fileCount"]),
|
|
plugin["disabledAt"] or plugin["installedAt"],
|
|
)
|
|
for plugin in plugins
|
|
]
|
|
widths = [
|
|
max(len(headers[index]), *(len(row[index]) for row in rows))
|
|
for index in range(len(headers))
|
|
]
|
|
header = " ".join(label.ljust(widths[index]) for index, label in enumerate(headers))
|
|
print(header)
|
|
print(" ".join("-" * width for width in widths))
|
|
for row in rows:
|
|
print(" ".join(value.ljust(widths[index]) for index, value in enumerate(row)))
|