From 201e2a033623aae23682c38398ee83b98fd75ff5 Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Mon, 16 Mar 2015 11:29:50 +0100 Subject: [PATCH] New method to compute md5 hash of file Signed-off-by: Vojtech Trefny --- blivet/util.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/blivet/util.py b/blivet/util.py index 5c1385817..9a6541dc9 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.