diff options
Diffstat (limited to 'python/servo/util.py')
-rw-r--r-- | python/servo/util.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/python/servo/util.py b/python/servo/util.py index 2043b0e2868..a4e126d3240 100644 --- a/python/servo/util.py +++ b/python/servo/util.py @@ -9,6 +9,7 @@ from __future__ import absolute_import, print_function, unicode_literals +import hashlib import os import os.path import platform @@ -165,3 +166,15 @@ def extract(src, dst, movedir=None): os.rmdir(movedir) os.remove(src) + +def check_hash(filename, expected, algorithm): + hasher = hashlib.new(algorithm) + with open(filename, "rb") as f: + while True: + block = f.read(16 * 1024) + if len(block) == 0: + break + hasher.update(block) + if hasher.hexdigest() != expected: + print("Incorrect {} hash for {}".format(algorithm, filename)) + sys.exit(1) |