commit d3dd720293a44a43331f6316bea33f2bab609880
Author: Radek Pazdera <rpazdera(a)redhat.com>
Date: Thu Nov 8 16:17:43 2012 +0100
Utils: Adding md5sum function
This function can be used to compute a hash of a file.
Signed-off-by: Radek Pazdera <rpazdera(a)redhat.com>
Common/Utils.py | 12 ++++++++++++
1 files changed, 12 insertions(+), 0 deletions(-)
---
diff --git a/Common/Utils.py b/Common/Utils.py
index bae3043..8d00a00 100644
--- a/Common/Utils.py
+++ b/Common/Utils.py
@@ -12,6 +12,7 @@ jzupka(a)redhat.com (Jiri Zupka)
import logging
import time
import re
+import hashlib
def die_when_parent_die():
try:
@@ -85,3 +86,14 @@ def bool_it(val):
elif re.match("^\s*(?i)(false)", val):
return False
return True if int_it(val) else False
+
+def md5sum(file_path, block_size=2**20):
+ md5 = hashlib.md5()
+ with open(file_path, "rb") as f:
+ while True:
+ data = f.read(block_size)
+ if not data:
+ break
+ md5.update(data)
+
+ return md5.hexdigest()