Skip to content

Functions

src.utils.download.download_cloudfront(url: yarl.URL, path: Path, callback: Optional[Callable] = None) -> bool

Download a template from cloudfront cached Amazon S3 bucket.

Parameters:

Name Type Description Default
url URL

URL to S3/cloudfront hosted file.

required
path Path

Path to save the archive.

required
callback Callable | None

Callback function to update progress.

None

Returns:

Type Description
bool

True if download is successful, otherwise False.

Source code in src\utils\download.py
def download_cloudfront(url: yarl.URL, path: Path, callback: Optional[Callable] = None) -> bool:
    """Download a template from cloudfront cached Amazon S3 bucket.

    Args:
        url: URL to S3/cloudfront hosted file.
        path: Path to save the archive.
        callback: Callback function to update progress.

    Returns:
        True if download is successful, otherwise False.
    """
    # Get a temp file
    temp_path = get_temporary_file(path=path, ext='.amzn')

    # Start the download
    try:
        download_file(
            url=url,
            path=temp_path,
            callback=callback)
        shutil.move(temp_path, path)
        unpack_archive(path)
    except (requests.RequestException, FileExistsError, FileNotFoundError):
        return False
    return True