Skip to content

Commit 1c77ea1

Browse files
committed
Merge branch 'local' of https://github.com/wexi/python-for-android into wexi-local
2 parents 129cbfa + 3e82aa9 commit 1c77ea1

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

pythonforandroid/recipe.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from six import PY2, with_metaclass
77

88
import hashlib
9+
from re import match
910

1011
import sh
1112
import shutil
@@ -349,51 +350,52 @@ def download(self):
349350
return
350351

351352
url = self.versioned_url
353+
ma = match(u'^(.+)#md5=([0-9a-f]{32})$', url)
354+
if ma: # fragmented URL?
355+
if self.md5sum:
356+
raise Exception('Recipe md5sum via fragmented URL only!')
357+
url = ma.group(1)
358+
expected_md5 = ma.group(2)
359+
else:
360+
expected_md5 = self.md5sum
352361

353362
shprint(sh.mkdir, '-p', join(self.ctx.packages_path, self.name))
354363

355364
with current_directory(join(self.ctx.packages_path, self.name)):
356365
filename = shprint(sh.basename, url).stdout[:-1].decode('utf-8')
357366

358367
do_download = True
359-
360368
marker_filename = '.mark-{}'.format(filename)
361369
if exists(filename) and isfile(filename):
362370
if not exists(marker_filename):
363371
shprint(sh.rm, filename)
364-
elif self.md5sum:
372+
elif expected_md5:
365373
current_md5 = md5sum(filename)
366-
if current_md5 == self.md5sum:
367-
debug('Checked md5sum: downloaded expected content!')
368-
do_download = False
369-
else:
370-
info('Downloaded unexpected content...')
374+
if current_md5 != expected_md5:
371375
debug('* Generated md5sum: {}'.format(current_md5))
372-
debug('* Expected md5sum: {}'.format(self.md5sum))
373-
376+
debug('* Expected md5sum: {}'.format(expected_md5))
377+
raise Exception('Cached unexpected content!')
378+
do_download = False
374379
else:
375380
do_download = False
376-
info('{} download already cached, skipping'
377-
.format(self.name))
378381

379382
# If we got this far, we will download
380383
if do_download:
381384
debug('Downloading {} from {}'.format(self.name, url))
382385

383386
shprint(sh.rm, '-f', marker_filename)
384-
self.download_file(url, filename)
387+
self.download_file(self.versioned_url, filename)
385388
shprint(sh.touch, marker_filename)
386389

387-
if exists(filename) and isfile(filename) and self.md5sum:
390+
if exists(filename) and isfile(filename) and expected_md5:
388391
current_md5 = md5sum(filename)
389-
if self.md5sum is not None:
390-
if current_md5 == self.md5sum:
391-
debug('Checked md5sum: downloaded expected content!')
392-
else:
393-
info('Downloaded unexpected content...')
392+
if expected_md5 is not None:
393+
if current_md5 != expected_md5:
394394
debug('* Generated md5sum: {}'.format(current_md5))
395-
debug('* Expected md5sum: {}'.format(self.md5sum))
396-
exit(1)
395+
debug('* Expected md5sum: {}'.format(expected_md5))
396+
raise Exception('Downloaded unexpected content!')
397+
else:
398+
info('{} download already cached, skipping'.format(self.name))
397399

398400
def unpack(self, arch):
399401
info_main('Unpacking {} for {}'.format(self.name, arch))
@@ -421,6 +423,9 @@ def unpack(self, arch):
421423

422424
filename = shprint(
423425
sh.basename, self.versioned_url).stdout[:-1].decode('utf-8')
426+
ma = match(u'^(.+)#md5=([0-9a-f]{32})$', filename)
427+
if ma: # fragmented URL?
428+
filename = ma.group(1)
424429

425430
with current_directory(build_dir):
426431
directory_name = self.get_build_dir(arch)

0 commit comments

Comments
 (0)