From afe4879f876d3b710cdf3e7d180cc26fca2d1eff Mon Sep 17 00:00:00 2001 From: Frede Hundewadt Date: Thu, 7 Dec 2023 07:30:45 +0100 Subject: [PATCH 1/6] Update get-iso --- get-iso | 123 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 98 insertions(+), 25 deletions(-) diff --git a/get-iso b/get-iso index 902fd67..fa73c75 100755 --- a/get-iso +++ b/get-iso @@ -4,19 +4,56 @@ # @linux-aarhus - root.nix.dk # License: GNU GPL, version 3 or later; https://www.gnu.org/licenses/gpl.html import argparse +import shutil import subprocess import sys import os import requests import time -from typing import List +import requests.exceptions from pathlib import Path + DEF_URL = "https://gitlab.manjaro.org/webpage/iso-info/-/raw/master/file-info.json" FOLDER = Path.home() PROG_NAME = os.path.basename(__file__) PROG_VERSION = "0.2" GNU_URL = "https://www.gnu.org/licenses/gpl.html" +REVIEW_URL = "https://api.github.com/repos/manjaro/release-review/releases/latest" +review_editions = ["gnome", "kde", "xfce"] + + +def init_review_iso_list(url: str) -> list: + """ + + :param url: + :return: + """ + # from the assets list we want to extract the browser_download_url propoerty for each asset + init_iso_result = [] + data = get_definitions(url) + data_assets: dict = data.get("assets") + url_list = [] + for asset in data_assets: + url_list.append(asset["browser_download_url"]) + + minimal = "minimal" + sha256sum = ".iso.sha256" + part = ".iso.z" + for edition in review_editions: + urls = [x for x in url_list if edition in x] + full_iso = [x for x in urls if minimal not in x] + minimal_iso = [x for x in urls if minimal in x] + f_part = [x for x in full_iso if part in x] + f_256sum = [x for x in full_iso if sha256sum in x] + m_part = [x for x in minimal_iso if part in x] + m_256sum = [x for x in minimal_iso if sha256sum in x] + result = {"name": edition, + "full": {"img": f_part, "shasum": f_256sum[0]}, + "minimal": {"img": m_part, "shasum": m_256sum[0]}} + init_iso_result.append(result) + + return init_iso_result def download_file(url: str, folder_name: str) -> bool: @@ -28,7 +65,6 @@ def download_file(url: str, folder_name: str) -> bool: block_size = 1024 if total_size_in_bytes < block_size: block_size = total_size_in_bytes - with open(path, "wb") as f: progress = 0 for data in response.iter_content(block_size): @@ -37,10 +73,9 @@ def download_file(url: str, folder_name: str) -> bool: progress += len(data) else: progress += block_size - print(f"Receiving <- {progress}/{total_size_in_bytes}", end="\r") - + print(f"Downloading {round(progress/1024/1024)}MiB of {round(total_size_in_bytes/1024/1024)}MiB", end="\r") except Exception as e: - print(e) + print(f"{e}") return False return True @@ -56,10 +91,17 @@ def get_definitions(url: str) -> dict: return iso_def -def init_iso_list(url: str) -> List: +def init_iso_list(url: str, review: bool = False) -> list: + if review: + return init_review_iso_list(url) + + return init_official_iso_list(url) + + +def init_official_iso_list(url: str) -> list: data = get_definitions(url) - data_official = data.get("official") - data_community = data.get("community") + data_official: dict = data.get("official") + data_community: dict = data.get("community") init_iso_result = [] for ok, ov in data_official.items(): try: @@ -69,7 +111,6 @@ def init_iso_list(url: str) -> List: }) except: continue - for ck, cv in data_community.items(): try: init_iso_result.append({"name": ck, @@ -78,18 +119,17 @@ def init_iso_list(url: str) -> List: }) except: continue - return init_iso_result def download(url: str) -> bool: - print(f'Downloading: {url.split("/")[-1]}') + print(f'Download: {url.split("/")[-1]}') success = download_file(url, f"{FOLDER}") return success def main(): - iso_files = init_iso_list(DEF_URL) + iso_files = init_iso_list(DEF_URL, review=False) choices = [] for c in iso_files: choices.append(c["name"]) @@ -105,26 +145,59 @@ def main(): required=False, action="store_true", help="Download full ISO") + parser.add_argument("-r", "--review", + required=False, + action="store_true", + help="Get Release Review ISO") args = parser.parse_args() - if args.edition is None: - parser.print_usage() - edition = [x for x in iso_files if args.edition == x["name"]] - for x in edition: - if args.full: - iso = x["full"] + + if args.review is not None: + if args.edition in review_editions: + iso_files = init_iso_list(REVIEW_URL, review=True) else: - iso = x["minimal"] + print("Invalid review edition. Valid editions: " + ", ".join(review_editions)) + sys.exit(1) + + edition = [x for x in iso_files if args.edition == x["name"]] + + if args.full: + iso = edition[0]["full"] + else: + iso = edition[0]["minimal"] + + if args.review: + sha_result = download(iso["shasum"]) + shaname = iso["shasum"].split("/")[-1] + isozip = [x for x in iso["img"] if ".iso.zip" in x] + zipname = isozip[0].split("/")[-1] + zip_result = False + for part in iso["img"]: + zip_result = download(part) + if not zip_result: + break + + if zip_result and sha_result: + subprocess.run(["7z", "-y", "x", f"{zipname}"], cwd=f"{FOLDER}") + subprocess.run(["7z", "-y", "t", f"{zipname}"], cwd=f"{FOLDER}") + print("Wait for checksum to complete ...") + subprocess.run(["sha256sum", "-c", f"{shaname}"], cwd=f"{FOLDER}") + time.sleep(5) + else: + print("Download failied") + sys.exit(1) + + else: iso_result = download(iso["img"]) sig_result = download(iso["sig"]) + if sig_result and iso_result: - print("Wait for verification ...") + print("Wait for verification to complete ...") time.sleep(5) - result = subprocess.run( - ["gpg", "--verify", f'{iso["sig"].split("/")[-1]}'], - cwd=f"{FOLDER}") + subprocess.run(["gpg", "--verify", f'{iso["sig"].split("/")[-1]}'], cwd=f"{FOLDER}") else: - print("Download ISO failed") - sys.exit(0) + print("Download failed") + sys.exit(1) + sys.exit(0) From ca0fb8e023a75d696faf7f52b13f54667902e6fc Mon Sep 17 00:00:00 2001 From: Frede Hundewadt Date: Thu, 7 Dec 2023 08:05:57 +0100 Subject: [PATCH 2/6] Update get-iso --- get-iso | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/get-iso b/get-iso index fa73c75..68e25f9 100755 --- a/get-iso +++ b/get-iso @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # # @linux-aarhus - root.nix.dk -# License: GNU GPL, version 3 or later; https://www.gnu.org/licenses/gpl.html +# License: GNU GPL, version 3 or later; import argparse import shutil import subprocess @@ -17,7 +17,7 @@ from pathlib import Path DEF_URL = "https://gitlab.manjaro.org/webpage/iso-info/-/raw/master/file-info.json" FOLDER = Path.home() PROG_NAME = os.path.basename(__file__) -PROG_VERSION = "0.2" +PROG_VERSION = "0.3" GNU_URL = "https://www.gnu.org/licenses/gpl.html" REVIEW_URL = "https://api.github.com/repos/manjaro/release-review/releases/latest" review_editions = ["gnome", "kde", "xfce"] @@ -181,7 +181,6 @@ def main(): subprocess.run(["7z", "-y", "t", f"{zipname}"], cwd=f"{FOLDER}") print("Wait for checksum to complete ...") subprocess.run(["sha256sum", "-c", f"{shaname}"], cwd=f"{FOLDER}") - time.sleep(5) else: print("Download failied") sys.exit(1) @@ -193,7 +192,8 @@ def main(): if sig_result and iso_result: print("Wait for verification to complete ...") time.sleep(5) - subprocess.run(["gpg", "--verify", f'{iso["sig"].split("/")[-1]}'], cwd=f"{FOLDER}") + subprocess.run(["gpg", "--verify", f'{iso["sig"].split("/")[-1]}'], + cwd=f"{FOLDER}") else: print("Download failed") sys.exit(1) From 885726c74daf65c611a6d91015271083a1740160 Mon Sep 17 00:00:00 2001 From: Frede Hundewadt Date: Thu, 7 Dec 2023 08:26:36 +0100 Subject: [PATCH 3/6] Update get-iso --- get-iso | 54 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/get-iso b/get-iso index 68e25f9..d6432b5 100755 --- a/get-iso +++ b/get-iso @@ -1,10 +1,9 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python # -*- coding: utf-8 -*- # # @linux-aarhus - root.nix.dk # License: GNU GPL, version 3 or later; import argparse -import shutil import subprocess import sys import os @@ -14,12 +13,14 @@ import requests.exceptions from pathlib import Path -DEF_URL = "https://gitlab.manjaro.org/webpage/iso-info/-/raw/master/file-info.json" +DEF_URL = \ + "https://gitlab.manjaro.org/webpage/iso-info/-/raw/master/file-info.json" FOLDER = Path.home() PROG_NAME = os.path.basename(__file__) PROG_VERSION = "0.3" GNU_URL = "https://www.gnu.org/licenses/gpl.html" -REVIEW_URL = "https://api.github.com/repos/manjaro/release-review/releases/latest" +REVIEW_URL = \ + "https://api.github.com/repos/manjaro/release-review/releases/latest" review_editions = ["gnome", "kde", "xfce"] @@ -29,7 +30,8 @@ def init_review_iso_list(url: str) -> list: :param url: :return: """ - # from the assets list we want to extract the browser_download_url propoerty for each asset + # from the assets list we want to extract\ + # the browser_download_url propoerty for each asset init_iso_result = [] data = get_definitions(url) data_assets: dict = data.get("assets") @@ -73,7 +75,8 @@ def download_file(url: str, folder_name: str) -> bool: progress += len(data) else: progress += block_size - print(f"Downloading {round(progress/1024/1024)}MiB of {round(total_size_in_bytes/1024/1024)}MiB", end="\r") + print(f"Downloading {round(progress/1024/1024)}MiB of " + f"{round(total_size_in_bytes/1024/1024)}MiB", end="\r") except Exception as e: print(f"{e}") return False @@ -106,17 +109,28 @@ def init_official_iso_list(url: str) -> list: for ok, ov in data_official.items(): try: init_iso_result.append({"name": ok, - "full": {"img": ov["image"], "sig": ov["signature"]}, - "minimal": {"img": ov["minimal"]["image"], "sig": ov["minimal"]["signature"]} + "full": { + "img": ov["image"], + "sig": ov["signature"] + }, + "minimal": { + "img": ov["minimal"]["image"], + "sig": ov["minimal"]["signature"] + } }) except: continue for ck, cv in data_community.items(): try: init_iso_result.append({"name": ck, - "full": {"img": cv["image"], "sig": cv["signature"]}, - "minimal": {"img": cv["minimal"]["image"], "sig": cv["minimal"]["signature"]} - }) + "full": { + "img": cv["image"], + "sig": cv["signature"] + }, + "minimal": { + "img": cv["minimal"]["image"], + "sig": cv["minimal"]["signature"] + }}) except: continue return init_iso_result @@ -135,11 +149,11 @@ def main(): choices.append(c["name"]) parser = argparse.ArgumentParser( prog=f"{PROG_NAME}", - description="This tool will download a named Manjaro ISO and verify the signature", + description="This tool will download a named Manjaro ISO", epilog=f"{PROG_NAME} v. {PROG_VERSION} - GPL v3 or later <{GNU_URL}>") parser.add_argument("edition", type=str, - help="edition e.g. plasma or xfce", + help="Edition e.g. plasma or xfce.", choices=choices) parser.add_argument("-f", "--full", required=False, @@ -152,10 +166,13 @@ def main(): args = parser.parse_args() if args.review is not None: + if args.edition == "plasma": + args.edition = "kde" if args.edition in review_editions: iso_files = init_iso_list(REVIEW_URL, review=True) else: - print("Invalid review edition. Valid editions: " + ", ".join(review_editions)) + print("Invalid review edition. Valid editions: " + + ", ".join(review_editions)) sys.exit(1) edition = [x for x in iso_files if args.edition == x["name"]] @@ -177,10 +194,13 @@ def main(): break if zip_result and sha_result: - subprocess.run(["7z", "-y", "x", f"{zipname}"], cwd=f"{FOLDER}") - subprocess.run(["7z", "-y", "t", f"{zipname}"], cwd=f"{FOLDER}") + subprocess.run(["7z", "-y", "x", f"{zipname}"], + cwd=f"{FOLDER}") + subprocess.run(["7z", "-y", "t", f"{zipname}"], + cwd=f"{FOLDER}") print("Wait for checksum to complete ...") - subprocess.run(["sha256sum", "-c", f"{shaname}"], cwd=f"{FOLDER}") + subprocess.run(["sha256sum", "-c", f"{shaname}"], + cwd=f"{FOLDER}") else: print("Download failied") sys.exit(1) From a21252cfc6b3d82530b118f6f9fa639d1018ab14 Mon Sep 17 00:00:00 2001 From: Frede Hundewadt Date: Thu, 7 Dec 2023 08:32:56 +0100 Subject: [PATCH 4/6] Update get-iso --- get-iso | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/get-iso b/get-iso index d6432b5..307678c 100755 --- a/get-iso +++ b/get-iso @@ -12,12 +12,11 @@ import time import requests.exceptions from pathlib import Path - +PROG_VERSION = "0.4" DEF_URL = \ "https://gitlab.manjaro.org/webpage/iso-info/-/raw/master/file-info.json" FOLDER = Path.home() PROG_NAME = os.path.basename(__file__) -PROG_VERSION = "0.3" GNU_URL = "https://www.gnu.org/licenses/gpl.html" REVIEW_URL = \ "https://api.github.com/repos/manjaro/release-review/releases/latest" @@ -226,4 +225,4 @@ if __name__ == '__main__': main() except KeyboardInterrupt: print("\n" + "Exit: interrupted by the user.") - sys.exit(1) + sys.exit(1) \ No newline at end of file From f6eeaa1e70579c591e2d393848c6dde59677a8e6 Mon Sep 17 00:00:00 2001 From: Frede Hundewadt Date: Thu, 7 Dec 2023 08:33:11 +0100 Subject: [PATCH 5/6] Update get-iso --- get-iso | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/get-iso b/get-iso index 307678c..77f2abb 100755 --- a/get-iso +++ b/get-iso @@ -225,4 +225,4 @@ if __name__ == '__main__': main() except KeyboardInterrupt: print("\n" + "Exit: interrupted by the user.") - sys.exit(1) \ No newline at end of file + sys.exit(1) From 68a36245d54afb065f2a22cd217fe89ac90567aa Mon Sep 17 00:00:00 2001 From: Frede Hundewadt Date: Thu, 7 Dec 2023 08:48:24 +0100 Subject: [PATCH 6/6] Update get-iso --- get-iso | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/get-iso b/get-iso index 77f2abb..51cb620 100755 --- a/get-iso +++ b/get-iso @@ -12,11 +12,12 @@ import time import requests.exceptions from pathlib import Path -PROG_VERSION = "0.4" + DEF_URL = \ "https://gitlab.manjaro.org/webpage/iso-info/-/raw/master/file-info.json" FOLDER = Path.home() PROG_NAME = os.path.basename(__file__) +PROG_VERSION = "0.5" GNU_URL = "https://www.gnu.org/licenses/gpl.html" REVIEW_URL = \ "https://api.github.com/repos/manjaro/release-review/releases/latest" @@ -193,11 +194,11 @@ def main(): break if zip_result and sha_result: - subprocess.run(["7z", "-y", "x", f"{zipname}"], - cwd=f"{FOLDER}") subprocess.run(["7z", "-y", "t", f"{zipname}"], cwd=f"{FOLDER}") - print("Wait for checksum to complete ...") + subprocess.run(["7z", "-y", "x", f"{zipname}"], + cwd=f"{FOLDER}") + print("\nWait for checksum to complete ...") subprocess.run(["sha256sum", "-c", f"{shaname}"], cwd=f"{FOLDER}") else: