| Index: mozharness/abb/transform_locales.py |
| =================================================================== |
| --- a/mozharness/abb/transform_locales.py |
| +++ b/mozharness/abb/transform_locales.py |
| @@ -16,76 +16,33 @@ |
| import os |
| import re |
| import shutil |
|
diegocarloslima
2017/12/05 10:09:40
This seems to not be required anymore
jens
2017/12/05 10:46:09
Acknowledged.
|
| 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") |
| _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_DIR, "region.properties") |
| _APPSTRINGS_PROPS_PATH = os.path.join(_BROWSER_DIR, "appstrings.properties") |
| _STRINGS_XML_PATH = "strings.xml" |
| _DEFAULT_LOCALE = "en-US" |
| -# Add Ecosia as secondary search engine. |
| -# See https://issues.adblockplus.org/ticket/5518 |
| -_ECOSIA_ID = "ecosia" |
| -_ECOSIA_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), |
| - "ecosia.xml") |
| - |
| -_SEARCH_ENGINE_ORDER_DEFAULT = [ |
| - "duckduckgo", |
| - "yahoo", |
| - "google", |
| - "wikipedia", |
| - "amazon"] |
| - |
| -_SEARCH_ENGINE_ORDER_ECOSIA = [ |
| - "duckduckgo", |
| - "yahoo", |
| - "google", |
| - _ECOSIA_ID, |
| - "wikipedia", |
| - "amazon"] |
| - |
| -_SEARCH_ENGINE_ORDER = { |
| - "de": _SEARCH_ENGINE_ORDER_ECOSIA, |
| - "en-GB": _SEARCH_ENGINE_ORDER_ECOSIA, |
| - "en-US": _SEARCH_ENGINE_ORDER_ECOSIA, |
| - "fr": _SEARCH_ENGINE_ORDER_ECOSIA, |
| - "nl": _SEARCH_ENGINE_ORDER_ECOSIA, |
| - "zh-CN": ["baidu", |
| - "duckduckgo", |
| - "yahoo", |
| - "google", |
| - "wikipedia", |
| - "amazon" |
| - ] |
| -} |
| - |
| _FIREFOX_REPLACE_STR = "Firefox" |
| _ABB_REPLACEMENT_STR = "Adblock Browser" |
| # Some string values that contain Firefox such as 'Firefox Sync' shouldn't be |
| # replaced, so we keep a list of ids that are exceptions |
| _ENTITY_EXCEPTIONS = [ |
| "overlay_no_synced_devices", |
| "home_remote_tabs_need_to_sign_in", |
| @@ -151,118 +108,20 @@ def _write_lines(filename, lines): |
| with open(filename, "w") as fd: |
| for l in lines: |
| fd.write("%s\n" % l) |
| def _transform_locale(locale, path, logger): |
| logger.info("Processing locale '%s'..." % locale) |
| - # Check for list.txt existence |
| - list_file_path = os.path.join(path, _LIST_TXT_PATH) |
| - _check_path_exists(list_file_path, logger) |
| - |
| - # Check for region.properties existence |
| - region_file_path = os.path.join(path, _REGION_PROPS_PATH) |
| - _check_path_exists(region_file_path, logger) |
| - |
| # Check for appstrings.properties existence |
| appstrings_file_path = os.path.join(path, _APPSTRINGS_PROPS_PATH) |
| _check_path_exists(appstrings_file_path, logger) |
| - ecosia_dst = os.path.join(path, _SEARCHPLUGINS_PATH, |
| - os.path.basename(_ECOSIA_PATH)) |
| - |
| - # Get whitelist and build regex |
| - whitelist = _SEARCH_ENGINE_ORDER.get(locale, |
| - _SEARCH_ENGINE_ORDER_DEFAULT) |
| - white_re = re.compile("^(%s).*$" % "|".join(whitelist)) |
| - |
| - if _ECOSIA_ID in whitelist and not os.path.exists(ecosia_dst): |
| - shutil.copyfile(_ECOSIA_PATH, ecosia_dst) |
| - |
| - # Read engine IDs from list.txt, discard engines not on whitelist |
| - all_engine_ids = [] |
| - engine_ids = [] |
| - removed_engine_ids = [] |
| - with open(list_file_path, "r") as fd: |
| - for line in fd: |
| - line = line.strip() |
| - all_engine_ids.append(line) |
| - if len(line) > 0: |
| - if white_re.match(line): |
| - engine_ids.append(line) |
| - else: |
| - removed_engine_ids.append(line) |
| - |
| - if _ECOSIA_ID in whitelist and _ECOSIA_ID not in all_engine_ids: |
| - all_engine_ids.append(_ECOSIA_ID) |
| - engine_ids.append(_ECOSIA_ID) |
| - |
| - # Make sure we still have search engines left |
| - if len(engine_ids) == 0: |
| - logger.fatal("No search engines left over for '%s'" % locale) |
| - |
| - # 'Parse' XML to get matching 'ShortName' for all engine IDs |
| - engine_names = {} |
| - for eid in engine_ids[:]: |
| - xml_file_path = os.path.join(path, _SEARCHPLUGINS_PATH, "%s.xml" % eid) |
| - if not os.path.exists(xml_file_path): |
| - logger.info("Missing xml file for plugin %s. Searched in path %s" % |
| - (eid, xml_file_path)) |
| - engine_ids.remove(eid) |
| - continue |
| - short_name = None |
| - with open(xml_file_path, "r") as fd: |
| - for line in fd: |
| - line = line.strip() |
| - match = _SHORTNAME_RE.match(line) |
| - if match: |
| - short_name = match.group(1).strip() |
| - |
| - if not short_name: |
| - logger.fatal("No ShortName defined for '%s' in '%s" % |
| - (eid, locale)) |
| - engine_names[eid] = short_name |
| - |
| - logger.info("Removed search engine IDs: %s" % |
| - ", ".join(removed_engine_ids)) |
| - logger.info("Remaining search engine IDs: %s" % ", ".join(engine_ids)) |
| - |
| - # Create search engine order with real engine names |
| - engine_order = [] |
| - for eid in whitelist: |
| - sn = _get_shortname_from_id(eid, engine_ids, engine_names) |
| - if sn: |
| - engine_order.append(sn) |
| - |
| - logger.info("Resulting search engine ordered list: %s" % |
| - (", ".join(engine_order))) |
| - |
| - # Read region.properties and remove browser.search.* lines |
| - props = [] |
| - with open(region_file_path, "r") as fd: |
| - for line in fd: |
| - line = line.rstrip("\r\n") |
| - if not _SEARCH_PROPS_RE.match(line.strip()): |
| - props.append(line) |
| - |
| - # Append default search engine name |
| - props.append("browser.search.defaultenginename=%s" % engine_order[0]) |
| - |
| - # Append search engine order |
| - for i in range(0, min(5, len(engine_order))): |
| - props.append("browser.search.order.%d=%s" % (i + 1, engine_order[i])) |
| - |
| - # Write back list.txt |
| - _write_lines(list_file_path, all_engine_ids) |
| - |
| - # Write back region.properties |
| - _write_lines(region_file_path, props) |
| - |
| # Replaces ocurrences of 'Firefox' by 'Adblock Browser' in |
| # 'appstrings.properties' |
| lines = [] |
| replacement_count = 0 |
| with open(appstrings_file_path, "r") as fd: |
| for line in fd: |
| line = line.rstrip("\r\n") |