diff --git a/modules/updaters/Rescuezilla.py b/modules/updaters/Rescuezilla.py index cc22ad6..cd938a9 100644 --- a/modules/updaters/Rescuezilla.py +++ b/modules/updaters/Rescuezilla.py @@ -40,7 +40,7 @@ def __init__(self, folder_path: Path, edition: str) -> None: @cache def _get_download_link(self) -> str: return self.release_info["files"][ - self._get_complete_normalized_file_path(absolute=False) + str(self._get_complete_normalized_file_path(absolute=False)) ] def check_integrity(self) -> bool: diff --git a/modules/utils.py b/modules/utils.py index 9af8111..f6fdb15 100644 --- a/modules/utils.py +++ b/modules/utils.py @@ -239,23 +239,38 @@ def download_file(url: str, local_file: Path, progress_bar: bool = True) -> None Returns: None """ - logging.debug(f"[download_file] Downloading {url} to {local_file.resolve()}") - with requests.get(url, stream=True) as r: - total_size = int(r.headers.get("content-length", 0)) # Sizes in bytes - - with open(local_file, "wb") as f: - if progress_bar: - with tqdm( - total=total_size, - unit="B", - desc=local_file.name, - ) as pbar: - for chunk in r.iter_content(chunk_size=1024): - if chunk: - f.write(chunk) - pbar.update(len(chunk)) - else: - shutil.copyfileobj(r.raw, f) + part_file = local_file.with_suffix(".part") + logging.debug(f"[download_file] Downloading {url} to {part_file.resolve()}") + + try: + with requests.get(url, stream=True) as r: + total_size = int(r.headers.get("content-length", 0)) # Sizes in bytes + + with open(part_file, "wb") as f: + if progress_bar: + with tqdm( + total=total_size, + unit="B", + desc=part_file.name, + ) as pbar: + for chunk in r.iter_content(chunk_size=1024): + if chunk: + f.write(chunk) + pbar.update(len(chunk)) + else: + shutil.copyfileobj(r.raw, f) + except requests.exceptions.RequestException: + logging.exception(f"Failed to download {url} to {part_file.resolve()}") + if part_file.exists(): + part_file.unlink() + raise + except KeyboardInterrupt: + logging.info(f"Download of {url} to {part_file.resolve()} was cancelled") + if part_file.exists(): + part_file.unlink() + raise + + part_file.rename(local_file) def windows_consumer_download( diff --git a/setup.py b/setup.py index e132c04..c4a1f75 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ setup( name="sisou", # Required - version="1.1.4", # Required + version="1.1.5", # Required description="A powerful tool to conveniently update all of your ISO files!", # Optional long_description=long_description, # Optional long_description_content_type="text/markdown", # Optional