aboutsummaryrefslogtreecommitdiff
path: root/src/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.py')
-rw-r--r--src/util.py23
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()