Skip to content

Commit

Permalink
Merge pull request #3780 from kyoshino/bug-1226476-android-all
Browse files Browse the repository at this point in the history
Fix Bug 1226476 - Convert android/all/ to the same format as desktop uses
  • Loading branch information
jgmize committed Jan 25, 2016
2 parents 1643254 + 4051c98 commit e3f844a
Show file tree
Hide file tree
Showing 29 changed files with 382 additions and 305 deletions.
27 changes: 9 additions & 18 deletions bedrock/base/templates/product-all-macros.html
Expand Up @@ -38,7 +38,7 @@ <h4>{{ _('Other Firefox downloads') }}</h4>
</form>
{% endmacro %}

{% macro build_table(builds, title, description) %}
{% macro build_table(platforms, builds, title, description) %}
<div class="build-table-container">
{% if builds %}
<table class="table build-table">
Expand All @@ -51,18 +51,14 @@ <h3>{{ title }}</h3>
<thead>
<tr>
<th colspan="2" scope="col">{{ _('Language') }}</th>
<th scope="col">{{ _('Windows') }}</th>
{% if 'win64' in builds[0].platforms.keys() -%}
<th scope="col">{{ _('Windows 64-bit') }}</th>
{% endif -%}
<th scope="col">{{ _('Mac OS X') }}</th>
<th scope="col">{{ _('Linux') }}</th>
<th scope="col">{{ _('Linux 64-bit') }}</th>
{% for p_name, p_label in platforms %}
<th scope="col">{{ p_label|replace('\n', '<br>'|safe) }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for build in builds %}
{{ build_row(build) }}
{{ build_row(platforms, build) }}
{% endfor %}
</tbody>
</table>
Expand All @@ -71,18 +67,13 @@ <h4 class="not-found{% if builds %} hide{% endif %}">{{ _('No matching languages
</div>
{% endmacro %}

{% macro build_row(build) %}
{% macro build_row(platforms, build) %}
<tr id="{{ build.locale }}" data-search="{{ build.name_en|lower }}, {{ build.name_native|lower }}">
<th scope="row">{{ build.name_en }}</th>
<td lang="{{ build.locale }}">{{ build.name_native }}</td>
{{ build_link(build, 'win', _('Download for Windows')) }}
{# Windows 64-bit builds are currently available only on the Firefox Aurora and Beta channels -#}
{% if 'win64' in build.platforms.keys() -%}
{{ build_link(build, 'win64', _('Download for 64-bit Windows')) }}
{% endif -%}
{{ build_link(build, 'osx', _('Download for Mac OS X')) }}
{{ build_link(build, 'linux', _('Download for Linux')) }}
{{ build_link(build, 'linux64', _('Download for 64-bit Linux')) }}
{% for p_name, p_label in platforms %}
{{ build_link(build, p_name, _('Download for %(platform)s in %(locale)s')|format(platform=p_label|replace('\n', ' '), locale=build.name_en)) }}
{% endfor %}
</tr>
{% endmacro %}

Expand Down
177 changes: 157 additions & 20 deletions bedrock/firefox/firefox_details.py
Expand Up @@ -5,21 +5,41 @@

from django.conf import settings
from product_details import ProductDetails
from lib.l10n_utils.dotlang import _


# TODO: port this to django-mozilla-product-details
class FirefoxDesktop(ProductDetails):
download_base_url_direct = 'https://download.mozilla.org/'
class _ProductDetails(ProductDetails):
bouncer_url = 'https://download.mozilla.org/'

def _matches_query(self, info, query):
words = re.split(r',|,?\s+', query.strip().lower())
return all((word in info['name_en'].lower() or
word in info['name_native'].lower()) for word in words)


class FirefoxDesktop(_ProductDetails):
download_base_url_transition = '/firefox/new/?scene=2#download-fx'

# Human-readable platform names
platform_labels = OrderedDict([
('win', 'Windows'),
('win64', 'Windows 64-bit'),
('osx', 'OS X'),
('linux', 'Linux'),
('linux64', 'Linux 64-bit'),
])
channel_map = {

# Human-readable channel names
channel_labels = {
'alpha': _('Developer Edition'),
'beta': _('Firefox Beta'),
'esr': _('Firefox Extended Support Release'),
'release': _('Firefox'),
}

# Version property names in product-details
version_map = {
'alpha': 'FIREFOX_AURORA',
'beta': 'LATEST_FIREFOX_DEVEL_VERSION',
'esr': 'FIREFOX_ESR',
Expand All @@ -30,8 +50,17 @@ class FirefoxDesktop(ProductDetails):
def __init__(self, **kwargs):
super(FirefoxDesktop, self).__init__(**kwargs)

def platforms(self, channel='release'):
platforms = self.platform_labels.copy()

# Windows 64-bit builds are not available on the ESR channel yet
if channel in ['esr', 'esr_next']:
del platforms['win64']

return platforms.items()

def latest_version(self, channel='release'):
version = self.channel_map.get(channel, 'LATEST_FIREFOX_VERSION')
version = self.version_map.get(channel, 'LATEST_FIREFOX_VERSION')
try:
return self.firefox_versions[version]
except KeyError:
Expand Down Expand Up @@ -90,17 +119,12 @@ def latest_builds(self, locale, channel='release'):
_builds['Linux 64-bit'] = _builds['Linux']
return version, _builds

def _matches_query(self, info, query):
words = re.split(r',|,?\s+', query.strip().lower())
return all((word in info['name_en'].lower() or
word in info['name_native'].lower()) for word in words)

def _get_filtered_builds(self, builds, channel, version=None, query=None):
"""
Get a list of builds, sorted by english locale name, for a specific
Firefox version.
:param builds: a build dict from the JSON
:param channel: one of self.channel_map.keys().
:param channel: one of self.version_map.keys().
:param version: a firefox version. one of self.latest_versions.
:param query: a string to match against native or english locale name
:return: list
Expand Down Expand Up @@ -140,7 +164,7 @@ def _get_filtered_builds(self, builds, channel, version=None, query=None):
def get_filtered_full_builds(self, channel, version=None, query=None):
"""
Return filtered builds for the fully translated releases.
:param channel: one of self.channel_map.keys().
:param channel: one of self.version_map.keys().
:param version: a firefox version. one of self.latest_version.
:param query: a string to match against native or english locale name
:return: list
Expand All @@ -151,7 +175,7 @@ def get_filtered_full_builds(self, channel, version=None, query=None):
def get_filtered_test_builds(self, channel, version=None, query=None):
"""
Return filtered builds for the translated releases in beta.
:param channel: one of self.channel_map.keys().
:param channel: one of self.version_map.keys().
:param version: a firefox version. one of self.latest_version.
:param query: a string to match against native or english locale name
:return: list
Expand All @@ -164,7 +188,7 @@ def get_download_url(self, channel, version, platform, locale,
force_funnelcake=False, funnelcake_id=None):
"""
Get direct download url for the product.
:param channel: one of self.channel_map.keys().
:param channel: one of self.version_map.keys().
:param version: a firefox version. one of self.latest_version.
:param platform: OS. one of self.platform_labels.keys().
:param locale: e.g. pt-BR. one exception is ja-JP-mac.
Expand All @@ -191,7 +215,7 @@ def get_download_url(self, channel, version, platform, locale,
else:
product = 'firefox-aurora-latest-l10n'

return '?'.join([self.download_base_url_direct,
return '?'.join([self.bouncer_url,
urlencode([
('product', product),
('os', platform),
Expand Down Expand Up @@ -224,7 +248,7 @@ def get_download_url(self, channel, version, platform, locale,
# (bypassing the transition page)
if force_direct:
# build a direct download link
return '?'.join([self.download_base_url_direct,
return '?'.join([self.bouncer_url,
urlencode([
('product', 'firefox-%s' % _version),
('os', platform),
Expand All @@ -236,12 +260,41 @@ def get_download_url(self, channel, version, platform, locale,
return self.download_base_url_transition


class FirefoxAndroid(ProductDetails):
channel_map = {
class FirefoxAndroid(_ProductDetails):
# Architecture names defined in bouncer and these human-readable names
platform_labels = OrderedDict([
('android', _('Modern devices\n(Android 4.0+)')),
('android-api-9', _('Legacy devices\n(Android 2.3)')),
('android-x86', _('Intel devices\n(Android 4.0+ x86 CPU)')),
])

# Human-readable channel names
channel_labels = {
'alpha': _('Firefox Aurora'),
'beta': _('Firefox Beta'),
'release': _('Firefox'),
}

# Version property names in product-details
version_map = {
'alpha': 'alpha_version',
'beta': 'beta_version',
'release': 'version',
}

# Build property names in product-details
build_map = {
'alpha': 'alpha_builds',
'beta': 'beta_builds',
'release': 'builds',
}

# Product names defined in bouncer
product_map = {
'beta': 'fennec-beta-latest',
'release': 'fennec-latest',
}

store_url = settings.GOOGLE_PLAY_FIREFOX_LINK
aurora_url_base = ('https://ftp.mozilla.org/pub/mozilla.org/mobile/nightly/'
'latest-mozilla-aurora-android')
Expand All @@ -251,10 +304,94 @@ class FirefoxAndroid(ProductDetails):
'x86': aurora_url_base + '-x86/fennec-%s.multi.android-i386.apk',
}

def platforms(self, channel='release'):
platforms = self.platform_labels.copy()

# Android Honeycomb (3.x) was supported on Firefox 45 and below
if int(self.latest_version(channel).split('.', 1)[0]) < 46:
platforms['android'] = _('Modern devices\n(Android 3.0+)')

return platforms.items()

def latest_version(self, channel):
version = self.channel_map.get(channel, 'version')
version = self.version_map.get(channel, 'version')
return self.mobile_details[version]

def _get_filtered_builds(self, builds, channel, version=None, query=None):
"""
Get a list of builds, sorted by english locale name, for a specific
Firefox version.
:param builds: a build dict from the JSON
:param channel: one of self.version_map.keys().
:param version: a firefox version. one of self.latest_versions.
:param query: a string to match against native or english locale name
:return: list
"""
product = self.product_map.get(channel, 'fennec-latest')
locales = [build['locale']['code'] for build in builds]
f_builds = []

# Prepend multi-locale build
locales.sort()
locales.insert(0, 'multi')

for locale in locales:
if locale == 'multi':
name_en = _('Multi-locale')
name_native = ''
elif locale in self.languages:
name_en = self.languages[locale]['English']
name_native = self.languages[locale]['native']
else:
continue

build_info = {
'locale': locale,
'name_en': name_en,
'name_native': name_native,
'platforms': {},
}

# only include builds that match a search query
if query is not None and not self._matches_query(build_info, query):
continue

for arch, label in self.platform_labels.iteritems():
# x86 builds are not localized yet
if arch == 'android-x86' and locale not in ['multi', 'en-US']:
continue

params = urlencode([
('product', product),
('os', arch),
# Order matters, lang must be last for bouncer.
('lang', locale),
])

build_info['platforms'][arch] = {
'download_url': '?'.join([self.bouncer_url, params])
}

f_builds.append(build_info)

return f_builds

def get_filtered_full_builds(self, channel, version=None, query=None):
"""
Return filtered builds for the fully translated releases.
:param channel: one of self.version_map.keys().
:param version: a firefox version. one of self.latest_version.
:param query: a string to match against native or english locale name
:return: list
"""
builds = self.mobile_details[self.build_map.get(channel, 'builds')]

return self._get_filtered_builds(builds, channel, version, query)

def get_filtered_test_builds(self, channel, version=None, query=None):
# We don't have pre-release builds yet
return []

def get_download_url(self, channel, type=None):
if channel == 'alpha':
return self.aurora_urls[type] % self.latest_version('alpha')
Expand All @@ -266,8 +403,8 @@ def get_download_url(self, channel, type=None):
return self.store_url


class FirefoxIOS(ProductDetails):
channel_map = {
class FirefoxIOS(_ProductDetails):
version_map = {
'release': 'version',
}
store_url = settings.APPLE_APPSTORE_FIREFOX_LINK
Expand Down
6 changes: 5 additions & 1 deletion bedrock/firefox/helpers.py
Expand Up @@ -201,9 +201,13 @@ def firefox_url(platform, page, channel=None):

if channel:
kwargs['channel'] = channel
if page == 'notes' and platform != 'desktop':
if platform != 'desktop':
kwargs['platform'] = platform

# Firefox for Android and iOS have the system requirements page on SUMO
if platform in ['android', 'ios'] and page == 'sysreq':
return settings.FIREFOX_MOBILE_SYSREQ_URL

return reverse('firefox.%s' % page, kwargs=kwargs)


Expand Down

0 comments on commit e3f844a

Please sign in to comment.