From 73cbed952c5d2cdfdaceb5f8c2b19c77738b5186 Mon Sep 17 00:00:00 2001 From: amelia squires Date: Sat, 24 Aug 2024 01:26:40 -0500 Subject: init --- src/common.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/common.py (limited to 'src/common.py') diff --git a/src/common.py b/src/common.py new file mode 100644 index 0000000..416d836 --- /dev/null +++ b/src/common.py @@ -0,0 +1,61 @@ +import yaml +import sys +import os +import subprocess +import questionary +import os +import shutil +import requests +import xmltodict +from difflib import SequenceMatcher +from typing import TypedDict + +REAL_REPO = "" +REPOS_LOCATION = "/var/db/repos" +REPO_LOC = "" + +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"] +except FileNotFoundError: + print("no configuration found, should be in ~/.config/gpo-steal/config.yaml") + exit(1) + +FULL_REPOS_LOCATION = os.path.join(REPOS_LOCATION, REAL_REPO) +REPO_CFG_LOC = os.path.join(REPO_LOC, "repos.yaml") +TRACKED_CFG_LOC = os.path.join(REPO_LOC, "tracked.yaml") + +os.system(f"mkdir -p {REPO_LOC}") + +class repo_pair(TypedDict): + url: str + name: str + +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 +except: + pass + +try: + with open(TRACKED_CFG_LOC, "r") as f: + tracked = yaml.safe_load(f.read()) or tracked +except: + pass + +def save() -> None: + with open(REPO_CFG_LOC, "w") as f: + yaml.dump(repos, f) + + with open(TRACKED_CFG_LOC, "w") as f: + yaml.dump(tracked, f) -- cgit v1.2.3