refactor(Mainsail): remove mainsail.zip after extracting content

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
dw-0
2023-12-25 20:16:38 +01:00
parent b69ecbc9b5
commit b4f5c3c1ac
2 changed files with 7 additions and 9 deletions

View File

@@ -147,11 +147,13 @@ def run_mainsail_installation() -> None:
def download_mainsail() -> None: def download_mainsail() -> None:
try: try:
Logger.print_status("Downloading Mainsail ...") 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_ok("Download complete!")
Logger.print_status("Extracting mainsail.zip ...") Logger.print_status("Extracting mainsail.zip ...")
unzip(Path.home().joinpath("mainsail.zip"), MAINSAIL_DIR) unzip(Path.home().joinpath("mainsail.zip"), MAINSAIL_DIR)
target.unlink(missing_ok=True)
Logger.print_ok("OK!") Logger.print_ok("OK!")
except Exception: except Exception:

View File

@@ -246,24 +246,20 @@ def get_ipv4_addr() -> str:
s.close() s.close()
def download_file( def download_file(url: str, target: Path, show_progress=True) -> None:
url: str, target_folder: Path, target_name: str, show_progress=True
) -> None:
""" """
Helper method for downloading files from a provided URL | Helper method for downloading files from a provided URL |
:param url: the url to the file :param url: the url to the file
:param target_folder: the target folder to download the file into :param target: the target path incl filename
:param target_name: the name of the downloaded file
:param show_progress: show download progress or not :param show_progress: show download progress or not
:return: None :return: None
""" """
target_path = target_folder.joinpath(target_name)
try: try:
if show_progress: if show_progress:
urllib.request.urlretrieve(url, target_path, download_progress) urllib.request.urlretrieve(url, target, download_progress)
sys.stdout.write("\n") sys.stdout.write("\n")
else: else:
urllib.request.urlretrieve(url, target_path) urllib.request.urlretrieve(url, target)
except urllib.error.HTTPError as e: except urllib.error.HTTPError as e:
Logger.print_error(f"Download failed! HTTP error occured: {e}") Logger.print_error(f"Download failed! HTTP error occured: {e}")
raise raise