How to use the pooch.utils.hash_matches function in pooch

To help you get started, we’ve selected a few pooch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fatiando / pooch / pooch / core.py View on Github external
Returns
    -------
    action, verb : str
        The action that must be taken and the English verb (infinitive form of
        *action*) used in the log:
        * ``'download'``: File does not exist locally and must be downloaded.
        * ``'update'``: File exists locally but needs to be updated.
        * ``'fetch'``: File exists locally and only need to inform its path.


    """
    if not path.exists():
        action = "download"
        verb = "Downloading"
    elif not hash_matches(str(path), known_hash):
        action = "update"
        verb = "Updating"
    else:
        action = "fetch"
        verb = "Fetching"
    return action, verb
github fatiando / pooch / pooch / core.py View on Github external
The file is first downloaded to a temporary file name in the cache folder.
    It will be moved to the desired file name only if the hash matches the
    known hash. Otherwise, the temporary file is deleted.

    """
    # Ensure the parent directory exists in case the file is in a subdirectory.
    # Otherwise, move will cause an error.
    if not fname.parent.exists():
        os.makedirs(str(fname.parent))

    # Stream the file to a temporary so that we can safely check its hash
    # before overwriting the original.
    with temporary_file(path=str(fname.parent)) as tmp:
        downloader(url, tmp, pooch)
        hash_matches(tmp, known_hash, strict=True, source=str(fname.name))
        shutil.move(tmp, str(fname))