def _extract_architecture_from_paths(apk_path, paths):
    detected_architectures = [
        path.split('/')[_ARCHITECTURE_SUBDIRECTORY_INDEX] for path in paths
    ]
    unique_architectures = filter_out_identical_values(detected_architectures)
    non_empty_unique_architectures = [
        architecture for architecture in unique_architectures if architecture
    ]
    number_of_unique_architectures = len(non_empty_unique_architectures)

    if number_of_unique_architectures == 0:
        raise BadApk('"{}" does not contain any architecture data under these paths: {}'.format(apk_path, paths))
    elif number_of_unique_architectures > 1:
        raise BadApk('"{}" contains too many architectures: {}'.format(apk_path, unique_architectures))

    return unique_architectures[0]
Example #2
0
def _check_version_matches_package_name(version, package_name):
    regex = _MATCHING_VERSION_NUMBER_PER_PACKAGE_NAME[package_name]
    if regex.match(version) is None:
        raise BadApk('Wrong version number "{}" for package name "{}"'.format(
            version, package_name))

    logger.info('Firefox version "{}" matches package name "{}"'.format(
        version, package_name))
Example #3
0
def check_if_apk_has_claimed_architecture(apk_path, architecture_name):
    architecture_within_apk = get_apk_architecture(apk_path)

    try:
        pretty_architecture_within_apk = _CLAIMED_ARCHITECTURE_PER_DIRECTORY_NAME[
            architecture_within_apk]
    except KeyError:
        raise BadApk(
            'Architecture "{}" detected within APK, but it is not supported. Supported ones are: {}'
            .format(architecture_within_apk,
                    _CLAIMED_ARCHITECTURE_PER_DIRECTORY_NAME.values()))

    if pretty_architecture_within_apk != architecture_name:
        raise BadApk(
            '"{}" is not built for the architecture called "{}". Detected architecture: {}'
            .format(apk_path, architecture_name,
                    pretty_architecture_within_apk))

    logger.info('"{}" is effectively built for architecture "{}"'.format(
        apk_path, architecture_name))
def _extract_architecture(apk_zip, original_apk_path):
    files_with_architecture_in_path = [
        name for name in apk_zip.namelist()
        if _DIRECTORY_WITH_ARCHITECTURE_METADATA in name
    ]

    if not files_with_architecture_in_path:
        raise BadApk('"{}" does not contain a directory called "{}"'
                     .format(original_apk_path, _DIRECTORY_WITH_ARCHITECTURE_METADATA))

    return _extract_architecture_from_paths(original_apk_path, files_with_architecture_in_path)
Example #5
0
def _check_all_apks_are_multi_locales(apks_metadata_per_paths):
    for path, metadata in apks_metadata_per_paths.items():
        locales = metadata['locales']

        if not isinstance(locales, tuple):
            raise BadApk('Locale list is not either a tuple. "{}" has: {}'.format(path, locales))

        number_of_locales = len(locales)

        if number_of_locales <= 1:
            raise NotMultiLocaleApk(path, locales)

        logger.info('"{}" is multilocale.'.format(path))
Example #6
0
def get_apk_architecture(apk_path):
    with ZipFile(apk_path) as apk_zip:
        files_with_architecture_in_path = [
            file_info.filename for file_info in apk_zip.infolist()
            if _DIRECTORY_WITH_ARCHITECTURE_METADATA in file_info.filename
        ]

    if not files_with_architecture_in_path:
        raise BadApk('"{}" does not contain a directory called "{}"'.format(
            apk_path, _DIRECTORY_WITH_ARCHITECTURE_METADATA))

    return _extract_architecture_from_paths(apk_path,
                                            files_with_architecture_in_path)
Example #7
0
def _check_version_matches_package_name(version, package_name):
    sanitized_version = FirefoxVersion(version)

    if (
        (package_name == 'org.mozilla.firefox' and sanitized_version.is_release) or
        # Due to project Dawn, Nightly is now using the Aurora package name. See bug 1357351.
        (package_name == 'org.mozilla.fennec_aurora' and sanitized_version.is_nightly) or
        (
            # XXX Betas aren't following the regular XX.0bY format. Instead they follow XX.0
            # (which looks like release). Therefore, we can't use sanitized_version.is_beta
            package_name == 'org.mozilla.firefox_beta'
            and sanitized_version.is_release
            and sanitized_version.minor_number == 0
            # We ensure the patch_number is undefined. Calling sanitized_version.patch_number
            # directly raises an (expected) AttributeError
            and getattr(sanitized_version, 'patch_number', None) is None
        )
    ):
        logger.info('Firefox version "{}" matches package name "{}"'.format(version, package_name))

    else:
        raise BadApk('Wrong version number "{}" for package name "{}"'.format(version, package_name))