Compare commits

...

4 Commits

6 changed files with 205 additions and 44 deletions
+34 -27
View File
@@ -6,33 +6,40 @@ import commands.init as init
import commands.pull as pull import commands.pull as pull
import commands.push as push import commands.push as push
args, ap = cliargs.add_cli_args()
if args.cmd == None: if __name__ == "__main__":
ap.print_help() args, ap = cliargs.add_cli_args()
print("\nSpecify a subcommand, '-h' or '-v'")
exit(64)
print( if args.cmd == None:
""" ap.print_help()
_ print("\nSpecify a subcommand, '-h' or '-v'")
( ) exit(64)
_ _ _ __ ___| |__ ___ ___ __ _ __
/ _ ) __)/ ___) _ \\ _ _ \\/ _ \\ __)
( (_| | | ( (___| | | | ( ) ( ) | (_) | |
\\__ _)_) \\____)_) (_)_) (_) (_)\\__ |_)
( )_) |
\\___/
"""
)
if args.cmd == "commit": print(
commit.commit(args.dry_run, args.force, args.no_commit) """
elif args.cmd == "config": _
config.config() ( )
elif args.cmd == "init": _ _ _ __ ___| |__ ___ ___ __ _ __
init.init(args.force) / _ ) __)/ ___) _ \\ _ _ \\/ _ \\ __)
elif args.cmd == "pull": ( (_| | | ( (___| | | | ( ) ( ) | (_) | |
pull.pull(args.rebase, args.apply) \\__ _)_) \\____)_) (_)_) (_) (_)\\__ |_)
elif args.cmd == "push": ( )_) |
push.push(args.force) \\___/
"""
)
try:
if args.cmd == "commit":
commit.commit(args.dry_run, args.force, args.no_render)
elif args.cmd == "config":
config.config()
elif args.cmd == "init":
init.init(args.force)
elif args.cmd == "pull":
pull.pull(args.rebase, args.apply)
elif args.cmd == "push":
push.push(args.force)
except KeyboardInterrupt as e:
exit(130)
except Exception as e:
raise e
+5 -2
View File
@@ -1,8 +1,11 @@
from commands.util.choice import confirm_overwrite from commands.util import pacman
from commands.util.input_mgr import confirm_overwrite, password
def commit(dry_run: bool = False, force: bool = False): def commit(dry_run: bool = False, force: bool = False, no_render: bool = False):
if dry_run: if dry_run:
pass pass
print("Commit, force:", force) print("Commit, force:", force)
password()
print(pacman.list_explicitly_installed())
print(confirm_overwrite()) print(confirm_overwrite())
-13
View File
@@ -1,13 +0,0 @@
from typing import List
def compute_diff(paths: List[str]):
pass
def file_diff(path: str):
pass
def pkg_diff():
pass
+102 -2
View File
@@ -1,5 +1,105 @@
import os
import subprocess import subprocess
def init(dirname: str): def init(dirname: str) -> bool:
subprocess.call("git init", cwd=dirname) """Initialize a new git repo in the directory
Args:
dirname: The directory to create it in
Returns:
True on success, False on error
"""
return subprocess.call("git init", cwd=dirname) == 0
def commit(msg: str):
"""Create a new commit
Args:
msg: The commit message
Returns:
True on success, False on error
"""
dir = os.getcwd()
return subprocess.call('git commit -am "' + msg + '"', cwd=dir) == 0
def branch_add(name: str):
"""Create a new git branch
Args:
name: The name of the branch to create
Returns:
True on success, False on error
"""
dir = os.getcwd()
return subprocess.call("git branch " + name, cwd=dir) == 0
def branch_switch(name: str):
"""Switch to a git branch
Args:
name: The name of the branch to switch to
Returns:
True on success, False on error
"""
dir = os.getcwd()
return subprocess.call("git checkout " + name, cwd=dir) == 0
def branch_show():
"""Create a new git branch
Args:
name: The name of the branch to create
Returns:
True on success, False on error
"""
dir = os.getcwd()
return subprocess.call("git branch", cwd=dir) == 0
def branch_delete(name: str):
"""Delete a git branch
Args:
name: The name of the branch to delete
Returns:
True on success, False on error
"""
dir = os.getcwd()
return subprocess.call("git branch -d " + name, cwd=dir) == 0
def pull(rebase: bool = False):
"""Pull git changes
Args:
rebase: Whether to rebase or not
Returns:
True on success, False on error
"""
dir = os.getcwd()
return subprocess.call("git pull" + (" --rebase" if rebase else ""), cwd=dir) == 0
def push(force: bool = False):
"""Push git changes
Args:
force: Whether to force push
Returns:
True on success, False on error
"""
dir = os.getcwd()
return subprocess.call("git push" + (" --force" if force else ""), cwd=dir) == 0
@@ -1,4 +1,6 @@
from typing import Optional from typing import Optional
import getpass
import time
def choice(default: str, options: str, msg: str) -> str: def choice(default: str, options: str, msg: str) -> str:
@@ -28,3 +30,17 @@ def confirm_overwrite(msg: Optional[str] = ""):
return confirm( return confirm(
False, (msg if msg != "" else "Do you really want to overwrite your changes?") False, (msg if msg != "" else "Do you really want to overwrite your changes?")
) )
def password(msg: str = ""):
pw = ""
if msg != "":
pw = getpass.getpass(msg)
else:
pw = getpass.getpass()
if pw != "":
return pw
else:
time.sleep(1)
print("Error: Password cannot be empty")
return password(msg)
+48
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)