Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.logger.info(
"Download will resume from existing incomplete file %s.", temp_path
)
pass
if not skip_download:
# Store the number of downloaded bytes for unit tests
product_info["downloaded_bytes"] = self._download(
product_info["url"], temp_path, self.session, product_info["size"]
)
# Check integrity with MD5 checksum
if checksum is True:
if not self._md5_compare(temp_path, product_info["md5"]):
remove(temp_path)
raise InvalidChecksumError("File corrupt: checksums do not match")
# Download successful, rename the temporary file to its proper name
shutil.move(temp_path, path)
return product_info
Returns
-------
dict or None:
Either dictionary containing the product's info or if the product is not online just None
"""
last_exception = None
if self.is_online(product_info["id"]):
self.logger.info("%s is online. Starting download", product_info["id"])
for cnt in range(max_attempts):
try:
ret_val = self.download(product_info["id"], directory_path, checksum)
break
except InvalidChecksumError as e:
self.logger.warning(
"Invalid checksum. The downloaded file for '%s' is corrupted.",
product_info["id"],
)
last_exception = e
except Exception as e:
self.logger.exception("There was an error downloading %s", product_info["id"])
self.logger.info("%d retries left", max_attempts - cnt - 1)
last_exception = e
else:
self.logger.info("No retries left for %s. Terminating.", product_info["id"])
raise last_exception
else:
self.logger.info("%s is not online.", product_info["id"])
ret_val = None