diff options
author | ame <[email protected]> | 2025-03-03 03:07:15 -0600 |
---|---|---|
committer | ame <[email protected]> | 2025-03-03 03:07:15 -0600 |
commit | bb96c6e30f393bb135e2f6b7ddb314027f0aee54 (patch) | |
tree | 9e26ea7d6eb41633436edc6091d01b6a3bb6b12d | |
parent | 73cbed952c5d2cdfdaceb5f8c2b19c77738b5186 (diff) |
qol update
-rw-r--r-- | example_config.yaml | 3 | ||||
-rwxr-xr-x | src/__main__.py | 9 | ||||
-rw-r--r-- | src/common.py | 12 | ||||
-rw-r--r-- | src/copy.py | 8 | ||||
-rw-r--r-- | src/rm.py | 4 | ||||
-rw-r--r-- | src/sync.py | 23 |
6 files changed, 36 insertions, 23 deletions
diff --git a/example_config.yaml b/example_config.yaml index 568006b..019955a 100644 --- a/example_config.yaml +++ b/example_config.yaml @@ -5,3 +5,6 @@ repo: amyy #location to store repositories repo_location: /home/amelia/.local/share/gpo-steal + +#method to get root access +elevation: doas diff --git a/src/__main__.py b/src/__main__.py index d38d550..913acff 100755 --- a/src/__main__.py +++ b/src/__main__.py @@ -26,8 +26,10 @@ if len(sys.argv) == 1: match sys.argv[1]: case "sync" | "s": options = list(repos.keys()) - name = questionary.select("which repository", options).ask() - sync_repos = [repos[name]] + name = questionary.select("which repository", ["all", *options]).ask() + sync_repos = repos.values() + if name != "all": + sync_repos = [repos[name]] sync(sync_repos) @@ -108,7 +110,8 @@ match sys.argv[1]: print("no matches") exit(0) - copy.copy([use]) + cmd = copy.copy([use]) + eexec(cmd) case "r" | "rm": assert len(sys.argv) >= 3 diff --git a/src/common.py b/src/common.py index 416d836..f1a64bf 100644 --- a/src/common.py +++ b/src/common.py @@ -13,12 +13,14 @@ from typing import TypedDict REAL_REPO = "" REPOS_LOCATION = "/var/db/repos" REPO_LOC = "" +ROOT = "sudo" try: with open(os.path.expanduser("~/.config/gpo-steal/config.yaml"), "r") as f: cfg = yaml.safe_load(f.read()) REAL_REPO = cfg["repo"] REPO_LOC = cfg["repo_location"] + ROOT = cfg["elevation"] except FileNotFoundError: print("no configuration found, should be in ~/.config/gpo-steal/config.yaml") exit(1) @@ -36,11 +38,6 @@ class repo_pair(TypedDict): repos = {} tracked = {} -root = "" -if not shutil.which("sudo") is None: - root = "sudo" -if not shutil.which("doas") is None: - root = "doas" try: with open(REPO_CFG_LOC, "r") as f: repos = yaml.safe_load(f.read()) or repos @@ -59,3 +56,8 @@ def save() -> None: with open(TRACKED_CFG_LOC, "w") as f: yaml.dump(tracked, f) + +def eexec(cmd) -> None: + run = f"{ROOT} sh -c '{cmd}'" + print(run) + os.system(run) diff --git a/src/copy.py b/src/copy.py index 9ffc24c..50e56b6 100644 --- a/src/copy.py +++ b/src/copy.py @@ -1,6 +1,6 @@ from common import * -def copy(use_d) -> None: +def copy(use_d) -> str: srcs = [] dests = [] @@ -14,11 +14,9 @@ def copy(use_d) -> None: srcs.append(os.path.join(REPO_LOC, use["repo"], use["path"])) dests.append(os.path.join(FULL_REPOS_LOCATION, use["path"])) - cmd = f"{root} sh -c 'mkdir -p {' '.join(dests)};" + cmd = f"mkdir -p {' '.join(dests)};" for i in range(len(dests)): cmd += f"cp -r {srcs[i]}/* {dests[i]};" - cmd += "'" - print(cmd) - os.system(cmd) + return cmd @@ -1,7 +1,7 @@ from common import * def rm_pkg(pkg) -> None: - cmd = f"{root} rm -fr {os.path.join(FULL_REPOS_LOCATION, pkg)}" + cmd = f"{ROOT} rm -fr {os.path.join(FULL_REPOS_LOCATION, pkg)}" print(cmd) os.system(cmd) @@ -21,7 +21,7 @@ def rm(pkg, repos) -> None: elif len(found) == 1: use = found[0] else: - names = [f"{x["path"]}:{x["repo"]}" for x in found] + names = [f"{x['path']}:{x['repo']}" for x in found] selected = questionary.select(f"{pkg} is ambiguous, select a more specific package", names).ask().split(":") use = [x for x in found if x["path"] == selected[0] and x["repo"] == selected[1]][0] print(use) diff --git a/src/sync.py b/src/sync.py index 8a1a94e..822104f 100644 --- a/src/sync.py +++ b/src/sync.py @@ -1,15 +1,19 @@ from common import * import copy -def sync_obj(repo_name: str) -> None: +def sync_obj(repo_name: str) -> str: if not repo_name in tracked: - return + return "" + cmds = "" for p in tracked[repo_name]: - copy.copy([{"path":p, "repo": repo_name, "full_path": os.path.join(REPO_LOC, repo_name, p)}]) + cmds += str(copy.copy([{"path":p, "repo": repo_name, "full_path": os.path.join(REPO_LOC, repo_name, p)}])) + return cmds def sync(sync_repos: list[repo_pair]) -> None: + cmds = "" for r in sync_repos: + print(r) full_path = os.path.join(REPO_LOC, r["name"]) if os.path.isdir(full_path): @@ -19,17 +23,20 @@ def sync(sync_repos: list[repo_pair]) -> None: new_hash = subprocess.getoutput(f"cd {full_path} && git rev-parse HEAD") if old_hash == new_hash: - print(f"{r["name"]}: up to date") + print(f"{r['name']}: up to date") else: - print(f"{r["name"]}: {new_hash}") + print(f"{r['name']}: {new_hash}") else: - os.system(f"cd {REPO_LOC} && git clone {r["url"]} {r["name"]}") + os.system(f"cd {REPO_LOC} && git clone {r['url']} {r['name']}") new_hash = subprocess.getoutput(f"cd {full_path} && git rev-parse HEAD") - print(f"{r["name"]}: {new_hash}") + print(f"{r['name']}: {new_hash}") if questionary.confirm("would you like to sync all tracked packages, from this repo?").ask(): - sync_obj(r["name"]) + cmds += sync_obj(r["name"]) + + if cmds != "": + eexec(cmds) |