Bug 1328713 - Allow region specific overrides of search engines. r=florian a=gchang
authorMichael Kaply <mozilla@kaply.com>
Thu, 02 Feb 2017 12:31:57 -0600
changeset 376036 7bab8cf2a1cf936aeeceb61d8f791ff8f4e9223b
parent 376035 bc736e4fab076b947c7918dba41af3d015e3ad22
child 376037 75bda9957ea872ab71fbfa63c8f4d57e2458afb6
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian, gchang
bugs1328713
milestone53.0a2
Bug 1328713 - Allow region specific overrides of search engines. r=florian a=gchang MozReview-Commit-ID: 62BjDdIlpgZ
browser/locales/search/list.json
python/mozbuild/mozbuild/action/generate_searchjson.py
python/mozbuild/mozbuild/action/output_searchplugins_list.py
--- a/browser/locales/search/list.json
+++ b/browser/locales/search/list.json
@@ -1,31 +1,53 @@
 {
   "default": {
     "visibleDefaultEngines": [
       "google", "yahoo", "amazondotcom", "bing", "ddg", "twitter", "wikipedia"
     ]
   },
+  "regionOverrides": {
+    "US": {
+      "google": "google-nocodes"
+    },
+    "CA": {
+      "google": "google-nocodes"
+    },
+    "KZ": {
+      "google": "google-nocodes"
+    },
+    "BY": {
+      "google": "google-nocodes"
+    },
+    "RU": {
+      "google": "google-nocodes"
+    },
+    "TR": {
+      "google": "google-nocodes"
+    },
+    "UA": {
+      "google": "google-nocodes"
+    },
+    "CN": {
+      "google": "google-nocodes"
+    },
+    "TW": {
+      "google": "google-nocodes"
+    },
+    "HK": {
+      "google": "google-nocodes"
+    }
+  },
   "locales": {
     "en-US": {
       "default": {
         "visibleDefaultEngines": [
           "google", "yahoo", "amazondotcom", "bing", "ddg", "twitter", "wikipedia"
         ]
       },
-      "US": {
-        "visibleDefaultEngines": [
-          "yahoo", "google-nocodes", "bing", "amazondotcom", "ddg", "twitter", "wikipedia"
-        ]
-      },
-      "CA": {
-        "visibleDefaultEngines": [
-          "google-nocodes", "yahoo", "bing", "amazondotcom", "ddg", "twitter", "wikipedia"
-        ]
-      },
       "experimental-hidden": {
         "visibleDefaultEngines": [
           "yahoo-en-CA"
         ]
       }
     },
     "ach": {
       "default": {
@@ -391,41 +413,16 @@
         ]
       }
     },
     "kk": {
       "default": {
         "visibleDefaultEngines": [
           "yandex-kk", "google", "ddg", "flip", "kaz-kk", "twitter", "wikipedia-kk"
         ]
-      },
-      "KZ": {
-        "visibleDefaultEngines": [
-          "yandex-kk", "google-nocodes", "ddg", "flip", "kaz-kk", "twitter", "wikipedia-kk"
-        ]
-      },
-      "BY": {
-        "visibleDefaultEngines": [
-          "yandex-kk", "google-nocodes", "ddg", "flip", "kaz-kk", "twitter", "wikipedia-kk"
-        ]
-      },
-      "RU": {
-        "visibleDefaultEngines": [
-          "yandex-kk", "google-nocodes", "ddg", "flip", "kaz-kk", "twitter", "wikipedia-kk"
-        ]
-      },
-      "TR": {
-        "visibleDefaultEngines": [
-          "yandex-kk", "google-nocodes", "ddg", "flip", "kaz-kk", "twitter", "wikipedia-kk"
-        ]
-      },
-      "UA": {
-        "visibleDefaultEngines": [
-          "yandex-kk", "google-nocodes", "ddg", "flip", "kaz-kk", "twitter", "wikipedia-kk"
-        ]
       }
     },
     "km": {
       "default": {
         "visibleDefaultEngines": [
           "google", "yahoo", "bing", "amazondotcom", "ddg", "twitter", "wikipedia-km"
         ]
       }
@@ -591,41 +588,16 @@
         ]
       }
     },
     "ru": {
       "default": {
         "visibleDefaultEngines": [
           "yandex-ru", "google", "ddg", "ozonru", "priceru", "wikipedia-ru", "mailru"
         ]
-      },
-      "RU": {
-        "visibleDefaultEngines": [
-          "yandex-ru", "google-nocodes", "ddg", "ozonru", "priceru", "wikipedia-ru", "mailru"
-        ]
-      },
-      "BY": {
-        "visibleDefaultEngines": [
-          "yandex-ru", "google-nocodes", "ddg", "ozonru", "priceru", "wikipedia-ru", "mailru"
-        ]
-      },
-      "KZ": {
-        "visibleDefaultEngines": [
-          "yandex-ru", "google-nocodes", "ddg", "ozonru", "priceru", "wikipedia-ru", "mailru"
-        ]
-      },
-      "TR": {
-        "visibleDefaultEngines": [
-          "yandex-ru", "google-nocodes", "ddg", "ozonru", "priceru", "wikipedia-ru", "mailru"
-        ]
-      },
-      "UA": {
-        "visibleDefaultEngines": [
-          "yandex-ru", "google-nocodes", "ddg", "ozonru", "priceru", "wikipedia-ru", "mailru"
-        ]
       }
     },
     "si": {
       "default": {
         "visibleDefaultEngines": [
           "google", "yahoo", "amazondotcom", "ddg", "wikipedia-si"
         ]
       }
@@ -700,73 +672,23 @@
         ]
       }
     },
     "tr": {
       "default": {
         "visibleDefaultEngines": [
           "yandex-tr", "google", "ddg", "twitter", "wikipedia-tr"
         ]
-      },
-      "TR": {
-        "visibleDefaultEngines": [
-          "yandex-tr", "google-nocodes", "ddg", "twitter", "wikipedia-tr"
-        ]
-      },
-      "BY": {
-        "visibleDefaultEngines": [
-          "yandex-tr", "google-nocodes", "ddg", "twitter", "wikipedia-tr"
-        ]
-      },
-      "KZ": {
-        "visibleDefaultEngines": [
-          "yandex-tr", "google-nocodes", "ddg", "twitter", "wikipedia-tr"
-        ]
-      },
-      "RU": {
-        "visibleDefaultEngines": [
-          "yandex-tr", "google-nocodes", "ddg", "twitter", "wikipedia-tr"
-        ]
-      },
-      "UA": {
-        "visibleDefaultEngines": [
-          "yandex-tr", "google-nocodes", "ddg", "twitter", "wikipedia-tr"
-        ]
       }
     },
     "uk": {
       "default": {
         "visibleDefaultEngines": [
           "google", "yandex-uk", "meta-ua", "ddg", "wikipedia-uk", "metamarket"
         ]
-      },
-      "UA": {
-        "visibleDefaultEngines": [
-          "google-nocodes", "yandex-uk", "meta-ua", "ddg", "wikipedia-uk", "metamarket"
-        ]
-      },
-      "TR": {
-        "visibleDefaultEngines": [
-          "google-nocodes", "yandex-uk", "meta-ua", "ddg", "wikipedia-uk", "metamarket"
-        ]
-      },
-      "BY": {
-        "visibleDefaultEngines": [
-          "google-nocodes", "yandex-uk", "meta-ua", "ddg", "wikipedia-uk", "metamarket"
-        ]
-      },
-      "KZ": {
-        "visibleDefaultEngines": [
-          "google-nocodes", "yandex-uk", "meta-ua", "ddg", "wikipedia-uk", "metamarket"
-        ]
-      },
-      "RU": {
-        "visibleDefaultEngines": [
-          "google-nocodes", "yandex-uk", "meta-ua", "ddg", "wikipedia-uk", "metamarket"
-        ]
       }
     },
     "ur": {
       "default": {
         "visibleDefaultEngines": [
           "google", "yahoo-in", "bing", "amazon-in", "ddg", "twitter", "wikipedia-ur"
         ]
       }
@@ -806,22 +728,12 @@
         ]
       }
     },
     "zh-TW": {
       "default": {
         "visibleDefaultEngines": [
           "yahoo-zh-TW", "google", "ddg", "findbook-zh-TW", "wikipedia-zh-TW", "yahoo-zh-TW-HK", "yahoo-bid-zh-TW", "yahoo-answer-zh-TW"
         ]
-      },
-      "TW": {
-        "visibleDefaultEngines": [
-          "yahoo-zh-TW", "google-nocodes", "ddg", "findbook-zh-TW", "wikipedia-zh-TW", "yahoo-zh-TW-HK", "yahoo-bid-zh-TW", "yahoo-answer-zh-TW"
-        ]
-      },
-      "HK": {
-        "visibleDefaultEngines": [
-          "yahoo-zh-TW-HK", "google-nocodes", "ddg", "findbook-zh-TW", "wikipedia-zh-TW", "yahoo-zh-TW", "yahoo-bid-zh-TW", "yahoo-answer-zh-TW"
-        ]
       }
     }
   }
 }
--- a/python/mozbuild/mozbuild/action/generate_searchjson.py
+++ b/python/mozbuild/mozbuild/action/generate_searchjson.py
@@ -1,23 +1,44 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 import sys
 import json
+import copy
 
 engines = []
 
 locale = sys.argv[2]
 output_file = sys.argv[3]
 
 output = open(output_file, 'w')
 
 with open(sys.argv[1]) as f:
   searchinfo = json.load(f)
 
 if locale in searchinfo["locales"]:
-  output.write(json.dumps(searchinfo["locales"][locale]))
+  localeSearchInfo = searchinfo["locales"][locale]
 else:
-  output.write(json.dumps(searchinfo["default"]))
+  localeSearchInfo = {}
+  localeSearchInfo["default"] = searchinfo["default"]
+
+# If we have region overrides, enumerate through them
+# and add the additional regions to the locale information.
+if "regionOverrides" in searchinfo:
+  regionOverrides = searchinfo["regionOverrides"]
+
+  for region in regionOverrides:
+    if not region in localeSearchInfo:
+      # Only add the region if it has engines that need to be overridden
+      if set(localeSearchInfo["default"]["visibleDefaultEngines"]) & set(regionOverrides[region].keys()):
+        localeSearchInfo[region] = copy.deepcopy(localeSearchInfo["default"])
+      else:
+        continue
+    for i, engine in enumerate(localeSearchInfo[region]["visibleDefaultEngines"]):
+      for engineToReplace in regionOverrides[region]:
+        if engine == engineToReplace:
+          localeSearchInfo[region]["visibleDefaultEngines"][i] = regionOverrides[region][engineToReplace]
+
+output.write(json.dumps(localeSearchInfo))
 
 output.close();
--- a/python/mozbuild/mozbuild/action/output_searchplugins_list.py
+++ b/python/mozbuild/mozbuild/action/output_searchplugins_list.py
@@ -7,15 +7,25 @@ import json
 
 engines = []
 
 locale = sys.argv[2]
 
 with open(sys.argv[1]) as f:
   searchinfo = json.load(f)
 
+# Get a list of the engines from the locale or the default
+engines = set()
 if locale in searchinfo["locales"]:
-  for region in searchinfo["locales"][locale]:
-    engines = list(set(engines)|set(searchinfo["locales"][locale][region]["visibleDefaultEngines"]))
+  for region, table in searchinfo["locales"][locale].iteritems():
+    engines.update(table["visibleDefaultEngines"])
 else:
-  engines = searchinfo["default"]["visibleDefaultEngines"]
+  engines.update(searchinfo["default"]["visibleDefaultEngines"])
 
+# Get additional engines from regionOverrides
+for region, overrides in searchinfo["regionOverrides"].iteritems():
+  for originalengine, replacement in overrides.iteritems():
+    if originalengine in engines:
+      # We add the engine because we still need the original
+      engines.add(replacement)
+
+# join() will take an iterable, not just a list.
 print '\n'.join(engines)