import logging
import requests
import hashlib


def fetch_tarball_sha256(url):
    """ Get the sha256 of a tarball """
    logging.info("Fetching tarball from {}...".format(url))
    response = requests.get(url, stream=True)
    sha256 = hashlib.sha256()
    for chunk in response.iter_content(chunk_size=1024 * 1024):
        sha256.update(chunk)
    hex_hash = sha256.hexdigest()
    logging.info("Downloaded {} with hash {}".format(url, hex_hash))
    return hex_hash