55from shutil import rmtree
66from six import PY2 , with_metaclass
77
8+ import hashlib
9+
810import sh
911import shutil
1012import fnmatch
@@ -360,9 +362,9 @@ def download(self):
360362 if not exists (marker_filename ):
361363 shprint (sh .rm , filename )
362364 elif self .md5sum :
363- current_md5 = shprint ( sh . md5sum , filename ). split ()[ 0 ]
365+ current_md5 = md5sum ( filename )
364366 if current_md5 == self .md5sum :
365- debug ('Downloaded expected content!' )
367+ debug ('Checked md5sum: downloaded expected content!' )
366368 do_download = False
367369 else :
368370 info ('Downloaded unexpected content...' )
@@ -386,10 +388,10 @@ def download(self):
386388 shprint (sh .touch , marker_filename )
387389
388390 if exists (filename ) and isfile (filename ) and self .md5sum :
389- current_md5 = shprint ( sh . md5sum , filename ). split ()[ 0 ]
391+ current_md5 = md5sum ( filename )
390392 if self .md5sum is not None :
391393 if current_md5 == self .md5sum :
392- debug ('Downloaded expected content!' )
394+ debug ('Checked md5sum: downloaded expected content!' )
393395 else :
394396 info ('Downloaded unexpected content...' )
395397 debug ('* Generated md5sum: {}' .format (current_md5 ))
@@ -1102,3 +1104,12 @@ def prebuild_arch(self, arch):
11021104 # def ctx(self, ctx):
11031105 # self._ctx = ctx
11041106 # ctx.python_recipe = self
1107+
1108+
1109+ def md5sum (filen ):
1110+ '''Calculate the md5sum of a file.
1111+ '''
1112+ with open (filen , 'rb' ) as fileh :
1113+ md5 = hashlib .md5 (fileh .read ())
1114+
1115+ return md5 .hexdigest ()
0 commit comments