Bug 1123980 - Part 2: Write region-specific search settings into res/raw/browsersearch.json. r=mfinkle

Pushing on a CLOSED TREE since Android build only.

--HG--
extra : rebase_source : cc99efa734d1f4738d3f026c930a4d1955723783
extra : amend_source : 52c07807a77f263d2eb2593826dc0285928d9be4
This commit is contained in:
Nick Alexander 2015-01-20 16:27:27 -08:00
parent 2b2f357b64
commit 524a7bb865

View File

@ -12,13 +12,21 @@ This script follows these steps:
srcdir option). Merge all properties into a single dict accounting for the
priority of source directories.
2. Read the default search plugin from the 'browser.search.defaultenginename'.
2. Read the default search plugin from 'browser.search.defaultenginename'.
3. Read the list of search plugins from the 'browser.search.order.INDEX'
properties with values identifying particular search plugins by name.
4. Generate a JSON representation of 2. and 3., and write the result to
browsersearch.json in the locale-specific raw resource directory
4. Read each region-specific default search plugin from each property named like
'browser.search.defaultenginename.REGION'.
5. Read the list of region-specific search plugins from the
'browser.search.order.REGION.INDEX' properties with values identifying
particular search plugins by name. Here, REGION is derived from a REGION for
which we have seen a region-specific default plugin.
6. Generate a JSON representation of the above information, and write the result
to browsersearch.json in the locale-specific raw resource directory
e.g. raw/browsersearch.json, raw-pt-rBR/browsersearch.json.
'''
@ -72,11 +80,12 @@ def main(args):
# Use reversed order so that the first srcdir has higher priority to override keys.
properties = merge_properties('region.properties', reversed(opts.srcdir))
# Default, not region-specific.
default = properties.get('browser.search.defaultenginename')
engines = properties.get_list('browser.search.order')
writer = codecs.getwriter('utf-8')(sys.stdout)
if opts.verbose:
writer = codecs.getwriter('utf-8')(sys.stdout)
print('Read {len} engines: {engines}'.format(len=len(engines), engines=engines), file=writer)
print("Default engine is '{default}'.".format(default=default), file=writer)
@ -84,6 +93,25 @@ def main(args):
browsersearch['default'] = default
browsersearch['engines'] = engines
# This gets defaults, yes; but it also gets the list of regions known.
regions = properties.get_dict('browser.search.defaultenginename')
browsersearch['regions'] = {}
for region in regions.keys():
region_default = regions[region]
region_engines = properties.get_list('browser.search.order.{region}'.format(region=region))
if opts.verbose:
print("Region '{region}': Read {len} engines: {region_engines}".format(
len=len(region_engines), region=region, region_engines=region_engines), file=writer)
print("Region '{region}': Default engine is '{region_default}'.".format(
region=region, region_default=region_default), file=writer)
browsersearch['regions'][region] = {
'default': region_default,
'engines': region_engines,
}
# FileAvoidWrite creates its parent directories.
output = os.path.abspath(opts.output)
fh = FileAvoidWrite(output)