feat(pacman): Add needed commands

This commit is contained in:
2026-04-10 08:58:54 +02:00
parent 0697bef7d5
commit 711b89a0d6

48
commands/util/pacman.py Normal file
View File

@@ -0,0 +1,48 @@
import subprocess as sp
from typing import List
pkg_manager = ["yay", "--noconfirm"]
def list_explicitly_installed() -> List[str]:
"""List all packages explicitly installed
Returns:
The package list
"""
return run_pkg_manager_cmd(["-Qeq"]).stdout.split()
def uninstall_package_list(pkgs: List[str]) -> bool:
"""Uninstall all packages in the list
Args:
pkgs: A list of packages to uninstall
Returns:
True if successful, False otherwise
"""
# TODO: Add guard to protect against uninstalling archmgr
# 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
def install_package_list(pkgs: List[str]) -> bool:
"""Install all packages in the list
Args:
pkgs: A list of packages to install
"""
return run_pkg_manager_cmd(["-S", *pkgs], True).returncode == 0
def run_pkg_manager_cmd(
args: List[str], use_sudo: bool = False
) -> sp.CompletedProcess[str]:
# TODO: Get password
pw = ""
if use_sudo:
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)