feat: printing utils
This commit is contained in:
+1
-1
@@ -28,7 +28,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
if args.cmd == "commit":
|
if args.cmd == "commit":
|
||||||
commit.commit(args.dry_run, args.force, args.no_render)
|
commit.commit(args.force, args.no_render)
|
||||||
elif args.cmd == "config":
|
elif args.cmd == "config":
|
||||||
config.config()
|
config.config()
|
||||||
elif args.cmd == "init":
|
elif args.cmd == "init":
|
||||||
|
|||||||
+1
-7
@@ -21,16 +21,10 @@ def add_cli_args():
|
|||||||
commit = sp.add_parser(
|
commit = sp.add_parser(
|
||||||
"commit", help="apply pending changes and commit to git repo"
|
"commit", help="apply pending changes and commit to git repo"
|
||||||
)
|
)
|
||||||
commit.add_argument("-f", "--force", help="force apply", action="store_true")
|
commit.add_argument("-f", "--force", help="force apply (skips prompts)", action="store_true")
|
||||||
commit.add_argument(
|
commit.add_argument(
|
||||||
"--no-render", "-r", help="do not re-render renderables", action="store_true"
|
"--no-render", "-r", help="do not re-render renderables", action="store_true"
|
||||||
)
|
)
|
||||||
commit.add_argument(
|
|
||||||
"--dry-run",
|
|
||||||
"-d",
|
|
||||||
help="print out files that would be changed",
|
|
||||||
action="store_true",
|
|
||||||
)
|
|
||||||
|
|
||||||
sp.add_parser("config", help="prints information about your config")
|
sp.add_parser("config", help="prints information about your config")
|
||||||
|
|
||||||
|
|||||||
+25
-5
@@ -1,11 +1,31 @@
|
|||||||
|
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_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):
|
def commit(force: bool = False, no_render: bool = False):
|
||||||
if dry_run:
|
|
||||||
pass
|
|
||||||
print("Commit, force:", force)
|
print("Commit, force:", force)
|
||||||
password()
|
# TODO: Make sure we don't uninstall critical system packages by accident (i.e. prompt user)
|
||||||
print(pacman.list_explicitly_installed())
|
# Probably do that check in the pacman util lib tho
|
||||||
|
# pw = password()
|
||||||
|
print_diff(pacman.list_explicitly_installed(), [])
|
||||||
print(confirm_overwrite())
|
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
|
import subprocess
|
||||||
|
|
||||||
from commands.util import pacman
|
from commands.util import pacman
|
||||||
|
from commands.util.input_mgr import confirm
|
||||||
|
|
||||||
|
|
||||||
def setup():
|
def setup():
|
||||||
@@ -8,6 +9,20 @@ def setup():
|
|||||||
if not pacman.install_package_list(["git"]):
|
if not pacman.install_package_list(["git"]):
|
||||||
print("Git installation failed")
|
print("Git installation failed")
|
||||||
return
|
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")
|
print("==> Installation completed")
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
import getpass
|
import getpass
|
||||||
import time
|
import time
|
||||||
|
import colorama
|
||||||
|
|
||||||
|
|
||||||
def choice(default: str, options: str, msg: str) -> str:
|
def choice(default: str, options: str, msg: str) -> str:
|
||||||
@@ -42,5 +43,8 @@ def password(msg: str = ""):
|
|||||||
return pw
|
return pw
|
||||||
else:
|
else:
|
||||||
time.sleep(1)
|
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)
|
return password(msg)
|
||||||
|
|||||||
@@ -13,6 +13,15 @@ def list_explicitly_installed() -> List[str]:
|
|||||||
return run_pkg_manager_cmd(["-Qeq"]).stdout.split()
|
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:
|
def uninstall_package_list(pkgs: List[str]) -> bool:
|
||||||
"""Uninstall all packages in the list
|
"""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