def get_hash(path, form='sha1', chunk_size=4096):
    try:
        hash_type = getattr(hashlib, form)
    except AttributeError:
        raise ValueError('Invalid hash type: {0}'.format(form))
    with open(path, 'rb') as ifile:
        hash_obj = hash_type()
        # read the file in in chunks, not the entire file
        for chunk in iter(lambda: ifile.read(chunk_size), b''):
            hash_obj.update(chunk)
        return hash_obj.hexdigest()
Generate a hash digest string for a file.
dataset/ETHPy150Open saltstack/salt/salt/client/ssh/ssh_py_shim.py/get_hash