From a8c82c3abbd0a0a1b9d82d126872ab989bb263aa Mon Sep 17 00:00:00 2001 From: davidovski Date: Tue, 9 Nov 2021 09:54:32 +0000 Subject: donwloading pkginfos --- src/verbs/sync.py | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'src/verbs') diff --git a/src/verbs/sync.py b/src/verbs/sync.py index f23d4fc..95c96f1 100644 --- a/src/verbs/sync.py +++ b/src/verbs/sync.py @@ -1,9 +1,43 @@ +import os +import requests +TEMP_DIR = "/tmp/xipkg" + +def curl(url): + r = requests.get(url) + return r.status_code, r.text + +def mkdir(path): + if not os.path.exists(path): + os.makedirs(path) + +def download_repo(output, url): + pkg_list_url = url + "/packages.txt" + + status, response = curl(pkg_list_url) + if status == 404: + print("repo does not exist at", pkg_list_url) + else: + packages = response.split("\n") + for package in packages: + if len(package) > 0: + pkg_url = url + "/" + package + status, package_info = curl(pkg_url) + + if status == 200: + with open(os.path.join(output, package), "w") as file: + file.write(package_info) + else: + print("package is missing at", pkg_url) # have separate list and download methods for each scheme def sync_package_infos(source_name, url, repos): + + source_dir = os.path.join(TEMP_DIR, source_name) + scheme = url.split(":")[0] + print(url) # TODO: add ftp if scheme.startswith("http"): sync_func = download_repo @@ -12,9 +46,16 @@ def sync_package_infos(source_name, url, repos): sync_func = copy_repo for repo in repos: - sync_func(output, url + f"/{repo}" if url[-1] == "/" else repo) + out = os.path.join(TEMP_DIR, repo) + mkdir(out) + sync_func(out, url + repo if url[-1] == "/" else f"/{repo}") def sync(options, config): sources = config["sources"] + repos = config["repos"] + + mkdir(TEMP_DIR) + for source, url in sources.items(): + sync_package_infos(source, url, repos) print("Synced!") -- cgit v1.2.1