(self, arch)
| 460 | info('{} download already cached, skipping'.format(self.name)) |
| 461 | |
| 462 | def unpack(self, arch): |
| 463 | info_main('Unpacking {} for {}'.format(self.name, arch)) |
| 464 | |
| 465 | build_dir = self.get_build_container_dir(arch) |
| 466 | |
| 467 | user_dir = environ.get('P4A_{}_DIR'.format(self.name.lower())) |
| 468 | if user_dir is not None: |
| 469 | info('P4A_{}_DIR exists, symlinking instead'.format( |
| 470 | self.name.lower())) |
| 471 | if exists(self.get_build_dir(arch)): |
| 472 | return |
| 473 | rmdir(build_dir) |
| 474 | ensure_dir(build_dir) |
| 475 | shprint(sh.cp, '-a', user_dir, self.get_build_dir(arch)) |
| 476 | return |
| 477 | |
| 478 | if self.url is None: |
| 479 | info('Skipping {} unpack as no URL is set'.format(self.name)) |
| 480 | return |
| 481 | |
| 482 | filename = shprint( |
| 483 | sh.basename, self.versioned_url).stdout[:-1].decode('utf-8') |
| 484 | ma = match(u'^(.+)#[a-z0-9_]{3,}=([0-9a-f]{32,})$', filename) |
| 485 | if ma: # fragmented URL? |
| 486 | filename = ma.group(1) |
| 487 | |
| 488 | with current_directory(build_dir): |
| 489 | directory_name = self.get_build_dir(arch) |
| 490 | |
| 491 | if not exists(directory_name) or not isdir(directory_name): |
| 492 | extraction_filename = join( |
| 493 | self.ctx.packages_path, self.name, filename) |
| 494 | if isfile(extraction_filename): |
| 495 | if extraction_filename.endswith(('.zip', '.whl')): |
| 496 | try: |
| 497 | sh.unzip(extraction_filename) |
| 498 | except (sh.ErrorReturnCode_1, sh.ErrorReturnCode_2): |
| 499 | # return code 1 means unzipping had |
| 500 | # warnings but did complete, |
| 501 | # apparently happens sometimes with |
| 502 | # github zips |
| 503 | pass |
| 504 | fileh = zipfile.ZipFile(extraction_filename, 'r') |
| 505 | root_directory = fileh.filelist[0].filename.split('/')[0] |
| 506 | if root_directory != basename(directory_name): |
| 507 | move(root_directory, directory_name) |
| 508 | elif extraction_filename.endswith( |
| 509 | ('.tar.gz', '.tgz', '.tar.bz2', '.tbz2', '.tar.xz', '.txz')): |
| 510 | sh.tar('xf', extraction_filename) |
| 511 | root_directory = sh.tar('tf', extraction_filename).split('\n')[0].split('/')[0] |
| 512 | if root_directory != basename(directory_name): |
| 513 | move(root_directory, directory_name) |
| 514 | else: |
| 515 | raise Exception( |
| 516 | 'Could not extract {} download, it must be .zip, ' |
| 517 | '.tar.gz or .tar.bz2 or .tar.xz'.format(extraction_filename)) |
| 518 | elif isdir(extraction_filename): |
| 519 | ensure_dir(directory_name) |
no test coverage detected