Beispiel #1
0
def build_site(lang):
    context = {'LANG': lang, 'DIR': text_dir(lang)}

    outpath = os.path.join(renderpath, lang)
    if not os.path.exists(outpath):
        os.makedirs(outpath)
    site = make_site(outpath=outpath,
                     searchpath=searchpath,
                     extensions=extensions,
                     env_globals=context)

    translator = translate.Translation(lang,
                                       ['thunderbird/start/release', 'main'])
    gettext_translator = translate.gettext_object(lang)
    site._env.install_gettext_translations(gettext_translator)

    def l10n_has_tag(tag):
        return tag in translator.lang_file_tag_set('thunderbird/start/release',
                                                   lang)

    # Add l10n_css function to context
    site._env.globals.update(l10n_css=translator.l10n_css,
                             l10n_has_tag=l10n_has_tag,
                             **helper.contextfunctions)
    site.render(use_reloader=False)
    shutil.rmtree(renderpath + '/media', ignore_errors=True)
    shutil.copytree(staticpath, renderpath + '/media')
Beispiel #2
0
 def _switch_lang(self, lang):
     """Switch current `lang` for build and update gettext translations accordingly."""
     self.lang = lang
     self._set_context()
     self._env.globals.update(self.context)
     translator = translate.gettext_object(lang)
     self._env.install_gettext_translations(translator)
     self._env.globals.update(translations=translator.get_translations(), l10n_css=translator.l10n_css)
Beispiel #3
0
def download_thunderbird(ctx,
                         channel='release',
                         dom_id=None,
                         locale=None,
                         force_direct=False,
                         alt_copy=None,
                         button_color='button-green'):
    """ Output a "Download Thunderbird" button.

    :param ctx: context from calling template.
    :param channel: name of channel: 'release', 'beta' or 'alpha'.
    :param dom_id: Use this string as the id attr on the element.
    :param locale: The locale of the download. Default to locale of request.
    :param force_direct: Force the download URL to be direct.
    :param alt_copy: Specifies alternate copy to use for download buttons.
    :param button_color: color of download button. Default to 'green'.
    :return: The button html.
    """
    alt_channel = '' if channel == 'release' else channel
    locale = ctx.get('LANG', None)
    dom_id = dom_id or 'download-button-desktop-%s' % channel

    l_version = thunderbird_desktop.latest_builds(locale, channel)
    if l_version:
        version, platforms = l_version
    else:
        locale = 'en-US'
        version, platforms = thunderbird_desktop.latest_builds(
            'en-US', channel)

    # Gather data about the build for each platform
    builds = []

    for plat_os, plat_os_pretty in thunderbird_desktop.platform_labels.iteritems(
    ):
        # And generate all the info
        download_link = thunderbird_desktop.get_download_url(
            channel,
            version,
            plat_os,
            locale,
            force_direct=force_direct,
        )

        # If download_link_direct is False the data-direct-link attr
        # will not be output, and the JS won't attempt the IE popup.
        if force_direct:
            # no need to run get_download_url again with the same args
            download_link_direct = False
        else:
            download_link_direct = thunderbird_desktop.get_download_url(
                channel,
                version,
                plat_os,
                locale,
                force_direct=True,
            )
            if download_link_direct == download_link:
                download_link_direct = False

        builds.append({
            'os': plat_os,
            'os_pretty': plat_os_pretty,
            'download_link': download_link,
            'download_link_direct': download_link_direct
        })

    # Get the native name for current locale
    langs = thunderbird_desktop.languages
    locale_name = langs[locale]['native'] if locale in langs else locale

    data = {
        'locale_name': locale_name,
        'version': version,
        'product': 'thunderbird',
        'builds': builds,
        'id': dom_id,
        'channel': alt_channel,
        'alt_copy': alt_copy,
        'button_color': button_color,
    }
    loader = jinja2.FileSystemLoader(searchpath=settings.WEBSITE_PATH)
    env = jinja2.Environment(loader=loader, extensions=['jinja2.ext.i18n'])
    translator = translate.gettext_object(locale)
    env.install_gettext_translations(translator)
    env.globals.update(**ctx)
    template = env.get_template('_includes/download-button.html')

    html = template.render(data)
    return jinja2.Markup(html)
def build_site(lang):
    version = helper.thunderbird_desktop.latest_version('release')
    caldata = helper.load_calendar_json('media/caldata/calendars.json')
    context = {
        'LANG':
        lang,
        'current_year':
        date.today().year,
        'DIR':
        text_dir(lang),
        'platform':
        'desktop',
        'query':
        '',
        'platforms':
        helper.thunderbird_desktop.platforms('release'),
        'full_builds_version':
        version.split('.', 1)[0],
        'full_builds':
        helper.thunderbird_desktop.get_filtered_full_builds(
            'release', helper.thunderbird_desktop.latest_version()),
        'full_builds_beta':
        helper.thunderbird_desktop.get_filtered_full_builds(
            'beta', helper.thunderbird_desktop.latest_version('beta')),
        'channel_label':
        'Thunderbird',
        'releases':
        helper.thunderbird_desktop.list_releases(),
        'calendars':
        caldata['calendars'],
        'letters':
        caldata['letters'],
        'CALDATA_URL':
        settings.CALDATA_URL,
        'latest_thunderbird_version':
        version,
    }

    outpath = os.path.join(renderpath, lang)
    if not os.path.exists(outpath):
        os.makedirs(outpath)
    site = make_site(outpath=outpath,
                     searchpath=searchpath,
                     extensions=extensions,
                     env_globals=context)

    translator = translate.Translation(lang, [
        'thunderbird/index', 'thunderbird/features', 'thunderbird/channel',
        'main', 'download_button'
    ])
    gettext_translator = translate.gettext_object(lang)
    site._env.install_gettext_translations(gettext_translator)

    def l10n_has_tag(tag):
        return tag in translator.lang_file_tag_set('thunderbird/features',
                                                   lang)

    # Add l10n_css function to context.
    site._env.globals.update(translations=translator.get_translations(),
                             l10n_css=translator.l10n_css,
                             l10n_has_tag=l10n_has_tag,
                             settings=settings,
                             **helper.contextfunctions)
    site._env.filters["markdown"] = helper.safe_markdown
    site._env.filters["f"] = helper.f
    site._env.filters["l10n_format_date"] = helper.l10n_format_date
    site.render(use_reloader=False)

    # Render release notes and system requirements for en-US only.
    if lang == settings.LANGUAGE_CODE:
        notelist = releasenotes.notes
        e = site._env
        template = e.get_template('_includes/release-notes.html')
        e.globals.update(feedback=releasenotes.settings["feedback"],
                         bugzilla=releasenotes.settings["bugzilla"])
        for k, n in notelist.iteritems():
            if 'beta' in k:
                e.globals.update(channel='Beta', channel_name='Beta')
            else:
                e.globals.update(channel='Release', channel_name='Release')
            n["release"]["release_date"] = n["release"].get(
                "release_date", helper.thunderbird_desktop.get_release_date(k))

            # If there's no data at all, we can't parse an empty string for a date.
            if n["release"]["release_date"]:
                n["release"]["release_date"] = parse(
                    str(n["release"]["release_date"]))
            e.globals.update(**n)
            target = os.path.join(outpath, 'thunderbird', str(k),
                                  'releasenotes')
            mkdir(target)
            with open(os.path.join(target, 'index.html'), "wb") as f:
                print "Rendering {0}/index.html...".format(target)
                o = template.render()
                f.write(o.encode('utf8'))

            target = os.path.join(outpath, 'thunderbird', str(k),
                                  'system-requirements')
            mkdir(target)
            newtemplate = e.get_template('_includes/system_requirements.html')
            with open(os.path.join(target, 'index.html'), "wb") as f:
                print "Rendering {0}/index.html...".format(target)
                o = newtemplate.render()
                f.write(o.encode('utf8'))

        # Build htaccess files for sysreq and release notes redirects.
        print "Writing htaccess files..."
        sysreq_path = os.path.join(renderpath, 'system-requirements')
        notes_path = os.path.join(renderpath, 'notes')
        write_htaccess(
            sysreq_path, settings.CANONICAL_URL +
            helper.thunderbird_url('system-requirements'))
        write_htaccess(
            notes_path,
            settings.CANONICAL_URL + helper.thunderbird_url('releasenotes'))