python/mozbuild/mozbuild/action/output_searchplugins_list.py
author Michael Kaply <mozilla@kaply.com>
Thu, 02 Feb 2017 12:31:57 -0600
changeset 376036 7bab8cf2a1cf936aeeceb61d8f791ff8f4e9223b
parent 362569 f668770cfb69bf698ad6ad59ca0fd3cdf1f60686
child 427024 dfb510e198b8761964837f2bc404ec1bd985ffed
permissions -rw-r--r--
Bug 1328713 - Allow region specific overrides of search engines. r=florian a=gchang MozReview-Commit-ID: 62BjDdIlpgZ

# 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

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, table in searchinfo["locales"][locale].iteritems():
    engines.update(table["visibleDefaultEngines"])
else:
  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)