DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Git (5daaab71bb)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
import sys
import os
pathToLib = os.path.join(os.path.dirname(__file__), "../kickoff/")  # NOQA
sys.path.append(pathToLib)  # NOQA
import json
import ConfigParser
import StringIO
import urllib2
from collections import OrderedDict
from config import SUPPORTED_NIGHTLY_LOCALES


def readConfFile(url):
    print("Synchronizing from " + url)
    response = urllib2.urlopen(url)
    content = response.read()
    ini_str = '[root]\n' + content
    ini_fp = StringIO.StringIO(ini_str)
    config = ConfigParser.RawConfigParser()
    config.readfp(ini_fp)
    return config.items('root')


def saveJSON(url, country):
    countries = readConfFile(url)
    valuesOrdered = OrderedDict(sorted(dict(countries).items(), key=lambda x: x[1]))
    dump = json.dumps(valuesOrdered, indent=4, separators=(',', ': '))

    # Save
    with open(pathToLib + "/static/regions/%s.json" % country, "w") as text_file:
        text_file.write(dump)


def getListLocalesFromURL(URL):
    response = urllib2.urlopen(URL)
    return response.read().splitlines()

# Get regionNames.properties for en-US from mozilla-central
enUSURL = "https://hg.mozilla.org/mozilla-central/raw-file/tip/toolkit/locales/en-US/chrome/global/regionNames.properties"
saveJSON(enUSURL, "en-US")

# Get the list of locales on Nightly for desktop
listDesktopNightlyLocalesURL = "https://hg.mozilla.org/mozilla-central/raw-file/default/browser/locales/all-locales"
remoteDesktopNightlyLocalesList = getListLocalesFromURL(listDesktopNightlyLocalesURL)
# Get the list of locales on Nightly for Android
listAndroidNightlyLocalesURL = "https://hg.mozilla.org/mozilla-central/raw-file/default/mobile/android/locales/all-locales"
remoteAndroidNightlyLocalesList = getListLocalesFromURL(listAndroidNightlyLocalesURL)

# Build the list of all locales available on Nightly
remoteNightlyLocalesList = list(set(remoteAndroidNightlyLocalesList + remoteDesktopNightlyLocalesList))
remoteNightlyLocalesList.sort()

warnings = []
missingLocales = []
for locale in remoteNightlyLocalesList:
    try:
        url = "https://hg.mozilla.org/l10n-central/%s/raw-file/tip/toolkit/chrome/global/regionNames.properties" % locale
        saveJSON(url, locale)
        if locale not in SUPPORTED_NIGHTLY_LOCALES:
            missingLocales.append(locale)
    except:
        warnings.append("Warning: regionNames.properties is not available for %s" % locale)
for locale in missingLocales:
    warnings.append("Warning: '%s' NOT found in SUPPORTED_NIGHTLY_LOCALES" % locale)
if warnings:
    print ("\n".join(warnings))
print("Sanity check: %d locales not in SUPPORTED_NIGHTLY_LOCALES (1 expected: zam)" % len(missingLocales))

print("Note that ship-it IS the source of truth for supported locales")
print("Please report a bug to have a locale added/remove: https://bugzilla.mozilla.org/enter_bug.cgi?product=Release%20Engineering&component=Ship%20It")