From 73cbed952c5d2cdfdaceb5f8c2b19c77738b5186 Mon Sep 17 00:00:00 2001 From: amelia squires Date: Sat, 24 Aug 2024 01:26:40 -0500 Subject: init --- src/sync.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/sync.py (limited to 'src/sync.py') diff --git a/src/sync.py b/src/sync.py new file mode 100644 index 0000000..8a1a94e --- /dev/null +++ b/src/sync.py @@ -0,0 +1,35 @@ +from common import * +import copy + +def sync_obj(repo_name: str) -> None: + if not repo_name in tracked: + return + + for p in tracked[repo_name]: + copy.copy([{"path":p, "repo": repo_name, "full_path": os.path.join(REPO_LOC, repo_name, p)}]) + +def sync(sync_repos: list[repo_pair]) -> None: + for r in sync_repos: + full_path = os.path.join(REPO_LOC, r["name"]) + if os.path.isdir(full_path): + + old_hash = subprocess.getoutput(f"cd {full_path} && git rev-parse HEAD") + os.system(f"cd {full_path} && git pull --quiet") + + new_hash = subprocess.getoutput(f"cd {full_path} && git rev-parse HEAD") + + if old_hash == new_hash: + print(f"{r["name"]}: up to date") + else: + print(f"{r["name"]}: {new_hash}") + + else: + 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}") + + if questionary.confirm("would you like to sync all tracked packages, from this repo?").ask(): + sync_obj(r["name"]) + + -- cgit v1.2.3