diff options
| author | Florian Fischer <florian.fl.fischer@fau.de> | 2019-09-29 15:35:02 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fl.fischer@fau.de> | 2019-09-29 15:35:02 +0200 |
| commit | 059d263a6b944c4cfc5a5a0f2716e6a85116cfc1 (patch) | |
| tree | 8169cefa09e08dab87f2f94967dc5a80ee2b425a /src/util.py | |
| parent | e9f41e9e3ef8f6d35dda10c6c58d77b52d577e8a (diff) | |
| parent | 3f43d0f464b8da5829ff652a3208720c74d1882b (diff) | |
| download | allocbench-059d263a6b944c4cfc5a5a0f2716e6a85116cfc1.tar.gz allocbench-059d263a6b944c4cfc5a5a0f2716e6a85116cfc1.zip | |
Merge branch 'artifact'
Diffstat (limited to 'src/util.py')
| -rw-r--r-- | src/util.py | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/util.py b/src/util.py index b44a263..c5fa162 100644 --- a/src/util.py +++ b/src/util.py @@ -17,24 +17,13 @@ """Helper functions for allocbench""" +import hashlib import os import subprocess import sys import src.globalvars -def download_reporthook(blocknum, blocksize, totalsize): - """Status report hook for urlretrieve""" - readsofar = blocknum * blocksize - if totalsize > 0: - percent = readsofar * 100 / totalsize - status = "\r%5.1f%% %*d / %d" % ( - percent, len(str(totalsize)), readsofar, totalsize) - sys.stderr.write(status) - else: # total size is unknown - sys.stderr.write(f"\rdownloaded {readsofar}") - - def is_exe(fpath): """Check if the given path is an exexutable file""" return os.path.isfile(fpath) and os.access(fpath, os.X_OK) @@ -173,3 +162,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() |
