14
14
from urlparse import urlparse
15
15
except ImportError :
16
16
from urllib .parse import urlparse
17
- from pythonforandroid .logger import (logger , info , warning , error , shprint , info_main )
17
+ from pythonforandroid .logger import (logger , info , warning , error , debug , shprint , info_main )
18
18
from pythonforandroid .util import (urlretrieve , current_directory , ensure_dir )
19
19
20
20
# this import is necessary to keep imp.load_source from complaining :)
@@ -360,11 +360,15 @@ def download(self):
360
360
if not exists (marker_filename ):
361
361
shprint (sh .rm , filename )
362
362
elif self .md5sum :
363
- current_md5 = shprint (sh .md5sum , filename )
364
- print ('downloaded md5: {}' .format (current_md5 ))
365
- print ('expected md5: {}' .format (self .md5sum ))
366
- print ('md5 not handled yet, exiting' )
367
- exit (1 )
363
+ current_md5 = shprint (sh .md5sum , filename ).split ()[0 ]
364
+ if current_md5 == self .md5sum :
365
+ debug ('Downloaded expected content!' )
366
+ do_download = False
367
+ else :
368
+ info ('Downloaded unexpected content...' )
369
+ debug ('* Generated md5sum: {}' .format (current_md5 ))
370
+ debug ('* Expected md5sum: {}' .format (self .md5sum ))
371
+
368
372
else :
369
373
do_download = False
370
374
info ('{} download already cached, skipping'
@@ -375,17 +379,22 @@ def download(self):
375
379
376
380
# If we got this far, we will download
377
381
if do_download :
378
- print ('Downloading {} from {}' .format (self .name , url ))
382
+ debug ('Downloading {} from {}' .format (self .name , url ))
379
383
380
384
shprint (sh .rm , '-f' , marker_filename )
381
385
self .download_file (url , filename )
382
386
shprint (sh .touch , marker_filename )
383
387
384
- if self .md5sum is not None :
385
- print ('downloaded md5: {}' .format (current_md5 ))
386
- print ('expected md5: {}' .format (self .md5sum ))
387
- print ('md5 not handled yet, exiting' )
388
- exit (1 )
388
+ if exists (filename ) and isfile (filename ) and self .md5sum :
389
+ current_md5 = shprint (sh .md5sum , filename ).split ()[0 ]
390
+ if self .md5sum is not None :
391
+ if current_md5 == self .md5sum :
392
+ debug ('Downloaded expected content!' )
393
+ else :
394
+ info ('Downloaded unexpected content...' )
395
+ debug ('* Generated md5sum: {}' .format (current_md5 ))
396
+ debug ('* Expected md5sum: {}' .format (self .md5sum ))
397
+ exit (1 )
389
398
390
399
def unpack (self , arch ):
391
400
info_main ('Unpacking {} for {}' .format (self .name , arch ))
0 commit comments