summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/util.py3
-rw-r--r--src/verbs/install.py86
2 files changed, 64 insertions, 25 deletions
diff --git a/src/util.py b/src/util.py
index 3badca0..16df7bc 100644
--- a/src/util.py
+++ b/src/util.py
@@ -7,6 +7,9 @@ import os
DEFAULT_BAR_COLOR = colors.BLACK + colors.BG_CYAN
DEFAULT_BAR_COLOR_RESET = colors.BG_BLACK + colors.CYAN
+def add_path(a, b):
+ return a + (b if a[-1] == "/" else f"/{b}")
+
def loading_bar(completed, total, text,
unit="", color=DEFAULT_BAR_COLOR, reset=DEFAULT_BAR_COLOR_RESET):
diff --git a/src/verbs/install.py b/src/verbs/install.py
index 686178e..703a7ee 100644
--- a/src/verbs/install.py
+++ b/src/verbs/install.py
@@ -3,34 +3,70 @@ import util
import colors
import time
+def find_package(query, repos, packages_dir):
+ sources = []
+ checksum = None
+ requested_repo = None
+
+ for repo in repos:
+ repo_dir = os.path.join(packages_dir, repo)
+ files = os.listdir(repo_dir)
+
+ if query in files:
+ requested_repo = repo
+ with open(os.path.join(repo_dir, query)) as file:
+ checksum = file.readline().strip().split("=")[-1]
+ sources = file.readline().strip().split("=")[-1].split()
+ return checksum, sources, requested_repo
+ return None, [], None
+
+
+def retrieve_package_info(sources, checksum, package_name,
+ verbose=False, skip_verification=False):
+ for source,url in sources.items():
+ package_info_url = util.add_path(url, package_name + ".xipkg.info")
+ status, response = util.curl(package_info_url)
+
+ if status == 200:
+ info = parse_package_info(response)
+ if info["CHECKSUM"] == checksum or skip_verification:
+ return info
+ else:
+ if verbose:
+ print(colors.RED + f"Checksum verification failed for {package_name} in {source}" + colors.RESET)
+ if verbose:
+ print(colors.RED + f"No matching hashes found" + colors.RESET)
+ return {}
+
+def parse_package_info(packageinfo):
+ info = {}
+
+ for line in packageinfo.split("\n"):
+ split = line.split("=")
+ if len(split) > 1:
+ info[split[0]] = "=".join(split[1:])
+ return info
+
+
def install(args, options, config):
+ sources = config["sources"]
+ repos = config["repos"]
+
+ v = options["v"]
+
+ packages_dir = config["dir"]["packages"]
for query in args:
- sources = config["sources"]
- repos = config["repos"]
-
- v = options["v"]
-
- packages_dir = config["dir"]["packages"]
-
- sources = []
- checksum = None
- requested_repo = None
-
- for repo in repos:
- repo_dir = os.path.join(packages_dir, repo)
- files = os.listdir(repo_dir)
-
- if query in files:
- requested_repo = repo
- with open(os.path.join(repo_dir, query)) as file:
- checksum = file.read().split("=")[-1]
- sources = file.read().split("=")[-1].split()
- break
+
+ # FIRST CHECK IF ALREADY INSTALLED
+
+ checksum, listed_sources, repo = find_package(query, repos, packages_dir)
+
if checksum is not None:
- print(query)
- print(checksum)
- print(sources)
- print(requested_repo)
+ repo_sources = {source: util.add_path(url, repo) for source, url in sources.items() if source in listed_sources}
+
+ info = retrieve_package_info(repo_sources, checksum, query, verbose=v)
+
+ print(info)
else:
print(colors.RED + "Package not found")
print(colors.RESET, end="")