41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
import subprocess as sp
|
|
from typing import List
|
|
|
|
from util.input import password
|
|
|
|
|
|
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 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
|
|
|
|
|
|
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]:
|
|
if use_sudo:
|
|
pw = password()
|
|
return sp.run(
|
|
["yay", "--noconfirm", *args], capture_output=True, text=True, input=pw
|
|
)
|
|
else:
|
|
return sp.run(["yay", "--noconfirm", *args], capture_output=True, text=True)
|