Some checks failed
Mark stable commit / test-unit (push) Has been cancelled
Mark stable commit / test-integration (push) Has been cancelled
Mark stable commit / test-env-virtual (push) Has been cancelled
Mark stable commit / test-env-nix (push) Has been cancelled
Mark stable commit / test-e2e (push) Has been cancelled
Mark stable commit / test-virgin-user (push) Has been cancelled
Mark stable commit / test-virgin-root (push) Has been cancelled
Mark stable commit / codesniffer-shellcheck (push) Has been cancelled
Mark stable commit / codesniffer-ruff (push) Has been cancelled
Mark stable commit / mark-stable (push) Has been cancelled
- Fix undefined repo_dir usage in repository deinstall action - Centralize and harden get_repo_dir with strict validation and clear errors - Expand user paths for repository base and binary directories - Add unit tests for get_repo_dir and deinstall_repos - Add comprehensive tests for resolve_repos identifier matching - Remove obsolete command resolution tests no longer applicable https://chatgpt.com/share/693d7442-c2d0-800f-9ff3-fb84d60eaeb4
49 lines
1.8 KiB
Python
49 lines
1.8 KiB
Python
import os
|
|
|
|
from pkgmgr.core.command.run import run_command
|
|
from pkgmgr.core.repository.dir import get_repo_dir
|
|
from pkgmgr.core.repository.identifier import get_repo_identifier
|
|
|
|
|
|
def deinstall_repos(
|
|
selected_repos,
|
|
repositories_base_dir,
|
|
bin_dir,
|
|
all_repos,
|
|
preview: bool = False,
|
|
) -> None:
|
|
for repo in selected_repos:
|
|
repo_identifier = get_repo_identifier(repo, all_repos)
|
|
|
|
# Resolve repository directory
|
|
repo_dir = get_repo_dir(repositories_base_dir, repo)
|
|
|
|
# Prefer alias if available; fall back to identifier
|
|
alias_name = str(repo.get("alias") or repo_identifier)
|
|
alias_path = os.path.join(os.path.expanduser(bin_dir), alias_name)
|
|
|
|
# Remove alias link/file (interactive)
|
|
if os.path.exists(alias_path):
|
|
confirm = input(
|
|
f"Are you sure you want to delete link '{alias_path}' for {repo_identifier}? [y/N]: "
|
|
).strip().lower()
|
|
if confirm == "y":
|
|
if preview:
|
|
print(f"[Preview] Would remove link '{alias_path}'.")
|
|
else:
|
|
os.remove(alias_path)
|
|
print(f"Removed link for {repo_identifier}.")
|
|
else:
|
|
print(f"No link found for {repo_identifier} in {bin_dir}.")
|
|
|
|
# Run make deinstall if repository exists and has a Makefile
|
|
makefile_path = os.path.join(repo_dir, "Makefile")
|
|
if os.path.exists(makefile_path):
|
|
print(f"Makefile found in {repo_identifier}, running 'make deinstall'...")
|
|
try:
|
|
run_command("make deinstall", cwd=repo_dir, preview=preview)
|
|
except SystemExit as e:
|
|
print(
|
|
f"[Warning] Failed to run 'make deinstall' for {repo_identifier}: {e}"
|
|
)
|