Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: mozharness/abb/transform_locales.py

Issue 29552607: Issue 5375 - ABB Widget has Google as default search engine instead of Duck Duck Go (Closed)
Patch Set: Created Sept. 22, 2017, 11:11 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | mozharness/mozilla/l10n/multi_locale_build.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mozharness/abb/transform_locales.py
===================================================================
--- a/mozharness/abb/transform_locales.py
+++ b/mozharness/abb/transform_locales.py
@@ -10,37 +10,41 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
import os
import re
+import sys
_LOCALE_RE = re.compile("^([a-z]{2,3}(?:-[A-Z]{2})?)$")
_VALUES_LOCALE_RE = re.compile("^values-([a-z]{2,3}(?:-r[A-Z]{2})?)$")
_SEARCH_PROPS_RE = re.compile("^browser\.search\."
"(defaultenginename|order\.).*$")
_SHORTNAME_RE = re.compile("^<ShortName>(.*)</ShortName>$")
_PROPERTY_FORMAT_RE = re.compile("^(([^=]*)=)(.*)$")
_ENTITY_FORMAT_RE = re.compile("^(\s*<!ENTITY\s*([^\"\s]*)\s*\")(.*)(\">)$")
_STRING_FORMAT_RE = re.compile(
"^(\s*<string name=\"([^\"]*)\">)(.*)(</string>)$")
+_MOZBUILD_PATH = os.path.join("python", "mozbuild")
+
_CHROME_PATH = os.path.join("dist", "bin", "chrome")
_RES_PATH = os.path.join("mobile", "android", "base", "res")
-_SEARCHPLUGINS_PATH = os.path.join("browser", "searchplugins")
+_BROWSER_DIR = "browser"
+_SEARCHPLUGINS_PATH = os.path.join(_BROWSER_DIR, "searchplugins")
_LIST_TXT_PATH = os.path.join(_SEARCHPLUGINS_PATH, "list.txt")
-_REGION_PROPS_PATH = os.path.join("browser", "region.properties")
+_REGION_PROPS_PATH = os.path.join(_BROWSER_DIR, "region.properties")
-_APPSTRINGS_PROPS_PATH = os.path.join("browser", "appstrings.properties")
+_APPSTRINGS_PROPS_PATH = os.path.join(_BROWSER_DIR, "appstrings.properties")
_STRINGS_XML_PATH = "strings.xml"
_DEFAULT_LOCALE = "en-US"
_SEARCH_ENGINE_ORDER = {
"en-US": ["duckduckgo",
"yahoo",
"google",
@@ -234,16 +238,33 @@ def _transform_locale(locale, path, logg
lines.append(line)
# Apply changes to appstrings.properties
_write_lines(appstrings_file_path, lines)
logger.info("Replaced %d ocurrences of %s in 'appstrings.properties'" %
(replacement_count, _FIREFOX_REPLACE_STR))
+def _generate_browser_search(locale, locale_path, res_path, build_dir):
+ raw_dir = "raw" if locale == _DEFAULT_LOCALE else (
+ "raw-%s" % locale.replace("-", "-r"))
+
+ browser_path = os.path.join(locale_path, _BROWSER_DIR)
+ browsersearch_file_path = os.path.join(res_path, raw_dir,
+ "browsersearch.json")
+
+ sys.path.append(os.path.join(build_dir, _MOZBUILD_PATH))
+ import mozbuild.action.generate_browsersearch as generate_browsersearch
+
+ # Call generate_browsersearch.py script to regenerate
+ # res/raw-LOCALE/browsersearch.json with the updated search engines
+ generate_browsersearch.main(["--verbose", "--srcdir", browser_path,
+ browsersearch_file_path])
+
+
def _transform_values_locale(locale, path, logger):
logger.info("Processing values-%s..." % locale)
# Check for strings.xml existence
strings_file_path = os.path.join(path, _STRINGS_XML_PATH)
_check_path_exists(strings_file_path, logger)
# Replaces ocurrences of 'Firefox' by 'Adblock Browser' in 'strings.xml'
@@ -282,17 +303,17 @@ class MinimalLogger:
def error(self, s):
print "ERROR: %s" % s
def fatal(self, s):
print "FATAL: %s" % s
exit(1)
-def transform_locales(obj_dir, logger=MinimalLogger()):
+def transform_locales(build_dir, obj_dir, logger=MinimalLogger()):
chrome_path = os.path.join(obj_dir, _CHROME_PATH)
_check_path_exists(chrome_path, logger)
res_path = os.path.join(obj_dir, _RES_PATH)
_check_path_exists(res_path, logger)
locales = _get_locales_from_path(chrome_path, _LOCALE_RE)
values_locales = _get_locales_from_path(res_path, _VALUES_LOCALE_RE)
@@ -300,15 +321,16 @@ def transform_locales(obj_dir, logger=Mi
locales_found_msg = "Found %d locales in %s"
logger.info(locales_found_msg % (len(locales), chrome_path))
logger.info(locales_found_msg % (len(values_locales), res_path))
for locale in locales:
locale_path = os.path.join(chrome_path, locale, "locale", locale)
if os.path.exists(locale_path):
_transform_locale(locale, locale_path, logger)
+ _generate_browser_search(locale, locale_path, res_path, build_dir)
else:
logger.error("Missing folder for locale '%s' in path: %s" %
(locale, locale_path))
for locale in values_locales:
locale_path = os.path.join(res_path, "values-" + locale)
_transform_values_locale(locale, locale_path, logger)
« no previous file with comments | « no previous file | mozharness/mozilla/l10n/multi_locale_build.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld