[master 2/6] New method to compute md5 hash of file

vojtechtrefny installerbot-noreply at redhat.com
Thu Mar 19 13:20:32 UTC 2015


From: Vojtech Trefny <vtrefny at redhat.com>

Signed-off-by: Vojtech Trefny <vtrefny at redhat.com>
---
 blivet/util.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/blivet/util.py b/blivet/util.py
index 5c13858..9a6541d 100644
--- a/blivet/util.py
+++ b/blivet/util.py
@@ -9,6 +9,7 @@
 import sys
 import tempfile
 import uuid
+import hashlib
 from decimal import Decimal
 from contextlib import contextmanager
 
@@ -357,6 +358,18 @@ def insert_colons(a_string):
     else:
         return suffix
 
+def md5_file(filename):
+
+    md5 = hashlib.md5()
+    with open(filename, "rb") as f:
+
+        block = f.read(65536)
+        while block:
+            md5.update(block)
+            block = f.read(65536)
+
+    return md5.hexdigest()
+
 class ObjectID(object):
     """This class is meant to be extended by other classes which require
        an ID which is preserved when an object copy is made.


-- 
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/201e2a033623aae23682c38398ee83b98fd75ff5


More information about the anaconda-patches mailing list