| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 1 # This file is part of Adblock Plus | 1 # This file is part of Adblock Plus |
| 2 # Copyright (C) 2006-present eyeo GmbH | 2 # Copyright (C) 2006-present eyeo GmbH |
| 3 # | 3 # |
| 4 # Adblock Plus is free software: you can redistribute it and/or modify | 4 # Adblock Plus is free software: you can redistribute it and/or modify |
| 5 # it under the terms of the GNU General Public License version 3 as | 5 # it under the terms of the GNU General Public License version 3 as |
| 6 # published by the Free Software Foundation. | 6 # published by the Free Software Foundation. |
| 7 # | 7 # |
| 8 # Adblock Plus is distributed in the hope that it will be useful, | 8 # Adblock Plus is distributed in the hope that it will be useful, |
| 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 _SEARCH_PROPS_RE = re.compile("^browser\.search\." | 25 _SEARCH_PROPS_RE = re.compile("^browser\.search\." |
| 26 "(defaultenginename|order\.).*$") | 26 "(defaultenginename|order\.).*$") |
| 27 _SHORTNAME_RE = re.compile("^<ShortName>(.*)</ShortName>$") | 27 _SHORTNAME_RE = re.compile("^<ShortName>(.*)</ShortName>$") |
| 28 | 28 |
| 29 _PROPERTY_FORMAT_RE = re.compile("^(([^=]*)=)(.*)$") | 29 _PROPERTY_FORMAT_RE = re.compile("^(([^=]*)=)(.*)$") |
| 30 _ENTITY_FORMAT_RE = re.compile("^(\s*<!ENTITY\s*([^\"\s]*)\s*\")(.*)(\">)$") | 30 _ENTITY_FORMAT_RE = re.compile("^(\s*<!ENTITY\s*([^\"\s]*)\s*\")(.*)(\">)$") |
| 31 _STRING_FORMAT_RE = re.compile( | 31 _STRING_FORMAT_RE = re.compile( |
| 32 "^(\s*<string name=\"([^\"]*)\">)(.*)(</string>)$") | 32 "^(\s*<string name=\"([^\"]*)\">)(.*)(</string>)$") |
| 33 | 33 |
| 34 _MOZBUILD_PATH = os.path.join("python", "mozbuild") | 34 _MOZBUILD_PATH = os.path.join("python", "mozbuild") |
| 35 | 35 _GENERATED_PATH = os.path.join("abb-build", "generated") |
| 36 _CHROME_PATH = os.path.join("dist", "bin", "chrome") | 36 _CHROME_PATH = os.path.join("dist", "bin", "chrome") |
| 37 _RES_PATH = os.path.join("mobile", "android", "base", "res") | 37 _RES_PATH = os.path.join("mobile", "android", "base", "res") |
| 38 _L10N_PATH = os.path.join("abb-build", "l10n") | |
| 39 _LOCALES_PATH = os.path.join("mobile", "locales") | 38 _LOCALES_PATH = os.path.join("mobile", "locales") |
| 40 _LISTJSON_PATH = os.path.join(_LOCALES_PATH, "search", "list.json") | 39 _LIST_JSON_FILE = "list.json" |
| 40 _LIST_JSON_PATH = os.path.join(_LOCALES_PATH, "search", _LIST_JSON_FILE) | |
| 41 _GENERATED_LIST_JSON_PATH = os.path.join(_GENERATED_PATH, _LIST_JSON_FILE) | |
| 41 _GENERAL_SEARCHPLUGINS_PATH = os.path.join(_LOCALES_PATH, "searchplugins") | 42 _GENERAL_SEARCHPLUGINS_PATH = os.path.join(_LOCALES_PATH, "searchplugins") |
| 42 | |
| 43 _BROWSER_DIR = "browser" | 43 _BROWSER_DIR = "browser" |
| 44 _REGION_PROPS_PATH = os.path.join(_BROWSER_DIR, "region.properties") | 44 _REGION_PROPS_PATH = os.path.join(_BROWSER_DIR, "region.properties") |
| 45 _LOCALE_SEARCHPLUGINS_PATH = os.path.join(_BROWSER_DIR, "searchplugins") | 45 _LOCALE_SEARCHPLUGINS_PATH = os.path.join(_BROWSER_DIR, "searchplugins") |
| 46 | |
| 47 _APPSTRINGS_PROPS_PATH = os.path.join(_BROWSER_DIR, "appstrings.properties") | 46 _APPSTRINGS_PROPS_PATH = os.path.join(_BROWSER_DIR, "appstrings.properties") |
| 48 _STRINGS_XML_PATH = "strings.xml" | 47 _STRINGS_XML_FILE = "strings.xml" |
| 49 | 48 |
| 50 _DEFAULT_LOCALE = "en-US" | 49 _DEFAULT_LOCALE = "en-US" |
| 51 _DEF_ENGINES = "visibleDefaultEngines" | 50 _DEF_ENGINES = "visibleDefaultEngines" |
| 52 | 51 |
| 53 # Add Ecosia as secondary search engine. | 52 # Add Ecosia as secondary search engine. |
| 54 # See https://issues.adblockplus.org/ticket/5518 | 53 # See https://issues.adblockplus.org/ticket/5518 |
| 55 _ECOSIA_ID = "ecosia" | 54 _ECOSIA_ID = "ecosia" |
| 56 _ECOSIA_PATH = os.path.join(_GENERAL_SEARCHPLUGINS_PATH, "ecosia.xml") | 55 _ECOSIA_PATH = os.path.join(_GENERAL_SEARCHPLUGINS_PATH, "ecosia.xml") |
| 57 | 56 |
| 58 _SEARCH_ENGINE_ORDER_DEFAULT = [ | 57 _SEARCH_ENGINE_ORDER_DEFAULT = [ |
| 59 "duckduckgo", | 58 "ddg", |
|
diegocarloslima
2019/03/29 12:51:01
The id changed from duckduckgo to ddg
| |
| 60 "yahoo", | 59 "yahoo", |
| 61 "google", | 60 "google", |
| 62 "wikipedia", | 61 "wikipedia", |
| 63 "amazondotcom"] | 62 "amazon"] |
|
diegocarloslima
2019/03/29 12:51:01
Took the opportunity to also fix this, otherwise a
| |
| 64 | 63 |
| 65 _SEARCH_ENGINE_ORDER_ECOSIA = [ | 64 _SEARCH_ENGINE_ORDER_ECOSIA = [ |
| 66 "duckduckgo", | 65 "ddg", |
| 67 "yahoo", | 66 "yahoo", |
| 68 "google", | 67 "google", |
| 69 _ECOSIA_ID, | 68 _ECOSIA_ID, |
| 70 "wikipedia", | 69 "wikipedia", |
| 71 "amazon"] | 70 "amazon"] |
| 72 | 71 |
| 73 _SEARCH_ENGINE_ORDER = { | 72 _SEARCH_ENGINE_ORDER = { |
| 74 "de": _SEARCH_ENGINE_ORDER_ECOSIA, | 73 "de": _SEARCH_ENGINE_ORDER_ECOSIA, |
| 75 "en-GB": _SEARCH_ENGINE_ORDER_ECOSIA, | 74 "en-GB": _SEARCH_ENGINE_ORDER_ECOSIA, |
| 76 "en-US": _SEARCH_ENGINE_ORDER_ECOSIA, | 75 "en-US": _SEARCH_ENGINE_ORDER_ECOSIA, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 return None | 149 return None |
| 151 | 150 |
| 152 | 151 |
| 153 def _write_lines(filename, lines): | 152 def _write_lines(filename, lines): |
| 154 """Writes lines into file appending \\n""" | 153 """Writes lines into file appending \\n""" |
| 155 with open(filename, "w") as fd: | 154 with open(filename, "w") as fd: |
| 156 for l in lines: | 155 for l in lines: |
| 157 fd.write("%s\n" % l) | 156 fd.write("%s\n" % l) |
| 158 | 157 |
| 159 | 158 |
| 160 def _transform_locale(data, locale, project_dir, locale_path, logger): | 159 def _transform_region_props(locale, locale_path, engines_ordered, logger): |
| 161 logger.info("Processing locale '%s'..." % locale) | |
| 162 | |
| 163 # Check for region.properties existence | 160 # Check for region.properties existence |
| 164 region_file_path = os.path.join(locale_path, _REGION_PROPS_PATH) | 161 region_file_path = os.path.join(locale_path, _REGION_PROPS_PATH) |
| 165 _check_path_exists(region_file_path, logger) | 162 _check_path_exists(region_file_path, logger) |
| 166 | 163 |
| 167 # Check for appstrings.properties existence | 164 # Read region.properties and remove browser.search.* lines |
| 168 appstrings_file_path = os.path.join(locale_path, _APPSTRINGS_PROPS_PATH) | 165 lines = [] |
| 169 _check_path_exists(appstrings_file_path, logger) | 166 with open(region_file_path, "r") as fd: |
| 170 | 167 for line in fd: |
| 171 ecosia_dst = os.path.join(locale_path, | 168 line = line.rstrip("\r\n") |
| 172 _LOCALE_SEARCHPLUGINS_PATH, "ecosia.xml") | 169 if not _SEARCH_PROPS_RE.match(line.strip()): |
| 173 | 170 lines.append(line) |
| 171 | |
| 172 # Append default search engine name | |
| 173 lines.append("browser.search.defaultenginename=%s" % engines_ordered[0]) | |
| 174 | |
| 175 # Append search engine order | |
| 176 for i in range(0, len(engines_ordered)): | |
| 177 lines.append("browser.search.order.%d=%s" % (i + 1, | |
| 178 engines_ordered[i])) | |
| 179 # Write back region.properties | |
| 180 _write_lines(region_file_path, lines) | |
| 181 logger.info("Resulting ordered search engines for %s: %s" % | |
| 182 (locale, ", ".join(engines_ordered))) | |
| 183 | |
| 184 | |
| 185 def _generate_browser_search(project_dir, res_path, locale, locale_path, | |
| 186 logger): | |
| 187 | |
|
anton
2019/04/05 12:42:24
unrequired line?
| |
| 188 raw_dir = "raw" if locale == _DEFAULT_LOCALE else ( | |
| 189 "raw-%s" % locale.replace("-", "-r")) | |
| 190 | |
| 191 browser_path = os.path.join(locale_path, _BROWSER_DIR) | |
| 192 browsersearch_file_path = os.path.join(res_path, raw_dir, | |
| 193 "browsersearch.json") | |
| 194 | |
| 195 sys.path.append(os.path.join(project_dir, _MOZBUILD_PATH)) | |
| 196 import mozbuild.action.generate_browsersearch as generate_browsersearch | |
| 197 | |
| 198 # Call generate_browsersearch.py script to regenerate | |
| 199 # res/raw-LOCALE/browsersearch.json with the updated search engines | |
| 200 generate_browsersearch.main(["--verbose", "--srcdir", browser_path, | |
| 201 browsersearch_file_path]) | |
| 202 | |
| 203 logger.info("Generated browsersearch.json for %s" % locale) | |
| 204 | |
| 205 | |
| 206 def _transform_search_locale(project_dir, data, locale, locale_path, logger): | |
| 174 # Get whitelist and build regex | 207 # Get whitelist and build regex |
| 175 whitelist = _SEARCH_ENGINE_ORDER.get(locale, | 208 whitelist = _SEARCH_ENGINE_ORDER.get(locale, _SEARCH_ENGINE_ORDER_DEFAULT) |
| 176 _SEARCH_ENGINE_ORDER_DEFAULT) | |
| 177 white_re = re.compile("^(%s).*$" % "|".join(whitelist)) | 209 white_re = re.compile("^(%s).*$" % "|".join(whitelist)) |
| 178 | 210 |
| 179 if _ECOSIA_ID in whitelist and not os.path.exists(ecosia_dst): | 211 all_engine_ids = data['locales'][locale]['default'][_DEF_ENGINES] |
| 212 engine_ids = [] | |
| 213 for item in all_engine_ids: | |
| 214 if white_re.match(item): | |
| 215 engine_ids.append(item) | |
| 216 | |
| 217 # We include Ecosia for some locales if its not there already | |
| 218 if _ECOSIA_ID in whitelist and _ECOSIA_ID not in all_engine_ids: | |
| 219 ecosia_dst = os.path.join(locale_path, _LOCALE_SEARCHPLUGINS_PATH, | |
| 220 "ecosia.xml") | |
| 221 | |
| 180 shutil.copyfile(os.path.join(project_dir, _ECOSIA_PATH), ecosia_dst) | 222 shutil.copyfile(os.path.join(project_dir, _ECOSIA_PATH), ecosia_dst) |
| 181 | |
| 182 all_engine_ids = [] | |
| 183 engine_ids = [] | |
| 184 removed_engine_ids = [] | |
| 185 | |
| 186 for item in data['locales'][locale]['default'][_DEF_ENGINES]: | |
| 187 all_engine_ids.append(item) | |
| 188 if len(item) > 0: | |
| 189 if white_re.match(item): | |
| 190 engine_ids.append(item) | |
| 191 else: | |
| 192 removed_engine_ids.append(item) | |
| 193 | |
| 194 if _ECOSIA_ID in whitelist and _ECOSIA_ID not in all_engine_ids: | |
| 195 all_engine_ids.append(_ECOSIA_ID) | 223 all_engine_ids.append(_ECOSIA_ID) |
| 196 engine_ids.append(_ECOSIA_ID) | 224 engine_ids.append(_ECOSIA_ID) |
| 197 | 225 |
| 198 # Make sure we still have search engines left | 226 # 'Parse' XML to get matching ShortName for all engine IDs |
| 199 if len(engine_ids) == 0: | |
| 200 logger.fatal("No search engines left over for '%s'" % locale) | |
| 201 | |
| 202 data['locales'][locale]['default'][_DEF_ENGINES] = all_engine_ids | |
| 203 | |
| 204 # 'Parse' XML to get matching 'ShortName' for all engine IDs | |
| 205 engine_names = {} | 227 engine_names = {} |
| 206 search_plugins_path = os.path.join(project_dir, | 228 plugins_path = os.path.join(project_dir, _GENERAL_SEARCHPLUGINS_PATH) |
| 207 _GENERAL_SEARCHPLUGINS_PATH) | 229 for eid in engine_ids: |
| 208 for eid in engine_ids[:]: | 230 plugin_path = os.path.join(plugins_path, "%s.xml" % eid) |
| 209 xml_file_path = os.path.join(search_plugins_path, "%s.xml" % eid) | 231 if not os.path.exists(plugin_path): |
| 210 if not os.path.exists(xml_file_path): | 232 logger.error("Missing file for plugin %s. Searched in path %s" % |
| 211 logger.info("Missing xml file for plugin %s. Searched in path %s" % | 233 (eid, plugin_path)) |
| 212 (eid, xml_file_path)) | |
| 213 engine_ids.remove(eid) | 234 engine_ids.remove(eid) |
| 214 continue | 235 continue |
| 236 | |
| 215 short_name = None | 237 short_name = None |
| 216 with open(xml_file_path, "r") as fd: | 238 with open(plugin_path, "r") as fd: |
| 217 for line in fd: | 239 for line in fd: |
| 218 line = line.strip() | 240 line = line.strip() |
| 219 match = _SHORTNAME_RE.match(line) | 241 match = _SHORTNAME_RE.match(line) |
| 220 if match: | 242 if match: |
| 221 short_name = match.group(1).strip() | 243 short_name = match.group(1).strip() |
| 222 | 244 |
| 223 if not short_name: | 245 if not short_name: |
| 224 logger.fatal("No ShortName defined for '%s' in '%s" % | 246 logger.fatal("No ShortName defined for '%s' in '%s" % |
| 225 (eid, locale)) | 247 (eid, locale)) |
| 248 | |
| 226 engine_names[eid] = short_name | 249 engine_names[eid] = short_name |
| 227 | 250 |
| 228 logger.info("Removed search engine IDs: %s" % | |
| 229 ", ".join(removed_engine_ids)) | |
| 230 logger.info("Remaining search engine IDs: %s" % ", ".join(engine_ids)) | |
| 231 | |
| 232 # Create search engine order with real engine names | 251 # Create search engine order with real engine names |
| 233 engine_order = [] | 252 engines_ordered = [] |
| 234 for eid in whitelist: | 253 for eid in whitelist: |
| 235 sn = _get_shortname_from_id(eid, engine_ids, engine_names) | 254 shortname = _get_shortname_from_id(eid, engine_ids, engine_names) |
| 236 if sn: | 255 if shortname: |
| 237 engine_order.append(sn) | 256 engines_ordered.append(shortname) |
| 238 | 257 |
| 239 logger.info("Resulting search engine ordered list: %s" % | 258 # Make sure we still have search engines left |
| 240 (", ".join(engine_order))) | 259 if len(engines_ordered) == 0: |
| 241 | 260 logger.fatal("No search engines left over for '%s'" % locale) |
| 242 # Read region.properties and remove browser.search.* lines | 261 |
| 243 props = [] | 262 _transform_region_props(locale, locale_path, engines_ordered, logger) |
| 244 with open(region_file_path, "r") as fd: | 263 |
| 245 for line in fd: | 264 |
| 246 line = line.rstrip("\r\n") | 265 def _transform_search_engines(project_dir, chrome_path, res_path, locales, |
| 247 if not _SEARCH_PROPS_RE.match(line.strip()): | 266 logger): |
| 248 props.append(line) | 267 |
|
anton
2019/04/05 12:42:24
unrequired line?
| |
| 249 | 268 list_json_path = os.path.join(project_dir, _LIST_JSON_PATH) |
| 250 # Append default search engine name | 269 _check_path_exists(list_json_path, logger) |
| 251 props.append("browser.search.defaultenginename=%s" % engine_order[0]) | 270 |
| 252 | 271 # Open the Mozilla list of search engines, put it into a buffer and close |
| 253 # Append search engine order | 272 # the JSON file after reading |
| 254 for i in range(0, len(engine_order)): | 273 with open(list_json_path, 'r') as json_file: |
| 255 props.append("browser.search.order.%d=%s" % (i + 1, engine_order[i])) | 274 data = json.load(json_file) |
| 256 | 275 |
| 257 # Write back region.properties | 276 # Set default search engine order |
| 258 _write_lines(region_file_path, props) | 277 data['default'][_DEF_ENGINES] = _SEARCH_ENGINE_ORDER_DEFAULT |
| 278 | |
| 279 for locale in locales: | |
| 280 locale_path = os.path.join(chrome_path, locale, "locale", locale) | |
| 281 if os.path.exists(locale_path): | |
| 282 | |
| 283 # Mozilla default list does not contain locale bn-BD, | |
| 284 # so we create it and use the values from locale bn-IN | |
| 285 if locale == 'bn-BD': | |
| 286 engines = data['locales']['bn-IN']['default'][_DEF_ENGINES] | |
| 287 data['locales'].update({locale: {'default': | |
| 288 {_DEF_ENGINES: engines}}}) | |
| 289 | |
| 290 # Mozilla default list does not contain locale wo, so we use | |
| 291 # the default order. In case they will not support any other | |
| 292 # locales in the future, we want the build to fail, to decide | |
| 293 # which order to use | |
| 294 elif locale == 'wo': | |
| 295 engines = _SEARCH_ENGINE_ORDER_DEFAULT | |
| 296 data['locales'].update({locale: {'default': | |
| 297 {_DEF_ENGINES: engines}}}) | |
| 298 | |
| 299 _transform_search_locale(project_dir, data, locale, | |
| 300 locale_path, logger) | |
| 301 | |
| 302 _generate_browser_search(project_dir, res_path, locale, | |
| 303 locale_path, logger) | |
| 304 else: | |
| 305 logger.error("Missing folder for locale '%s' in path: %s" % | |
| 306 (locale, locale_path)) | |
| 307 | |
| 308 # Save modified list.json in generated folder, so we dont change the | |
| 309 # original file | |
| 310 generated_list_json = os.path.join(project_dir, | |
|
diegocarloslima
2019/03/29 12:51:01
Saving the modified list.json into the generated f
| |
| 311 _GENERATED_LIST_JSON_PATH) | |
| 312 | |
| 313 with open(generated_list_json, 'w') as outfile: | |
| 314 json.dump(data, outfile, indent=4, sort_keys=True) | |
| 315 | |
| 316 logger.info("Generated list.json in %s" % generated_list_json) | |
| 317 | |
| 318 | |
| 319 def _generate_search_json(project_dir, locale, locale_path, logger): | |
| 320 script_path = os.path.join(project_dir, _MOZBUILD_PATH, | |
| 321 "mozbuild", "action", "generate_searchjson.py") | |
| 322 | |
| 323 # We read from the list.json in generated folder, that contains our own | |
| 324 # modifications | |
| 325 list_json_src = os.path.join(project_dir, _GENERATED_LIST_JSON_PATH) | |
| 326 list_json_dst = os.path.join(locale_path, _BROWSER_DIR, "searchplugins", | |
| 327 "list.json") | |
| 328 | |
| 329 import subprocess as sub | |
| 330 # Call generate_searchjson.py script | |
| 331 sub.check_call(['python', script_path, list_json_src, locale, | |
| 332 list_json_dst]) | |
| 333 | |
| 334 logger.info("Generated search list.json for %s" % locale) | |
| 335 | |
| 336 | |
| 337 def _transform_appstrings(locale, locale_path, logger): | |
| 338 logger.info("Processing appstrings for %s..." % locale) | |
| 339 # Check for appstrings.properties existence | |
| 340 appstrings_file_path = os.path.join(locale_path, _APPSTRINGS_PROPS_PATH) | |
| 341 _check_path_exists(appstrings_file_path, logger) | |
| 259 | 342 |
| 260 # Replaces ocurrences of 'Firefox' by 'Adblock Browser' in | 343 # Replaces ocurrences of 'Firefox' by 'Adblock Browser' in |
| 261 # 'appstrings.properties' | 344 # appstrings.properties |
| 262 lines = [] | 345 lines = [] |
| 263 replacement_count = 0 | 346 replacement_count = 0 |
| 264 | 347 |
| 265 with open(appstrings_file_path, "r") as fd: | 348 with open(appstrings_file_path, "r") as fd: |
| 266 for line in fd: | 349 for line in fd: |
| 267 line = line.rstrip("\r\n") | 350 line = line.rstrip("\r\n") |
| 268 replacement = _replace_in_value(_PROPERTY_FORMAT_RE, line, | 351 replacement = _replace_in_value(_PROPERTY_FORMAT_RE, line, |
| 269 _FIREFOX_REPLACE_STR, | 352 _FIREFOX_REPLACE_STR, |
| 270 _ABB_REPLACEMENT_STR) | 353 _ABB_REPLACEMENT_STR) |
| 271 if replacement: | 354 if replacement: |
| 272 line = replacement | 355 line = replacement |
| 273 replacement_count += 1 | 356 replacement_count += 1 |
| 274 lines.append(line) | 357 lines.append(line) |
| 275 | 358 |
| 276 # Apply changes to appstrings.properties | 359 # Apply changes to appstrings.properties |
| 277 _write_lines(appstrings_file_path, lines) | 360 _write_lines(appstrings_file_path, lines) |
| 278 logger.info("Replaced %d ocurrences of %s in 'appstrings.properties'" % | 361 logger.info("Replaced %d ocurrences of %s in 'appstrings.properties'" % |
| 279 (replacement_count, _FIREFOX_REPLACE_STR)) | 362 (replacement_count, _FIREFOX_REPLACE_STR)) |
| 280 | 363 |
| 281 | 364 |
| 282 def _generate_browser_search(locale, locale_path, res_path, project_dir): | 365 def _transform_values_locale(locale, locale_path, logger): |
| 283 raw_dir = "raw" if locale == _DEFAULT_LOCALE else ( | |
| 284 "raw-%s" % locale.replace("-", "-r")) | |
| 285 | |
| 286 browser_path = os.path.join(locale_path, _BROWSER_DIR) | |
| 287 browsersearch_file_path = os.path.join(res_path, raw_dir, | |
| 288 "browsersearch.json") | |
| 289 | |
| 290 sys.path.append(os.path.join(project_dir, _MOZBUILD_PATH)) | |
| 291 import mozbuild.action.generate_browsersearch as generate_browsersearch | |
| 292 | |
| 293 # Call generate_browsersearch.py script to regenerate | |
| 294 # res/raw-LOCALE/browsersearch.json with the updated search engines | |
| 295 generate_browsersearch.main(["--verbose", "--srcdir", browser_path, | |
| 296 browsersearch_file_path]) | |
| 297 | |
| 298 | |
| 299 def _generate_search_json(locale, locale_path, project_dir): | |
| 300 script_path = os.path.join(project_dir, "python", "mozbuild", | |
| 301 "mozbuild", "action", "generate_searchjson.py") | |
| 302 list_json_path = os.path.join(project_dir, _LISTJSON_PATH) | |
| 303 searchplugins_path = os.path.join(locale_path, _BROWSER_DIR, | |
| 304 "searchplugins", "list.json") | |
| 305 | |
| 306 import subprocess as s | |
| 307 # Call generate_searchjson.py script | |
| 308 s.check_call(['python', script_path, list_json_path, | |
| 309 locale, searchplugins_path]) | |
| 310 | |
| 311 | |
| 312 def _transform_values_locale(locale, path, logger): | |
| 313 logger.info("Processing values-%s..." % locale) | 366 logger.info("Processing values-%s..." % locale) |
| 314 | |
| 315 # Check for strings.xml existence | 367 # Check for strings.xml existence |
| 316 strings_file_path = os.path.join(path, _STRINGS_XML_PATH) | 368 strings_file_path = os.path.join(locale_path, _STRINGS_XML_FILE) |
| 317 _check_path_exists(strings_file_path, logger) | 369 _check_path_exists(strings_file_path, logger) |
| 318 | 370 |
| 319 # Replaces ocurrences of 'Firefox' by 'Adblock Browser' in 'strings.xml' | 371 # Replaces ocurrences of 'Firefox' by 'Adblock Browser' in 'strings.xml' |
| 320 lines = [] | 372 lines = [] |
| 321 replacement_count = 0 | 373 replacement_count = 0 |
| 322 | 374 |
| 323 with open(strings_file_path, "r") as fd: | 375 with open(strings_file_path, "r") as fd: |
| 324 for line in fd: | 376 for line in fd: |
| 325 line = line.rstrip("\r\n") | 377 line = line.rstrip("\r\n") |
| 326 replacement = _replace_in_value(_ENTITY_FORMAT_RE, line, | 378 replacement = _replace_in_value(_ENTITY_FORMAT_RE, line, |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 357 exit(1) | 409 exit(1) |
| 358 | 410 |
| 359 | 411 |
| 360 def transform_locales(project_dir, obj_dir, logger=MinimalLogger()): | 412 def transform_locales(project_dir, obj_dir, logger=MinimalLogger()): |
| 361 chrome_path = os.path.join(obj_dir, _CHROME_PATH) | 413 chrome_path = os.path.join(obj_dir, _CHROME_PATH) |
| 362 _check_path_exists(chrome_path, logger) | 414 _check_path_exists(chrome_path, logger) |
| 363 | 415 |
| 364 res_path = os.path.join(obj_dir, _RES_PATH) | 416 res_path = os.path.join(obj_dir, _RES_PATH) |
| 365 _check_path_exists(res_path, logger) | 417 _check_path_exists(res_path, logger) |
| 366 | 418 |
| 367 list_json_path = os.path.join(project_dir, _LISTJSON_PATH) | |
| 368 _check_path_exists(list_json_path, logger) | |
| 369 | |
| 370 locales = _get_locales_from_path(chrome_path, _LOCALE_RE) | 419 locales = _get_locales_from_path(chrome_path, _LOCALE_RE) |
| 371 values_locales = _get_locales_from_path(res_path, _VALUES_LOCALE_RE) | 420 values_locales = _get_locales_from_path(res_path, _VALUES_LOCALE_RE) |
| 372 | 421 |
| 373 locales_found_msg = "Found %d locales in %s" | 422 locales_found_msg = "Found %d locales in %s" |
| 374 logger.info(locales_found_msg % (len(locales), chrome_path)) | 423 logger.info(locales_found_msg % (len(locales), chrome_path)) |
| 375 logger.info(locales_found_msg % (len(values_locales), res_path)) | 424 logger.info(locales_found_msg % (len(values_locales), res_path)) |
| 376 | 425 |
| 377 # open the Mozilla list of search engines, put it into a buffer and | 426 _transform_search_engines(project_dir, chrome_path, res_path, locales, |
| 378 # close the JSON file after reading | 427 logger) |
| 379 with open(list_json_path, 'r') as json_file: | |
| 380 data = json.load(json_file) | |
| 381 | 428 |
| 382 # set default search engine order | 429 for locale in locales: |
| 383 data['default'][_DEF_ENGINES] = _SEARCH_ENGINE_ORDER_DEFAULT | 430 locale_path = os.path.join(chrome_path, locale, "locale", locale) |
| 431 _generate_search_json(project_dir, locale, locale_path, logger) | |
| 432 _transform_appstrings(locale, locale_path, logger) | |
| 384 | 433 |
| 385 for locale in locales: | 434 for locale in values_locales: |
| 386 locale_path = os.path.join(chrome_path, locale, "locale", locale) | 435 locale_path = os.path.join(res_path, "values-" + locale) |
| 387 if os.path.exists(locale_path): | 436 _transform_values_locale(locale, locale_path, logger) |
| 388 | |
| 389 # Mozilla default list does not contain locale bn-BD, | |
| 390 # so we create it and use the values from locale bn-IN | |
| 391 if locale == 'bn-BD': | |
| 392 data['locales'].update({locale: {'default': | |
| 393 {_DEF_ENGINES: | |
| 394 data['locales']['bn-IN']['default'][_DEF_ENGINES]}}}) | |
| 395 # Mozilla default list does not contain locale wo, so we use | |
| 396 # the default order. In case they will not support any other | |
| 397 # locales in the future, we want the build to fail, to decide | |
| 398 # which order to use | |
| 399 elif locale == 'wo': | |
| 400 data['locales'].update({locale: {'default': | |
| 401 {_DEF_ENGINES: | |
| 402 _SEARCH_ENGINE_ORDER_DEFAULT}}}) | |
| 403 | |
| 404 _transform_locale(data, locale, project_dir, locale_path, | |
| 405 logger) | |
| 406 _generate_browser_search(locale, locale_path, res_path, | |
| 407 project_dir) | |
| 408 else: | |
| 409 logger.error("Missing folder for locale '%s' in path: %s" % | |
| 410 (locale, locale_path)) | |
| 411 | |
| 412 # Save changes to list.json | |
| 413 with open(list_json_path, 'w') as outfile: | |
| 414 json.dump(data, outfile, indent=4, sort_keys=True) | |
| 415 | |
| 416 # Generate search.json for each locale | |
| 417 for locale in locales: | |
| 418 locale_path = os.path.join(chrome_path, locale, "locale", locale) | |
| 419 _generate_search_json(locale, locale_path, project_dir) | |
| 420 | |
| 421 for locale in values_locales: | |
| 422 locale_path = os.path.join(res_path, "values-" + locale) | |
| 423 _transform_values_locale(locale, locale_path, logger) | |
| OLD | NEW |