/usr/share/pyshared/juju/lib/filehash.py is in juju-0.7 0.7-0ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | def compute_file_hash(hash_type, filename):
"""Simple helper to compute the digest of a file.
@param hash_type: A class like hashlib.sha256.
@param filename: File path to compute the digest from.
"""
hash = hash_type()
with open(filename) as file:
# Chunk the digest extraction to avoid loading large
# files in memory unnecessarily.
while True:
chunk = file.read(8192)
if not chunk:
break
hash.update(chunk)
return hash.hexdigest()
|