in src/olympia/files/utils.py [0:0]
def apps(self):
"""Return `ApplicationsVersion`s (without the `version` field being
set yet) for this manifest to be used in Version.from_upload()."""
from olympia.versions.models import ApplicationsVersions
type_ = self.type
if type_ == amo.ADDON_LPAPP:
# Langpack are only compatible with Firefox desktop at the moment.
# https://github.com/mozilla/addons-server/issues/8381
# They are all strictly compatible with a specific version, so
# the default min version here doesn't matter much.
apps = ((amo.FIREFOX, amo.DEFAULT_WEBEXT_MIN_VERSION),)
elif type_ == amo.ADDON_STATICTHEME:
# Static themes are only compatible with Firefox desktop >= 53.
# They used to be compatible with Android, but that support was
# removed.
apps = ((amo.FIREFOX, amo.DEFAULT_STATIC_THEME_MIN_VERSION_FIREFOX),)
elif type_ == amo.ADDON_DICT:
# WebExt dicts are only compatible with Firefox desktop >= 61.
apps = ((amo.FIREFOX, amo.DEFAULT_WEBEXT_DICT_MIN_VERSION_FIREFOX),)
else:
webext_min_firefox = amo.DEFAULT_WEBEXT_MIN_VERSION
webext_min_android = (
amo.DEFAULT_WEBEXT_MIN_VERSION_GECKO_ANDROID
if self.gecko_android is not EMPTY_FALLBACK_DICT
else amo.DEFAULT_WEBEXT_MIN_VERSION_ANDROID
)
apps = (
(amo.FIREFOX, webext_min_firefox),
(amo.ANDROID, webext_min_android),
)
if self.get('manifest_version') == 3:
# Update minimum supported versions if it's an mv3 addon.
mv3_mins = {
amo.FIREFOX: amo.DEFAULT_WEBEXT_MIN_VERSION_MV3_FIREFOX,
amo.ANDROID: amo.DEFAULT_WEBEXT_MIN_VERSION_MV3_ANDROID,
}
apps = (
(app, max(VersionString(ver), mv3_mins.get(app, mv3_mins[amo.FIREFOX])))
for app, ver in apps
)
strict_min_version_firefox = self.get_strict_version_for(
key='min', application=amo.FIREFOX
)
# If a minimum strict version is specified, it needs to be higher
# than the version when Firefox started supporting WebExtensions.
unsupported_no_matter_what = (
strict_min_version_firefox
and strict_min_version_firefox
< VersionString(amo.DEFAULT_WEBEXT_MIN_VERSION)
)
if unsupported_no_matter_what:
msg = gettext('Lowest supported "strict_min_version" is {min_version}.')
raise forms.ValidationError(
msg.format(min_version=amo.DEFAULT_WEBEXT_MIN_VERSION)
)
for app, default_min_version in apps:
strict_min_version_from_manifest = self.get_strict_version_for(
key='min', application=app
)
# strict_min_version for this app shouldn't be lower than the
# default min version for this app.
strict_min_version = max(
strict_min_version_from_manifest, VersionString(default_min_version)
)
strict_max_version_from_manifest = self.get_strict_version_for(
key='max', application=app
)
strict_max_version = strict_max_version_from_manifest or VersionString(
amo.DEFAULT_WEBEXT_MAX_VERSION
)
if strict_max_version < strict_min_version:
strict_max_version = strict_min_version
qs = AppVersion.objects.filter(application=app.id)
try:
min_appver = qs.get(version=strict_min_version)
except AppVersion.DoesNotExist as exc:
msg = gettext(
'Unknown "strict_min_version" {appver} for {app}'.format(
app=app.pretty, appver=strict_min_version
)
)
raise forms.ValidationError(msg) from exc
try:
max_appver = qs.get(version=strict_max_version)
except AppVersion.DoesNotExist as exc:
# If the specified strict_max_version can't be found, raise an
# error: we used to use '*' instead but this caused more
# problems, especially with langpacks that are really specific
# to a given Firefox version.
msg = gettext(
'Unknown "strict_max_version" {appver} for {app}'.format(
app=app.pretty, appver=strict_max_version
)
)
raise forms.ValidationError(msg) from exc
if app == amo.ANDROID and self.gecko_android is not EMPTY_FALLBACK_DICT:
originated_from = amo.APPVERSIONS_ORIGINATED_FROM_MANIFEST_GECKO_ANDROID
elif strict_min_version_from_manifest or strict_max_version_from_manifest:
# At least part of the compatibility came from the manifest.
originated_from = amo.APPVERSIONS_ORIGINATED_FROM_MANIFEST
else:
originated_from = amo.APPVERSIONS_ORIGINATED_FROM_AUTOMATIC
yield ApplicationsVersions(
application=app.id,
min=min_appver,
max=max_appver,
originated_from=originated_from,
)