apenwarr-redo/docs/cookbook/container/default.sha256.do
Avery Pennarun fb0a5bd69c Fix more problems with "/usr/bin/env python" picking python3.
Open files in 'rb' (read binary) mode to prevent useless default utf8
encoding in python3, without breaking python2 compatibility.

Reported-by: Tharre <tharre3@gmail.com>
2019-05-15 16:54:21 -07:00

16 lines
360 B
Text

#!/usr/bin/env python
"""Calculate the sha256 digest of a given file."""
import hashlib, os, subprocess, sys
subprocess.check_call([
'redo-ifchange',
sys.argv[2],
], close_fds=False)
h = hashlib.sha256()
f = open(sys.argv[2], 'rb')
while 1:
b = f.read(65536)
if not b: break
h.update(b)
open(sys.argv[3], 'w').write(h.hexdigest() + '\n')