feat: Diff packages
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
from typing import List
|
||||
|
||||
|
||||
def pkg_diff(target: List[str], actual: List[str]) -> tuple[List[str], List[str]]:
|
||||
"""Compute a diff between target packages and installed packages
|
||||
|
||||
Args:
|
||||
target: The target packages
|
||||
actual: The actually installed packages
|
||||
|
||||
Returns:
|
||||
A tuple with first the missing (not installed) packages
|
||||
and second the extraneous (to be uninstalled) packages
|
||||
"""
|
||||
for i, pkg in enumerate(actual):
|
||||
try:
|
||||
idx = target.index(pkg)
|
||||
target.pop(idx)
|
||||
actual.pop(i)
|
||||
except Exception:
|
||||
pass
|
||||
return (target, actual)
|
||||
+11
-4
@@ -1,6 +1,8 @@
|
||||
import subprocess as sp
|
||||
from typing import List
|
||||
|
||||
from commands.util.input_mgr import password
|
||||
|
||||
pkg_manager = ["yay", "--noconfirm"]
|
||||
|
||||
|
||||
@@ -19,7 +21,13 @@ def remove_orphans() -> bool:
|
||||
Returns:
|
||||
True if successful, False otherwise
|
||||
"""
|
||||
return sp.run("pacman -Qdtq | sudo pacman -Rns --noconfirm -", capture_output=True).returncode == 0
|
||||
return (
|
||||
sp.run(
|
||||
["pacman", "-Qdtq", "|", "sudo", "pacman", "-Rns", "--noconfirm", "-"],
|
||||
capture_output=True,
|
||||
).returncode
|
||||
== 0
|
||||
)
|
||||
|
||||
|
||||
def uninstall_package_list(pkgs: List[str]) -> bool:
|
||||
@@ -31,7 +39,7 @@ def uninstall_package_list(pkgs: List[str]) -> bool:
|
||||
Returns:
|
||||
True if successful, False otherwise
|
||||
"""
|
||||
# TODO: Add guard to protect against uninstalling archmgr
|
||||
# TODO: Add guard to protect against uninstalling archmgr and confirm uninstalling crucial pkgs
|
||||
# pkgs.index("archmgr")
|
||||
# TODO: Consider if we want to print out stdout and stderr on err
|
||||
return run_pkg_manager_cmd(["-Rs", *pkgs], True).returncode == 0
|
||||
@@ -49,9 +57,8 @@ def install_package_list(pkgs: List[str]) -> bool:
|
||||
def run_pkg_manager_cmd(
|
||||
args: List[str], use_sudo: bool = False
|
||||
) -> sp.CompletedProcess[str]:
|
||||
# TODO: Get password
|
||||
pw = ""
|
||||
if use_sudo:
|
||||
pw = password()
|
||||
return sp.run([*pkg_manager, *args], capture_output=True, text=True, input=pw)
|
||||
else:
|
||||
return sp.run([*pkg_manager, *args], capture_output=True, text=True)
|
||||
|
||||
Reference in New Issue
Block a user