From b4f5c3c1ace8635c002b09be8fcaf1c4b225159d Mon Sep 17 00:00:00 2001 From: dw-0 Date: Mon, 25 Dec 2023 20:16:38 +0100 Subject: [PATCH] refactor(Mainsail): remove mainsail.zip after extracting content Signed-off-by: Dominik Willner --- kiauh/modules/mainsail/mainsail_setup.py | 4 +++- kiauh/utils/system_utils.py | 12 ++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/kiauh/modules/mainsail/mainsail_setup.py b/kiauh/modules/mainsail/mainsail_setup.py index 758c39a..cb0e85e 100644 --- a/kiauh/modules/mainsail/mainsail_setup.py +++ b/kiauh/modules/mainsail/mainsail_setup.py @@ -147,11 +147,13 @@ def run_mainsail_installation() -> None: def download_mainsail() -> None: try: Logger.print_status("Downloading Mainsail ...") - download_file(MAINSAIL_URL, Path.home(), "mainsail.zip") + target = Path.home().joinpath("mainsail.zip") + download_file(MAINSAIL_URL, target, True) Logger.print_ok("Download complete!") Logger.print_status("Extracting mainsail.zip ...") unzip(Path.home().joinpath("mainsail.zip"), MAINSAIL_DIR) + target.unlink(missing_ok=True) Logger.print_ok("OK!") except Exception: diff --git a/kiauh/utils/system_utils.py b/kiauh/utils/system_utils.py index be317ea..5d7292e 100644 --- a/kiauh/utils/system_utils.py +++ b/kiauh/utils/system_utils.py @@ -246,24 +246,20 @@ def get_ipv4_addr() -> str: s.close() -def download_file( - url: str, target_folder: Path, target_name: str, show_progress=True -) -> None: +def download_file(url: str, target: Path, show_progress=True) -> None: """ Helper method for downloading files from a provided URL | :param url: the url to the file - :param target_folder: the target folder to download the file into - :param target_name: the name of the downloaded file + :param target: the target path incl filename :param show_progress: show download progress or not :return: None """ - target_path = target_folder.joinpath(target_name) try: if show_progress: - urllib.request.urlretrieve(url, target_path, download_progress) + urllib.request.urlretrieve(url, target, download_progress) sys.stdout.write("\n") else: - urllib.request.urlretrieve(url, target_path) + urllib.request.urlretrieve(url, target) except urllib.error.HTTPError as e: Logger.print_error(f"Download failed! HTTP error occured: {e}") raise