Skip to content

Commit

Permalink
New method to compute md5 hash of file
Browse files Browse the repository at this point in the history
Signed-off-by: Vojtech Trefny <vtrefny@redhat.com>
  • Loading branch information
vojtechtrefny committed Mar 18, 2015
1 parent 796351c commit 201e2a0
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions blivet/util.py
Expand Up @@ -9,6 +9,7 @@
import sys
import tempfile
import uuid
import hashlib
from decimal import Decimal
from contextlib import contextmanager

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 201e2a0

Please sign in to comment.