feat: printing utils
This commit is contained in:
+25
-5
@@ -1,11 +1,31 @@
|
||||
from typing import List
|
||||
from commands.util import pacman
|
||||
from commands.util.input_mgr import confirm_overwrite, password
|
||||
import colorama as cl
|
||||
|
||||
from commands.util.printer import print_list
|
||||
|
||||
|
||||
def commit(dry_run: bool = False, force: bool = False, no_render: bool = False):
|
||||
if dry_run:
|
||||
pass
|
||||
def commit(force: bool = False, no_render: bool = False):
|
||||
print("Commit, force:", force)
|
||||
password()
|
||||
print(pacman.list_explicitly_installed())
|
||||
# TODO: Make sure we don't uninstall critical system packages by accident (i.e. prompt user)
|
||||
# Probably do that check in the pacman util lib tho
|
||||
# pw = password()
|
||||
print_diff(pacman.list_explicitly_installed(), [])
|
||||
print(confirm_overwrite())
|
||||
|
||||
|
||||
def print_diff(add: List[str], remove: List[str]):
|
||||
print(
|
||||
cl.Fore.GREEN + "==>",
|
||||
cl.Style.RESET_ALL + "Packages that will be",
|
||||
cl.Fore.GREEN + "installed" + cl.Style.RESET_ALL,
|
||||
)
|
||||
|
||||
print_list(add)
|
||||
|
||||
print(
|
||||
cl.Fore.GREEN + "==>",
|
||||
cl.Style.RESET_ALL + "Packages that will be",
|
||||
cl.Fore.RED + "uninstalled" + cl.Style.RESET_ALL,
|
||||
)
|
||||
|
||||
+17
-2
@@ -1,6 +1,7 @@
|
||||
import subprocess
|
||||
|
||||
from commands.util import pacman
|
||||
from commands.util.input_mgr import confirm
|
||||
|
||||
|
||||
def setup():
|
||||
@@ -8,6 +9,20 @@ def setup():
|
||||
if not pacman.install_package_list(["git"]):
|
||||
print("Git installation failed")
|
||||
return
|
||||
subprocess.run(["git", "clone", "https://aur.archlinux.org/yay.git"], cwd="/tmp")
|
||||
subprocess.run(["makepkg", "-si"], cwd="/tmp/yay")
|
||||
|
||||
subprocess.run(
|
||||
["git", "clone", "https://aur.archlinux.org/yay.git"],
|
||||
cwd="/tmp",
|
||||
capture_output=True,
|
||||
)
|
||||
yay_install = subprocess.run(
|
||||
["makepkg", "-si"], cwd="/tmp/yay", capture_output=True
|
||||
)
|
||||
|
||||
if yay_install.returncode != 0:
|
||||
print("==> Installation of yay failed")
|
||||
if confirm(True, "Do you wish to view the logs?"):
|
||||
print(yay_install.stdout, "\n", yay_install.stderr)
|
||||
return
|
||||
|
||||
print("==> Installation completed")
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from typing import Optional
|
||||
import getpass
|
||||
import time
|
||||
import colorama
|
||||
|
||||
|
||||
def choice(default: str, options: str, msg: str) -> str:
|
||||
@@ -42,5 +43,8 @@ def password(msg: str = ""):
|
||||
return pw
|
||||
else:
|
||||
time.sleep(1)
|
||||
print("Error: Password cannot be empty")
|
||||
print(
|
||||
colorama.Fore.RED + "Error:",
|
||||
colorama.Style.RESET_ALL + "Password cannot be empty",
|
||||
)
|
||||
return password(msg)
|
||||
|
||||
@@ -13,6 +13,15 @@ def list_explicitly_installed() -> List[str]:
|
||||
return run_pkg_manager_cmd(["-Qeq"]).stdout.split()
|
||||
|
||||
|
||||
def remove_orphans() -> bool:
|
||||
"""Removes all orphan packages
|
||||
|
||||
Returns:
|
||||
True if successful, False otherwise
|
||||
"""
|
||||
return sp.run("pacman -Qdtq | pacman -Rnsy -", capture_output=True).returncode == 0
|
||||
|
||||
|
||||
def uninstall_package_list(pkgs: List[str]) -> bool:
|
||||
"""Uninstall all packages in the list
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
from typing import Any, List
|
||||
import colorama as cl
|
||||
|
||||
|
||||
def count_digits(number: int):
|
||||
return len(str(number))
|
||||
|
||||
|
||||
def print_list(list: List[Any]):
|
||||
digit_count = count_digits(len(list))
|
||||
for i, pkg in enumerate(list):
|
||||
print(
|
||||
" "
|
||||
+ cl.Fore.BLUE
|
||||
+ cl.Style.DIM
|
||||
+ (" " * (digit_count - count_digits(i)))
|
||||
+ str(i)
|
||||
+ cl.Style.RESET_ALL + " ",
|
||||
pkg,
|
||||
)
|
||||
Reference in New Issue
Block a user