Пример #1
0
    def from_upload(cls,
                    upload,
                    version,
                    platform,
                    is_beta=False,
                    parsed_data=None):
        if parsed_data is None:
            parsed_data = {}
        addon = version.addon

        file_ = cls(version=version, platform=platform)
        upload.path = force_bytes(nfd_str(upload.path))
        ext = os.path.splitext(upload.path)[1]
        if ext == '.jar':
            ext = '.xpi'
        file_.filename = file_.generate_filename(extension=ext or '.xpi')
        # Size in bytes.
        file_.size = storage.size(upload.path)
        data = cls.get_jetpack_metadata(upload.path)
        if 'sdkVersion' in data and data['sdkVersion']:
            file_.jetpack_version = data['sdkVersion'][:10]
        file_.no_restart = parsed_data.get('no_restart', False)
        file_.strict_compatibility = parsed_data.get('strict_compatibility',
                                                     False)
        file_.is_multi_package = parsed_data.get('is_multi_package', False)
        file_.is_experiment = parsed_data.get('is_experiment', False)
        file_.is_webextension = parsed_data.get('is_webextension', False)

        if (is_beta and addon.status == amo.STATUS_PUBLIC
                and version.channel == amo.RELEASE_CHANNEL_LISTED):
            file_.status = amo.STATUS_BETA

        file_.hash = file_.generate_hash(upload.path)
        file_.original_hash = file_.hash

        if upload.validation:
            validation = json.loads(upload.validation)
            if validation['metadata'].get('requires_chrome'):
                file_.requires_chrome = True

        file_.save()

        log.debug('New file: %r from %r' % (file_, upload))
        # Move the uploaded file from the temp location.
        copy_stored_file(
            upload.path,
            os.path.join(version.path_prefix, nfd_str(file_.filename)))

        if upload.validation:
            # Import loop.
            from olympia.devhub.tasks import annotate_validation_results
            from olympia.devhub.utils import ValidationAnnotator

            validation = annotate_validation_results(validation)
            FileValidation.from_json(file_, validation)

            # Copy annotations from any previously approved file.
            ValidationAnnotator(file_).update_annotations()

        return file_
Пример #2
0
    def from_upload(cls,
                    upload,
                    version,
                    platform,
                    is_beta=False,
                    parse_data={}):
        addon = version.addon

        file_ = cls(version=version, platform=platform)
        upload.path = smart_path(nfd_str(upload.path))
        ext = os.path.splitext(upload.path)[1]
        if ext == '.jar':
            ext = '.xpi'
        file_.filename = file_.generate_filename(extension=ext or '.xpi')
        # Size in bytes.
        file_.size = storage.size(upload.path)
        data = cls.get_jetpack_metadata(upload.path)
        if 'sdkVersion' in data and data['sdkVersion']:
            file_.jetpack_version = data['sdkVersion'][:10]
        if file_.jetpack_version:
            Tag(tag_text='jetpack').save_tag(addon)
        file_.no_restart = parse_data.get('no_restart', False)
        file_.strict_compatibility = parse_data.get('strict_compatibility',
                                                    False)
        file_.is_multi_package = parse_data.get('is_multi_package', False)
        file_.is_experiment = parse_data.get('is_experiment', False)
        file_.is_webextension = parse_data.get('is_webextension', False)

        if is_beta and addon.status == amo.STATUS_PUBLIC:
            file_.status = amo.STATUS_BETA
        elif addon.trusted:
            # New files in trusted add-ons automatically receive the correct
            # approved status for their review class.
            if addon.status == amo.STATUS_PUBLIC:
                file_.status = amo.STATUS_PUBLIC
            elif addon.status in amo.LITE_STATUSES:
                file_.status = amo.STATUS_LITE

        file_.hash = file_.generate_hash(upload.path)
        file_.original_hash = file_.hash

        if upload.validation:
            validation = json.loads(upload.validation)
            if validation['metadata'].get('requires_chrome'):
                file_.requires_chrome = True

        file_.save()

        log.debug('New file: %r from %r' % (file_, upload))
        # Move the uploaded file from the temp location.
        destinations = [version.path_prefix]
        if file_.status in amo.MIRROR_STATUSES:
            destinations.append(version.mirror_path_prefix)
        for dest in destinations:
            copy_stored_file(upload.path,
                             os.path.join(dest, nfd_str(file_.filename)))

        if upload.validation:
            # Import loop.
            from olympia.devhub.tasks import annotate_validation_results
            from olympia.devhub.utils import ValidationAnnotator

            validation = annotate_validation_results(validation)
            FileValidation.from_json(file_, validation)

            # Copy annotations from any previously approved file.
            ValidationAnnotator(file_).update_annotations()

        return file_