feat: Improved package diff printing
This commit is contained in:
+56
-12
@@ -1,6 +1,6 @@
|
|||||||
from typing import List
|
from typing import List
|
||||||
from commands.util import pacman
|
from commands.util import pacman
|
||||||
from commands.util.input_mgr import confirm_overwrite, password
|
from commands.util.input_mgr import confirm, password
|
||||||
import colorama as cl
|
import colorama as cl
|
||||||
|
|
||||||
from commands.util.printer import print_list
|
from commands.util.printer import print_list
|
||||||
@@ -10,22 +10,66 @@ def commit(force: bool = False, no_render: bool = False):
|
|||||||
print("Commit, force:", force)
|
print("Commit, force:", force)
|
||||||
# TODO: Make sure we don't uninstall critical system packages by accident (i.e. prompt user)
|
# 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
|
# Probably do that check in the pacman util lib tho
|
||||||
# pw = password()
|
|
||||||
print_diff(pacman.list_explicitly_installed(), [])
|
print_diff(pacman.list_explicitly_installed(), [])
|
||||||
print(confirm_overwrite())
|
if confirm(True, "Do you really want to proceed?"):
|
||||||
|
pw = password()
|
||||||
|
|
||||||
|
|
||||||
def print_diff(add: List[str], remove: List[str]):
|
def print_diff(add: List[str], remove: List[str]):
|
||||||
|
if len(add) == 0 and len(remove) == 0:
|
||||||
|
print(
|
||||||
|
cl.Fore.BLUE
|
||||||
|
+ "-->"
|
||||||
|
+ cl.Style.DIM
|
||||||
|
+ cl.Fore.GREEN
|
||||||
|
+ " No packages changes"
|
||||||
|
+ cl.Style.RESET_ALL,
|
||||||
|
)
|
||||||
|
# Packages to be installed
|
||||||
|
if len(add) == 0:
|
||||||
|
print(
|
||||||
|
cl.Fore.BLUE
|
||||||
|
+ "-->"
|
||||||
|
+ cl.Style.DIM
|
||||||
|
+ cl.Fore.GREEN
|
||||||
|
+ " No packages to be installed"
|
||||||
|
+ cl.Style.RESET_ALL,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
print(
|
||||||
|
cl.Fore.GREEN + "==>",
|
||||||
|
cl.Style.RESET_ALL + "Packages that will be",
|
||||||
|
cl.Fore.GREEN + "installed" + cl.Style.RESET_ALL,
|
||||||
|
)
|
||||||
|
print_list(add)
|
||||||
|
print()
|
||||||
|
|
||||||
|
# Packages to be removed
|
||||||
|
if len(remove) == 0:
|
||||||
|
print(
|
||||||
|
cl.Fore.BLUE
|
||||||
|
+ "-->"
|
||||||
|
+ cl.Style.DIM
|
||||||
|
+ cl.Fore.GREEN
|
||||||
|
+ " No packages to be uninstalled"
|
||||||
|
+ cl.Style.RESET_ALL,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
print(
|
||||||
|
cl.Fore.GREEN + "==>",
|
||||||
|
cl.Style.RESET_ALL + "Packages that will be",
|
||||||
|
cl.Fore.RED + "uninstalled" + cl.Style.RESET_ALL,
|
||||||
|
)
|
||||||
|
print_list(remove)
|
||||||
|
print()
|
||||||
|
|
||||||
|
# Ask user to confirm
|
||||||
print(
|
print(
|
||||||
cl.Fore.GREEN + "==>",
|
cl.Fore.GREEN + "==>",
|
||||||
cl.Style.RESET_ALL + "Packages that will be",
|
cl.Style.RESET_ALL
|
||||||
cl.Fore.GREEN + "installed" + cl.Style.RESET_ALL,
|
+ f"Transaction (packages): {cl.Fore.BLUE + str(len(add)) + cl.Style.RESET_ALL}",
|
||||||
)
|
cl.Fore.GREEN + "installed",
|
||||||
|
cl.Style.RESET_ALL
|
||||||
print_list(add)
|
+ f"and {cl.Fore.BLUE + str(len(remove)) + cl.Style.RESET_ALL}",
|
||||||
|
|
||||||
print(
|
|
||||||
cl.Fore.GREEN + "==>",
|
|
||||||
cl.Style.RESET_ALL + "Packages that will be",
|
|
||||||
cl.Fore.RED + "uninstalled" + cl.Style.RESET_ALL,
|
cl.Fore.RED + "uninstalled" + cl.Style.RESET_ALL,
|
||||||
)
|
)
|
||||||
|
|||||||
+6
-4
@@ -1,6 +1,8 @@
|
|||||||
|
from commands.util import pacman
|
||||||
|
|
||||||
|
|
||||||
def config():
|
def config():
|
||||||
print(
|
print("""
|
||||||
"""
|
|
||||||
Your config can be found at
|
Your config can be found at
|
||||||
"""
|
""")
|
||||||
)
|
pacman.install_package_list(["chromium"])
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ def remove_orphans() -> bool:
|
|||||||
Returns:
|
Returns:
|
||||||
True if successful, False otherwise
|
True if successful, False otherwise
|
||||||
"""
|
"""
|
||||||
return sp.run("pacman -Qdtq | pacman -Rnsy -", 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:
|
def uninstall_package_list(pkgs: List[str]) -> bool:
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ def print_list(list: List[Any]):
|
|||||||
" "
|
" "
|
||||||
+ cl.Fore.BLUE
|
+ cl.Fore.BLUE
|
||||||
+ cl.Style.DIM
|
+ cl.Style.DIM
|
||||||
+ (" " * (digit_count - count_digits(i)))
|
+ (" " * (digit_count - count_digits(i + 1)))
|
||||||
+ str(i)
|
+ str(1 + i)
|
||||||
+ cl.Style.RESET_ALL + " ",
|
+ cl.Style.RESET_ALL + " ",
|
||||||
pkg,
|
pkg,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user