Bug 1123980 - Part 2: Write region-specific search settings into res/raw/browsersearch.json. r=mfinkle a=sylvestre
authorNick Alexander <nalexander@mozilla.com>
Tue, 20 Jan 2015 16:27:27 -0800
changeset 243726 05befa69d765
parent 243725 923404bb30ac
child 243727 5d37d11b64f2
push id4452
push usermfinkle@mozilla.com
push date2015-02-09 17:44 +0000
treeherdermozilla-beta@05befa69d765 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle, sylvestre
bugs1123980
milestone36.0
Bug 1123980 - Part 2: Write region-specific search settings into res/raw/browsersearch.json. r=mfinkle a=sylvestre Pushing on a CLOSED TREE since Android build only.
python/mozbuild/mozbuild/action/generate_browsersearch.py
--- a/python/mozbuild/mozbuild/action/generate_browsersearch.py
+++ b/python/mozbuild/mozbuild/action/generate_browsersearch.py
@@ -7,23 +7,31 @@
 Script to generate the browsersearch.json file for Fennec.
 
 This script follows these steps:
 
 1. Read the region.properties file in all the given source directories (see
 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.
 '''
 
 from __future__ import (
     print_function,
     unicode_literals,
 )
 
@@ -67,28 +75,48 @@ def main(args):
                         help='directories to read inputs from, in order of priority')
     parser.add_argument('output', metavar='OUTPUT',
                         help='output')
     opts = parser.parse_args(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)
 
     browsersearch = {}
     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)
     json.dump(browsersearch, fh)
     existed, updated = fh.close()
 
     if not opts.silent:
         if updated: