aboutsummaryrefslogtreecommitdiff
path: root/src/common.py
diff options
context:
space:
mode:
authoramelia squires <[email protected]>2024-08-24 01:26:40 -0500
committeramelia squires <[email protected]>2024-08-24 01:26:40 -0500
commit73cbed952c5d2cdfdaceb5f8c2b19c77738b5186 (patch)
tree609a05141cfa950fd8637490de1dfe8241d65d3d /src/common.py
init
Diffstat (limited to 'src/common.py')
-rw-r--r--src/common.py61
1 files changed, 61 insertions, 0 deletions
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)