Skip to content

Commit 7c3d5e1

Browse files
committed
recipe: Completing comparison via md5sum
If the md5sum doesn't fit, the code will retry to compare the md5sum. If it still doesn't fit the code will exit(1) at the end.
1 parent 0478279 commit 7c3d5e1

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

pythonforandroid/recipe.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from urlparse import urlparse
1515
except ImportError:
1616
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)
1818
from pythonforandroid.util import (urlretrieve, current_directory, ensure_dir)
1919

2020
# this import is necessary to keep imp.load_source from complaining :)
@@ -360,11 +360,15 @@ def download(self):
360360
if not exists(marker_filename):
361361
shprint(sh.rm, filename)
362362
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+
368372
else:
369373
do_download = False
370374
info('{} download already cached, skipping'
@@ -375,18 +379,22 @@ def download(self):
375379

376380
# If we got this far, we will download
377381
if do_download:
378-
print('Downloading {} from {}'.format(self.name, url))
382+
debug('Downloading {} from {}'.format(self.name, url))
379383

380384
shprint(sh.rm, '-f', marker_filename)
381385
self.download_file(url, filename)
382386
shprint(sh.touch, marker_filename)
383387

384388
if exists(filename) and isfile(filename) and self.md5sum:
389+
current_md5 = shprint(sh.md5sum, filename).split()[0]
385390
if self.md5sum is not None:
386-
print('downloaded md5: {}'.format(current_md5))
387-
print('expected md5: {}'.format(self.md5sum))
388-
print('md5 not handled yet, exiting')
389-
exit(1)
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)
390398

391399
def unpack(self, arch):
392400
info_main('Unpacking {} for {}'.format(self.name, arch))

0 commit comments

Comments
 (0)