From cac85412d757b6054436dc9c63d30db645bc93ea Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Sun, 22 Sep 2019 18:35:47 +0200 Subject: Add ArchiveArtifacts ArchiveArtifacts check a downloaded archive against a provided checksum. The Archive is downloaded to cache//.. The only suported format is tar. ArchiveArtifacts can be used as sources of an Allocator. --- src/util.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/util.py') diff --git a/src/util.py b/src/util.py index 027cbcb..8b9e585 100644 --- a/src/util.py +++ b/src/util.py @@ -17,6 +17,7 @@ """Helper functions for allocbench""" +import hashlib import os import subprocess import sys @@ -173,3 +174,13 @@ def print_version_and_exit(): print(f"{commit}{dirty}") exit(0) + +def sha1sum(filename): + """Return sha1sum of a file""" + sha1 = hashlib.sha1() + barray = bytearray(64*1024) + view = memoryview(barray) + with open(filename, 'rb', buffering=0) as f: + for n in iter(lambda : f.readinto(view), 0): + sha1.update(view[:n]) + return sha1.hexdigest() -- cgit v1.2.3