From 0d72a2b411e66e656662a5287971b17856ea5a67 Mon Sep 17 00:00:00 2001 From: davidovski Date: Wed, 10 Nov 2021 12:13:01 +0000 Subject: added package info downloading --- src/verbs/install.py | 86 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 61 insertions(+), 25 deletions(-) (limited to 'src/verbs') 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="") -- cgit v1.2.1