Show version-locked plugins in menu
This commit is contained in:
@@ -41,8 +41,8 @@ def enable_disabled_plugin(
|
||||
progress: Callable[[str], None] | None = None,
|
||||
) -> dict[str, Any]:
|
||||
installed_state = load_installed_state(state_root, instance)
|
||||
if plugin_id not in installed_state.get("disabledPlugins", {}):
|
||||
raise KeyError(f"plugin is not recorded as disabled: {plugin_id}")
|
||||
if plugin_id in installed_state.get("plugins", {}):
|
||||
raise KeyError(f"plugin is already enabled: {plugin_id}")
|
||||
|
||||
root, registry_path, _lock_path, loaded_lockfile, loaded_registry = _resolve_paths(
|
||||
instance=instance,
|
||||
@@ -51,7 +51,21 @@ def enable_disabled_plugin(
|
||||
repo=repo,
|
||||
)
|
||||
if not any(plugin.id == plugin_id for plugin in loaded_lockfile.plugins):
|
||||
raise KeyError(f"plugin is disabled but not locked for this instance: {plugin_id}")
|
||||
raise KeyError(f"plugin is not locked for this instance: {plugin_id}")
|
||||
|
||||
tell = progress or (lambda _message: None)
|
||||
tell(f"Planning {plugin_id} from local assets")
|
||||
plan, path = create_plan(
|
||||
instance=instance,
|
||||
instance_path=instance_path,
|
||||
beat_saber_version=loaded_lockfile.beat_saber_version,
|
||||
registry=loaded_registry,
|
||||
lockfile=loaded_lockfile,
|
||||
state_root=state_root,
|
||||
repo_root=root,
|
||||
selected={plugin_id},
|
||||
require_bootstrap=False,
|
||||
)
|
||||
|
||||
ensure_healthy_bootstrap(
|
||||
instance=instance,
|
||||
@@ -65,16 +79,7 @@ def enable_disabled_plugin(
|
||||
progress=progress,
|
||||
)
|
||||
|
||||
plan, path = create_plan(
|
||||
instance=instance,
|
||||
instance_path=instance_path,
|
||||
beat_saber_version=loaded_lockfile.beat_saber_version,
|
||||
registry=loaded_registry,
|
||||
lockfile=loaded_lockfile,
|
||||
state_root=state_root,
|
||||
repo_root=root,
|
||||
selected={plugin_id},
|
||||
)
|
||||
tell(f"Applying {plugin_id}")
|
||||
result = apply_plan(plan, state_root)
|
||||
return {"planPath": str(path), **result}
|
||||
|
||||
@@ -100,8 +105,38 @@ def enable_disabled_plugins(
|
||||
repo=repo,
|
||||
)
|
||||
installed_state = load_installed_state(state_root, instance)
|
||||
disabled_plugins = installed_state.get("disabledPlugins", {})
|
||||
selected_ids = set(plugin_ids)
|
||||
enabled_plugins = installed_state.get("plugins", {})
|
||||
locked_ids = {plugin.id for plugin in loaded_lockfile.plugins}
|
||||
|
||||
enabled: list[dict[str, Any]] = []
|
||||
errors: list[dict[str, str]] = []
|
||||
plannable_ids: list[str] = []
|
||||
for plugin_id in plugin_ids:
|
||||
if plugin_id in enabled_plugins:
|
||||
errors.append({"plugin": plugin_id, "error": f"plugin is already enabled: {plugin_id}"})
|
||||
continue
|
||||
if plugin_id not in locked_ids:
|
||||
errors.append({"plugin": plugin_id, "error": f"plugin is not locked for this instance: {plugin_id}"})
|
||||
continue
|
||||
plannable_ids.append(plugin_id)
|
||||
|
||||
if not plannable_ids:
|
||||
return {"enabled": enabled, "errors": errors}
|
||||
|
||||
selected_ids = set(plannable_ids)
|
||||
tell = progress or (lambda _message: None)
|
||||
tell(f"Planning {len(plannable_ids)} plugins from local assets")
|
||||
batch_plan, batch_path = create_plan(
|
||||
instance=instance,
|
||||
instance_path=instance_path,
|
||||
beat_saber_version=loaded_lockfile.beat_saber_version,
|
||||
registry=loaded_registry,
|
||||
lockfile=loaded_lockfile,
|
||||
state_root=state_root,
|
||||
repo_root=root,
|
||||
selected=selected_ids,
|
||||
require_bootstrap=False,
|
||||
)
|
||||
|
||||
ensure_healthy_bootstrap(
|
||||
instance=instance,
|
||||
@@ -115,31 +150,14 @@ def enable_disabled_plugins(
|
||||
progress=progress,
|
||||
)
|
||||
|
||||
enabled: list[dict[str, Any]] = []
|
||||
errors: list[dict[str, str]] = []
|
||||
for plugin_id in plugin_ids:
|
||||
if plugin_id not in disabled_plugins:
|
||||
errors.append({"plugin": plugin_id, "error": f"plugin is not recorded as disabled: {plugin_id}"})
|
||||
continue
|
||||
if not any(plugin.id == plugin_id for plugin in loaded_lockfile.plugins):
|
||||
errors.append(
|
||||
{"plugin": plugin_id, "error": f"plugin is disabled but not locked for this instance: {plugin_id}"}
|
||||
)
|
||||
continue
|
||||
try:
|
||||
plan, path = create_plan(
|
||||
instance=instance,
|
||||
instance_path=instance_path,
|
||||
beat_saber_version=loaded_lockfile.beat_saber_version,
|
||||
registry=loaded_registry,
|
||||
lockfile=loaded_lockfile,
|
||||
state_root=state_root,
|
||||
repo_root=root,
|
||||
selected={plugin_id},
|
||||
)
|
||||
result = apply_plan(plan, state_root)
|
||||
enabled.append({"plugin": plugin_id, "planPath": str(path), "applied": len(result["applied"])})
|
||||
except Exception as exc:
|
||||
errors.append({"plugin": plugin_id, "error": str(exc)})
|
||||
tell(f"Applying {len(plannable_ids)} plugins")
|
||||
result = apply_plan(batch_plan, state_root)
|
||||
applied_by_plugin: dict[str, int] = {}
|
||||
for item in result["applied"]:
|
||||
plugin_id = item["plugin"]
|
||||
applied_by_plugin[plugin_id] = applied_by_plugin.get(plugin_id, 0) + 1
|
||||
|
||||
for plugin_id in plannable_ids:
|
||||
enabled.append({"plugin": plugin_id, "planPath": str(batch_path), "applied": applied_by_plugin.get(plugin_id, 0)})
|
||||
|
||||
return {"enabled": enabled, "errors": errors}
|
||||
|
||||
Reference in New Issue
Block a user