| OLD | NEW |
| 1 # This file is part of Adblock Plus | 1 # This file is part of Adblock Plus |
| 2 # Copyright (C) 2006-2015 Eyeo GmbH | 2 # Copyright (C) 2006-2015 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 |
| 11 # GNU General Public License for more details. | 11 # GNU General Public License for more details. |
| 12 # | 12 # |
| 13 # You should have received a copy of the GNU General Public License | 13 # You should have received a copy of the GNU General Public License |
| 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 15 | 15 |
| 16 import os | 16 import os |
| 17 import re | 17 import re |
| 18 import sys |
| 18 | 19 |
| 19 _LOCALE_RE = re.compile("^([a-z]{2,3}(?:-[A-Z]{2})?)$") | 20 _LOCALE_RE = re.compile("^([a-z]{2,3}(?:-[A-Z]{2})?)$") |
| 20 _VALUES_LOCALE_RE = re.compile("^values-([a-z]{2,3}(?:-r[A-Z]{2})?)$") | 21 _VALUES_LOCALE_RE = re.compile("^values-([a-z]{2,3}(?:-r[A-Z]{2})?)$") |
| 21 | 22 |
| 22 _SEARCH_PROPS_RE = re.compile("^browser\.search\." | 23 _SEARCH_PROPS_RE = re.compile("^browser\.search\." |
| 23 "(defaultenginename|order\.).*$") | 24 "(defaultenginename|order\.).*$") |
| 24 _SHORTNAME_RE = re.compile("^<ShortName>(.*)</ShortName>$") | 25 _SHORTNAME_RE = re.compile("^<ShortName>(.*)</ShortName>$") |
| 25 | 26 |
| 26 _PROPERTY_FORMAT_RE = re.compile("^(([^=]*)=)(.*)$") | 27 _PROPERTY_FORMAT_RE = re.compile("^(([^=]*)=)(.*)$") |
| 27 _ENTITY_FORMAT_RE = re.compile("^(\s*<!ENTITY\s*([^\"\s]*)\s*\")(.*)(\">)$") | 28 _ENTITY_FORMAT_RE = re.compile("^(\s*<!ENTITY\s*([^\"\s]*)\s*\")(.*)(\">)$") |
| 28 _STRING_FORMAT_RE = re.compile( | 29 _STRING_FORMAT_RE = re.compile( |
| 29 "^(\s*<string name=\"([^\"]*)\">)(.*)(</string>)$") | 30 "^(\s*<string name=\"([^\"]*)\">)(.*)(</string>)$") |
| 30 | 31 |
| 32 _MOZBUILD_PATH = os.path.join("python", "mozbuild") |
| 33 |
| 31 _CHROME_PATH = os.path.join("dist", "bin", "chrome") | 34 _CHROME_PATH = os.path.join("dist", "bin", "chrome") |
| 32 _RES_PATH = os.path.join("mobile", "android", "base", "res") | 35 _RES_PATH = os.path.join("mobile", "android", "base", "res") |
| 33 | 36 |
| 34 _SEARCHPLUGINS_PATH = os.path.join("browser", "searchplugins") | 37 _BROWSER_DIR = "browser" |
| 38 _SEARCHPLUGINS_PATH = os.path.join(_BROWSER_DIR, "searchplugins") |
| 35 _LIST_TXT_PATH = os.path.join(_SEARCHPLUGINS_PATH, "list.txt") | 39 _LIST_TXT_PATH = os.path.join(_SEARCHPLUGINS_PATH, "list.txt") |
| 36 _REGION_PROPS_PATH = os.path.join("browser", "region.properties") | 40 _REGION_PROPS_PATH = os.path.join(_BROWSER_DIR, "region.properties") |
| 37 | 41 |
| 38 _APPSTRINGS_PROPS_PATH = os.path.join("browser", "appstrings.properties") | 42 _APPSTRINGS_PROPS_PATH = os.path.join(_BROWSER_DIR, "appstrings.properties") |
| 39 _STRINGS_XML_PATH = "strings.xml" | 43 _STRINGS_XML_PATH = "strings.xml" |
| 40 | 44 |
| 41 _DEFAULT_LOCALE = "en-US" | 45 _DEFAULT_LOCALE = "en-US" |
| 42 | 46 |
| 43 _SEARCH_ENGINE_ORDER = { | 47 _SEARCH_ENGINE_ORDER = { |
| 44 "en-US": ["duckduckgo", | 48 "en-US": ["duckduckgo", |
| 45 "yahoo", | 49 "yahoo", |
| 46 "google", | 50 "google", |
| 47 "wikipedia", | 51 "wikipedia", |
| 48 "amazon" | 52 "amazon" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 line = replacement | 236 line = replacement |
| 233 replacement_count += 1 | 237 replacement_count += 1 |
| 234 lines.append(line) | 238 lines.append(line) |
| 235 | 239 |
| 236 # Apply changes to appstrings.properties | 240 # Apply changes to appstrings.properties |
| 237 _write_lines(appstrings_file_path, lines) | 241 _write_lines(appstrings_file_path, lines) |
| 238 logger.info("Replaced %d ocurrences of %s in 'appstrings.properties'" % | 242 logger.info("Replaced %d ocurrences of %s in 'appstrings.properties'" % |
| 239 (replacement_count, _FIREFOX_REPLACE_STR)) | 243 (replacement_count, _FIREFOX_REPLACE_STR)) |
| 240 | 244 |
| 241 | 245 |
| 246 def _generate_browser_search(locale, locale_path, res_path, build_dir): |
| 247 raw_dir = "raw" if locale == _DEFAULT_LOCALE else ( |
| 248 "raw-%s" % locale.replace("-", "-r")) |
| 249 |
| 250 browser_path = os.path.join(locale_path, _BROWSER_DIR) |
| 251 browsersearch_file_path = os.path.join(res_path, raw_dir, |
| 252 "browsersearch.json") |
| 253 |
| 254 sys.path.append(os.path.join(build_dir, _MOZBUILD_PATH)) |
| 255 import mozbuild.action.generate_browsersearch as generate_browsersearch |
| 256 |
| 257 # Call generate_browsersearch.py script to regenerate |
| 258 # res/raw-LOCALE/browsersearch.json with the updated search engines |
| 259 generate_browsersearch.main(["--verbose", "--srcdir", browser_path, |
| 260 browsersearch_file_path]) |
| 261 |
| 262 |
| 242 def _transform_values_locale(locale, path, logger): | 263 def _transform_values_locale(locale, path, logger): |
| 243 logger.info("Processing values-%s..." % locale) | 264 logger.info("Processing values-%s..." % locale) |
| 244 | 265 |
| 245 # Check for strings.xml existence | 266 # Check for strings.xml existence |
| 246 strings_file_path = os.path.join(path, _STRINGS_XML_PATH) | 267 strings_file_path = os.path.join(path, _STRINGS_XML_PATH) |
| 247 _check_path_exists(strings_file_path, logger) | 268 _check_path_exists(strings_file_path, logger) |
| 248 | 269 |
| 249 # Replaces ocurrences of 'Firefox' by 'Adblock Browser' in 'strings.xml' | 270 # Replaces ocurrences of 'Firefox' by 'Adblock Browser' in 'strings.xml' |
| 250 lines = [] | 271 lines = [] |
| 251 replacement_count = 0 | 272 replacement_count = 0 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 280 print "INFO: %s" % s | 301 print "INFO: %s" % s |
| 281 | 302 |
| 282 def error(self, s): | 303 def error(self, s): |
| 283 print "ERROR: %s" % s | 304 print "ERROR: %s" % s |
| 284 | 305 |
| 285 def fatal(self, s): | 306 def fatal(self, s): |
| 286 print "FATAL: %s" % s | 307 print "FATAL: %s" % s |
| 287 exit(1) | 308 exit(1) |
| 288 | 309 |
| 289 | 310 |
| 290 def transform_locales(obj_dir, logger=MinimalLogger()): | 311 def transform_locales(build_dir, obj_dir, logger=MinimalLogger()): |
| 291 chrome_path = os.path.join(obj_dir, _CHROME_PATH) | 312 chrome_path = os.path.join(obj_dir, _CHROME_PATH) |
| 292 _check_path_exists(chrome_path, logger) | 313 _check_path_exists(chrome_path, logger) |
| 293 | 314 |
| 294 res_path = os.path.join(obj_dir, _RES_PATH) | 315 res_path = os.path.join(obj_dir, _RES_PATH) |
| 295 _check_path_exists(res_path, logger) | 316 _check_path_exists(res_path, logger) |
| 296 | 317 |
| 297 locales = _get_locales_from_path(chrome_path, _LOCALE_RE) | 318 locales = _get_locales_from_path(chrome_path, _LOCALE_RE) |
| 298 values_locales = _get_locales_from_path(res_path, _VALUES_LOCALE_RE) | 319 values_locales = _get_locales_from_path(res_path, _VALUES_LOCALE_RE) |
| 299 | 320 |
| 300 locales_found_msg = "Found %d locales in %s" | 321 locales_found_msg = "Found %d locales in %s" |
| 301 logger.info(locales_found_msg % (len(locales), chrome_path)) | 322 logger.info(locales_found_msg % (len(locales), chrome_path)) |
| 302 logger.info(locales_found_msg % (len(values_locales), res_path)) | 323 logger.info(locales_found_msg % (len(values_locales), res_path)) |
| 303 | 324 |
| 304 for locale in locales: | 325 for locale in locales: |
| 305 locale_path = os.path.join(chrome_path, locale, "locale", locale) | 326 locale_path = os.path.join(chrome_path, locale, "locale", locale) |
| 306 if os.path.exists(locale_path): | 327 if os.path.exists(locale_path): |
| 307 _transform_locale(locale, locale_path, logger) | 328 _transform_locale(locale, locale_path, logger) |
| 329 _generate_browser_search(locale, locale_path, res_path, build_dir) |
| 308 else: | 330 else: |
| 309 logger.error("Missing folder for locale '%s' in path: %s" % | 331 logger.error("Missing folder for locale '%s' in path: %s" % |
| 310 (locale, locale_path)) | 332 (locale, locale_path)) |
| 311 | 333 |
| 312 for locale in values_locales: | 334 for locale in values_locales: |
| 313 locale_path = os.path.join(res_path, "values-" + locale) | 335 locale_path = os.path.join(res_path, "values-" + locale) |
| 314 _transform_values_locale(locale, locale_path, logger) | 336 _transform_values_locale(locale, locale_path, logger) |
| OLD | NEW |