def from_upload(cls, upload, addon, platforms): data = utils.parse_addon(upload.path, addon) try: license = addon.versions.latest().license_id except Version.DoesNotExist: license = None v = cls.objects.create(addon=addon, version=data['version'], license_id=license) log.info('New version: %r (%s) from %r' % (v, v.id, upload)) # appversions AV = ApplicationsVersions for app in data.get('apps', []): AV(version=v, min=app.min, max=app.max, application_id=app.id).save() if addon.type == amo.ADDON_SEARCH: # Search extensions are always for all platforms. platforms = [Platform.objects.get(id=amo.PLATFORM_ALL.id)] else: platforms = cls._make_safe_platform_files(platforms) for platform in platforms: File.from_upload(upload, v, platform, parse_data=data) v.disable_old_files() # After the upload has been copied to all # platforms, remove the upload. upload.path.unlink() version_uploaded.send(sender=v) return v
def from_upload(cls, upload, addon, platforms, send_signal=True): data = utils.parse_addon(upload, addon) try: license = addon.versions.latest().license_id except Version.DoesNotExist: license = None max_len = cls._meta.get_field_by_name('_developer_name')[0].max_length developer = data.get('developer_name', '')[:max_len] v = cls.objects.create(addon=addon, version=data['version'], license_id=license, _developer_name=developer) log.info('New version: %r (%s) from %r' % (v, v.id, upload)) AV = ApplicationsVersions for app in data.get('apps', []): AV(version=v, min=app.min, max=app.max, application_id=app.id).save() if addon.type == amo.ADDON_SEARCH: # Search extensions are always for all platforms. platforms = [Platform.objects.get(id=amo.PLATFORM_ALL.id)] else: platforms = cls._make_safe_platform_files(platforms) for platform in platforms: File.from_upload(upload, v, platform, parse_data=data) v.disable_old_files() # After the upload has been copied to all platforms, remove the upload. storage.delete(upload.path) if send_signal: version_uploaded.send(sender=v) return v
def from_upload(cls, upload, addon, platforms, send_signal=True): data = utils.parse_addon(upload, addon) try: license = addon.versions.latest().license_id except Version.DoesNotExist: license = None v = cls.objects.create(addon=addon, version=data['version'], license_id=license) log.info('New version: %r (%s) from %r' % (v, v.id, upload)) # appversions AV = ApplicationsVersions for app in data.get('apps', []): AV(version=v, min=app.min, max=app.max, application_id=app.id).save() if addon.type == amo.ADDON_SEARCH: # Search extensions are always for all platforms. platforms = [Platform.objects.get(id=amo.PLATFORM_ALL.id)] else: platforms = cls._make_safe_platform_files(platforms) for platform in platforms: File.from_upload(upload, v, platform, parse_data=data) v.disable_old_files() # After the upload has been copied to all # platforms, remove the upload. path.path(upload.path).unlink() if send_signal: version_uploaded.send(sender=v) return v
def from_upload(cls, upload, addon, platforms, send_signal=True): data = utils.parse_addon(upload, addon) try: license = addon.versions.latest().license_id except Version.DoesNotExist: license = None max_len = cls._meta.get_field_by_name('_developer_name')[0].max_length developer = data.get('developer_name', '')[:max_len] v = cls.objects.create(addon=addon, version=data['version'], license_id=license, _developer_name=developer) log.info('New version: %r (%s) from %r' % (v, v.id, upload)) AV = ApplicationsVersions for app in data.get('apps', []): AV(version=v, min=app.min, max=app.max, application_id=app.id).save() if addon.type in [amo.ADDON_SEARCH, amo.ADDON_WEBAPP]: # Search extensions and webapps are always for all platforms. platforms = [Platform.objects.get(id=amo.PLATFORM_ALL.id)] else: platforms = cls._make_safe_platform_files(platforms) if addon.is_webapp(): from mkt.webapps.models import AppManifest # Create AppManifest if we're a Webapp. # Note: This must happen before we call `File.from_upload`. manifest = utils.WebAppParser().get_json_data(upload) AppManifest.objects.create(version=v, manifest=json.dumps(manifest)) for platform in platforms: File.from_upload(upload, v, platform, parse_data=data) if addon.is_webapp(): # Update supported locales from manifest. # Note: This needs to happen after we call `File.from_upload`. update_supported_locales_single.apply_async( args=[addon.id], kwargs={'latest': True}, eta=datetime.datetime.now() + datetime.timedelta(seconds=settings.NFS_LAG_DELAY)) v.disable_old_files() # After the upload has been copied to all platforms, remove the upload. storage.delete(upload.path) if send_signal: version_uploaded.send(sender=v) # If packaged app and app is blocked, put in escalation queue. if (addon.is_webapp() and addon.is_packaged and addon.status == amo.STATUS_BLOCKED): # To avoid circular import. from editors.models import EscalationQueue EscalationQueue.objects.create(addon=addon) return v
def from_upload(cls, upload, addon, platforms, send_signal=True, source=None, is_beta=False): data = utils.parse_addon(upload, addon) try: license = addon.versions.latest().license_id except Version.DoesNotExist: license = None max_len = cls._meta.get_field_by_name('_developer_name')[0].max_length developer = data.get('developer_name', '')[:max_len] v = cls.objects.create(addon=addon, version=data['version'], license_id=license, _developer_name=developer, source=source) log.info('New version: %r (%s) from %r' % (v, v.id, upload)) AV = ApplicationsVersions for app in data.get('apps', []): AV(version=v, min=app.min, max=app.max, application=app.id).save() if addon.type == amo.ADDON_SEARCH: # Search extensions are always for all platforms. platforms = [amo.PLATFORM_ALL.id] else: platforms = cls._make_safe_platform_files(platforms) for platform in platforms: File.from_upload(upload, v, platform, parse_data=data, is_beta=is_beta) v.disable_old_files() # After the upload has been copied to all platforms, remove the upload. storage.delete(upload.path) if send_signal: version_uploaded.send(sender=v) # Track the time it took from first upload through validation # (and whatever else) until a version was created. upload_start = utc_millesecs_from_epoch(upload.created) now = datetime.datetime.now() now_ts = utc_millesecs_from_epoch(now) upload_time = now_ts - upload_start log.info('Time for version {version} creation from upload: {delta}; ' 'created={created}; now={now}'.format(delta=upload_time, version=v, created=upload.created, now=now)) statsd.timing('devhub.version_created_from_upload', upload_time) return v
def from_upload(cls, upload, addon, platforms, send_signal=True): data = utils.parse_addon(upload, addon) try: license = addon.versions.latest().license_id except Version.DoesNotExist: license = None max_len = cls._meta.get_field_by_name('_developer_name')[0].max_length developer = data.get('developer_name', '')[:max_len] v = cls.objects.create(addon=addon, version=data['version'], license_id=license, _developer_name=developer) log.info('New version: %r (%s) from %r' % (v, v.id, upload)) AV = ApplicationsVersions for app in data.get('apps', []): AV(version=v, min=app.min, max=app.max, application_id=app.id).save() if addon.type in [amo.ADDON_SEARCH, amo.ADDON_WEBAPP]: # Search extensions and webapps are always for all platforms. platforms = [Platform.objects.get(id=amo.PLATFORM_ALL.id)] else: platforms = cls._make_safe_platform_files(platforms) if addon.is_webapp(): from mkt.webapps.models import AppManifest # Create AppManifest if we're a Webapp. # Note: This must happen before we call `File.from_upload`. manifest = utils.WebAppParser().get_json_data(upload) AppManifest.objects.create( version=v, manifest=json.dumps(manifest)) for platform in platforms: File.from_upload(upload, v, platform, parse_data=data) if addon.is_webapp(): # Update supported locales from manifest. # Note: This needs to happen after we call `File.from_upload`. update_supported_locales_single.apply_async( args=[addon.id], kwargs={'latest': True}, eta=datetime.datetime.now() + datetime.timedelta(seconds=settings.NFS_LAG_DELAY)) v.disable_old_files() # After the upload has been copied to all platforms, remove the upload. storage.delete(upload.path) if send_signal: version_uploaded.send(sender=v) # If packaged app and app is blocked, put in escalation queue. if (addon.is_webapp() and addon.is_packaged and addon.status == amo.STATUS_BLOCKED): # To avoid circular import. from editors.models import EscalationQueue EscalationQueue.objects.create(addon=addon) return v
def from_upload(cls, upload, addon, platforms, send_signal=True, source=None, is_beta=False): data = utils.parse_addon(upload, addon) try: license = addon.versions.latest().license_id except Version.DoesNotExist: license = None max_len = cls._meta.get_field_by_name('_developer_name')[0].max_length developer = data.get('developer_name', '')[:max_len] v = cls.objects.create( addon=addon, version=data['version'], license_id=license, _developer_name=developer, source=source ) log.info('New version: %r (%s) from %r' % (v, v.id, upload)) AV = ApplicationsVersions for app in data.get('apps', []): AV(version=v, min=app.min, max=app.max, application=app.id).save() if addon.type == amo.ADDON_SEARCH: # Search extensions are always for all platforms. platforms = [amo.PLATFORM_ALL.id] else: platforms = cls._make_safe_platform_files(platforms) for platform in platforms: File.from_upload(upload, v, platform, parse_data=data, is_beta=is_beta) v.disable_old_files() # After the upload has been copied to all platforms, remove the upload. storage.delete(upload.path) if send_signal: version_uploaded.send(sender=v) # Track the time it took from first upload through validation # (and whatever else) until a version was created. upload_start = utc_millesecs_from_epoch(upload.created) now = datetime.datetime.now() now_ts = utc_millesecs_from_epoch(now) upload_time = now_ts - upload_start log.info('Time for version {version} creation from upload: {delta}; ' 'created={created}; now={now}' .format(delta=upload_time, version=v, created=upload.created, now=now)) statsd.timing('devhub.version_created_from_upload', upload_time) return v
def from_upload(cls, upload, addon, platforms, send_signal=True): data = utils.parse_addon(upload, addon) try: license = addon.versions.latest().license_id except Version.DoesNotExist: license = None v = cls.objects.create(addon=addon, version=data['version'], license_id=license) log.info('New version: %r (%s) from %r' % (v, v.id, upload)) # appversions AV = ApplicationsVersions for app in data.get('apps', []): AV(version=v, min=app.min, max=app.max, application_id=app.id).save() if addon.type in [amo.ADDON_SEARCH, amo.ADDON_WEBAPP]: # Search extensions and webapps are always for all platforms. platforms = [Platform.objects.get(id=amo.PLATFORM_ALL.id)] else: platforms = cls._make_safe_platform_files(platforms) for platform in platforms: File.from_upload(upload, v, platform, parse_data=data) if addon.type == amo.ADDON_WEBAPP: update_supported_locales_single.apply_async( args=[addon.id], kwargs={'latest': True}, eta=datetime.datetime.now() + datetime.timedelta(seconds=settings.NFS_LAG_DELAY)) v.disable_old_files() # After the upload has been copied to all platforms, remove the upload. storage.delete(upload.path) if send_signal: version_uploaded.send(sender=v) # If packaged app and app is blocked, put in escalation queue. if (addon.is_webapp() and addon.is_packaged and addon.status == amo.STATUS_BLOCKED): # To avoid circular import. from editors.models import EscalationQueue EscalationQueue.objects.create(addon=addon) return v
def from_upload(cls, upload, addon, platforms, send_signal=True, source=None, is_beta=False): data = utils.parse_addon(upload, addon) try: license = addon.versions.latest().license_id except Version.DoesNotExist: license = None max_len = cls._meta.get_field_by_name('_developer_name')[0].max_length developer = data.get('developer_name', '')[:max_len] v = cls.objects.create(addon=addon, version=data['version'], license_id=license, _developer_name=developer, source=source) log.info('New version: %r (%s) from %r' % (v, v.id, upload)) AV = ApplicationsVersions for app in data.get('apps', []): AV(version=v, min=app.min, max=app.max, application=app.id).save() if addon.type == amo.ADDON_SEARCH: # Search extensions are always for all platforms. platforms = [amo.PLATFORM_ALL.id] else: platforms = cls._make_safe_platform_files(platforms) for platform in platforms: File.from_upload(upload, v, platform, parse_data=data, is_beta=is_beta) v.disable_old_files() # After the upload has been copied to all platforms, remove the upload. storage.delete(upload.path) if send_signal: version_uploaded.send(sender=v) return v
def from_upload(cls, upload, addon, send_signal=True): data = utils.parse_addon(upload, addon) try: license = addon.versions.latest().license_id except Version.DoesNotExist: license = None max_len = cls._meta.get_field_by_name('_developer_name')[0].max_length developer = data.get('developer_name', '')[:max_len] v = cls.objects.create(addon=addon, version=data['version'], license_id=license, _developer_name=developer) log.info('New version: %r (%s) from %r' % (v, v.id, upload)) # To avoid circular import. from mkt.webapps.models import AppManifest # Note: This must happen before we call `File.from_upload`. manifest = utils.WebAppParser().get_json_data(upload) AppManifest.objects.create( version=v, manifest=json.dumps(manifest)) File.from_upload(upload, v, parse_data=data) # Update supported locales from manifest. # Note: This needs to happen after we call `File.from_upload`. update_supported_locales_single.apply_async( args=[addon.id], kwargs={'latest': True}, eta=datetime.datetime.now() + datetime.timedelta(seconds=settings.NFS_LAG_DELAY)) v.disable_old_files() # After the upload has been copied, remove the upload. storage.delete(upload.path) if send_signal: version_uploaded.send(sender=v) # If packaged app and app is blocked, put in escalation queue. if addon.is_packaged and addon.status == amo.STATUS_BLOCKED: # To avoid circular import. from mkt.reviewers.models import EscalationQueue EscalationQueue.objects.create(addon=addon) return v
def from_upload(cls, upload, addon, platforms): data = utils.parse_addon(upload.path, addon) try: license = addon.versions.latest().license_id except Version.DoesNotExist: license = None v = cls.objects.create(addon=addon, version=data['version'], license_id=license) log.debug('New version: %r (%s) from %r' % (v, v.id, upload)) # appversions AV = ApplicationsVersions for app in data.get('apps', []): AV(version=v, min=app.min, max=app.max, application_id=app.id).save() if addon.type == amo.ADDON_SEARCH: # Search extensions are always for all platforms. platforms = [Platform.objects.get(id=amo.PLATFORM_ALL.id)] else: new_plats = [] # Transform PLATFORM_ALL_MOBILE into specific mobile platform # files (e.g. Android, Maemo). # TODO(Kumar) Stop doing this when allmobile is supported # for downloads. See bug 646268. for p in platforms: if p.id == amo.PLATFORM_ALL_MOBILE.id: for mobi_p in (set(amo.MOBILE_PLATFORMS.keys()) - set([amo.PLATFORM_ALL_MOBILE.id])): new_plats.append(Platform.objects.get(id=mobi_p)) else: new_plats.append(p) platforms = new_plats for platform in platforms: File.from_upload(upload, v, platform, parse_data=data) v.disable_old_files() # After the upload has been copied to all # platforms, remove the upload. upload.path.unlink() return v
def from_upload(cls, upload, addon, send_signal=True): data = utils.parse_addon(upload, addon) max_len = cls._meta.get_field_by_name('_developer_name')[0].max_length developer = data.get('developer_name', '')[:max_len] v = cls.objects.create(addon=addon, version=data['version'], _developer_name=developer) log.info('New version: %r (%s) from %r' % (v, v.id, upload)) # To avoid circular import. from mkt.webapps.models import AppManifest # Note: This must happen before we call `File.from_upload`. manifest = utils.WebAppParser().get_json_data(upload) AppManifest.objects.create(version=v, manifest=json.dumps(manifest)) File.from_upload(upload, v, parse_data=data) # Update supported locales from manifest. # Note: This needs to happen after we call `File.from_upload`. update_supported_locales_single.apply_async( args=[addon.id], kwargs={'latest': True}, eta=datetime.datetime.now() + datetime.timedelta(seconds=settings.NFS_LAG_DELAY)) v.disable_old_files() # After the upload has been copied, remove the upload. storage.delete(upload.path) if send_signal: version_uploaded.send(sender=v) # If packaged app and app is blocked, put in escalation queue. if addon.is_packaged and addon.status == amo.STATUS_BLOCKED: # To avoid circular import. from mkt.reviewers.models import EscalationQueue EscalationQueue.objects.create(addon=addon) return v