5
5
from shutil import rmtree
6
6
from six import PY2 , with_metaclass
7
7
8
+ import hashlib
9
+
8
10
import sh
9
11
import shutil
10
12
import fnmatch
@@ -360,9 +362,9 @@ def download(self):
360
362
if not exists (marker_filename ):
361
363
shprint (sh .rm , filename )
362
364
elif self .md5sum :
363
- current_md5 = shprint ( sh . md5sum , filename ). split ()[ 0 ]
365
+ current_md5 = md5sum ( filename )
364
366
if current_md5 == self .md5sum :
365
- debug ('Downloaded expected content!' )
367
+ debug ('Checked md5sum: downloaded expected content!' )
366
368
do_download = False
367
369
else :
368
370
info ('Downloaded unexpected content...' )
@@ -386,10 +388,10 @@ def download(self):
386
388
shprint (sh .touch , marker_filename )
387
389
388
390
if exists (filename ) and isfile (filename ) and self .md5sum :
389
- current_md5 = shprint ( sh . md5sum , filename ). split ()[ 0 ]
391
+ current_md5 = md5sum ( filename )
390
392
if self .md5sum is not None :
391
393
if current_md5 == self .md5sum :
392
- debug ('Downloaded expected content!' )
394
+ debug ('Checked md5sum: downloaded expected content!' )
393
395
else :
394
396
info ('Downloaded unexpected content...' )
395
397
debug ('* Generated md5sum: {}' .format (current_md5 ))
@@ -1102,3 +1104,12 @@ def prebuild_arch(self, arch):
1102
1104
# def ctx(self, ctx):
1103
1105
# self._ctx = ctx
1104
1106
# 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