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

Delta Between Two Patch Sets: mozharness/abb/transform_locales.py

Issue 29633713: Issue 6077 - Create script to modify the list of search engines dynamically (Closed)
Left Patch Set: Created Dec. 8, 2017, 3:37 p.m.
Right Patch Set: Created Jan. 10, 2018, 4:14 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
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 json 16 import json
17 import os 17 import os
18 import re 18 import re
19 import shutil
19 import sys 20 import sys
20 21
21 _LOCALE_RE = re.compile("^([a-z]{2,3}(?:-[A-Z]{2})?)$") 22 _LOCALE_RE = re.compile("^([a-z]{2,3}(?:-[A-Z]{2})?)$")
22 _VALUES_LOCALE_RE = re.compile("^values-([a-z]{2,3}(?:-r[A-Z]{2})?)$") 23 _VALUES_LOCALE_RE = re.compile("^values-([a-z]{2,3}(?:-r[A-Z]{2})?)$")
23 24
24 _SEARCH_PROPS_RE = re.compile("^browser\.search\." 25 _SEARCH_PROPS_RE = re.compile("^browser\.search\."
25 "(defaultenginename|order\.).*$") 26 "(defaultenginename|order\.).*$")
26 _SHORTNAME_RE = re.compile("^<ShortName>(.*)</ShortName>$") 27 _SHORTNAME_RE = re.compile("^<ShortName>(.*)</ShortName>$")
27 28
28 _PROPERTY_FORMAT_RE = re.compile("^(([^=]*)=)(.*)$") 29 _PROPERTY_FORMAT_RE = re.compile("^(([^=]*)=)(.*)$")
29 _ENTITY_FORMAT_RE = re.compile("^(\s*<!ENTITY\s*([^\"\s]*)\s*\")(.*)(\">)$") 30 _ENTITY_FORMAT_RE = re.compile("^(\s*<!ENTITY\s*([^\"\s]*)\s*\")(.*)(\">)$")
30 _STRING_FORMAT_RE = re.compile( 31 _STRING_FORMAT_RE = re.compile(
31 "^(\s*<string name=\"([^\"]*)\">)(.*)(</string>)$") 32 "^(\s*<string name=\"([^\"]*)\">)(.*)(</string>)$")
32 33
33 _MOZBUILD_PATH = os.path.join("python", "mozbuild") 34 _MOZBUILD_PATH = os.path.join("python", "mozbuild")
34 35
35 _CHROME_PATH = os.path.join("dist", "bin", "chrome") 36 _CHROME_PATH = os.path.join("dist", "bin", "chrome")
36 _RES_PATH = os.path.join("mobile", "android", "base", "res") 37 _RES_PATH = os.path.join("mobile", "android", "base", "res")
37 _I10N_PATH = os.path.join("abb-build", "l10n") 38 _L10N_PATH = os.path.join("abb-build", "l10n")
diegocarloslima 2017/12/13 10:44:42 This var should be named L10N_PATH :)
38 _LISTJSON_PATH = os.path.join("mobile", "locales", "search") 39 _LOCALES_PATH = os.path.join("mobile", "locales")
39 _SEARCHPLUGINS_PATH = os.path.join("mobile", "locales", "searchplugins") 40 _LISTJSON_PATH = os.path.join(_LOCALES_PATH, "search", "list.json")
diegocarloslima 2017/12/13 10:44:41 Maybe the ("mobile","locales") part could be extra
41 _GENERAL_SEARCHPLUGINS_PATH = os.path.join(_LOCALES_PATH, "searchplugins")
40 42
41 _BROWSER_DIR = "browser" 43 _BROWSER_DIR = "browser"
42 _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")
43 46
44 _APPSTRINGS_PROPS_PATH = os.path.join(_BROWSER_DIR, "appstrings.properties") 47 _APPSTRINGS_PROPS_PATH = os.path.join(_BROWSER_DIR, "appstrings.properties")
45 _STRINGS_XML_PATH = "strings.xml" 48 _STRINGS_XML_PATH = "strings.xml"
46 _LIST_JSON = "list.json"
47 49
48 _DEFAULT_LOCALE = "en-US" 50 _DEFAULT_LOCALE = "en-US"
49 _KEY_VDF = "visibleDefaultEngines" 51 _DEF_ENGINES = "visibleDefaultEngines"
50 _KEY_LOC = "locales"
51 _KEY_DEF = "default"
diegocarloslima 2017/12/13 10:44:42 I know that having short variable names helps to b
52 52
53 # Add Ecosia as secondary search engine. 53 # Add Ecosia as secondary search engine.
54 # See https://issues.adblockplus.org/ticket/5518 54 # See https://issues.adblockplus.org/ticket/5518
55 _ECOSIA_ID = "ecosia" 55 _ECOSIA_ID = "ecosia"
56 _ECOSIA_PATH = os.path.join(_GENERAL_SEARCHPLUGINS_PATH, "ecosia.xml")
56 57
57 _SEARCH_ENGINE_ORDER_DEFAULT = [ 58 _SEARCH_ENGINE_ORDER_DEFAULT = [
58 "duckduckgo", 59 "duckduckgo",
59 "yahoo", 60 "yahoo",
60 "google", 61 "google",
61 "wikipedia", 62 "wikipedia",
62 "amazondotcom"] 63 "amazondotcom"]
63 64
64 _SEARCH_ENGINE_ORDER_ECOSIA = [ 65 _SEARCH_ENGINE_ORDER_ECOSIA = [
65 "duckduckgo", 66 "duckduckgo",
66 "yahoo", 67 "yahoo",
67 "google", 68 "google",
68 "ecosia", 69 _ECOSIA_ID,
69 "wikipedia", 70 "wikipedia",
70 "amazon"] 71 "amazon"]
71 72
72 _SEARCH_ENGINE_ORDER = { 73 _SEARCH_ENGINE_ORDER = {
73 "de": _SEARCH_ENGINE_ORDER_ECOSIA, 74 "de": _SEARCH_ENGINE_ORDER_ECOSIA,
74 "en-GB": _SEARCH_ENGINE_ORDER_ECOSIA, 75 "en-GB": _SEARCH_ENGINE_ORDER_ECOSIA,
75 "en-US": _SEARCH_ENGINE_ORDER_ECOSIA, 76 "en-US": _SEARCH_ENGINE_ORDER_ECOSIA,
76 "fr": _SEARCH_ENGINE_ORDER_ECOSIA, 77 "fr": _SEARCH_ENGINE_ORDER_ECOSIA,
77 "nl": _SEARCH_ENGINE_ORDER_ECOSIA, 78 "nl": _SEARCH_ENGINE_ORDER_ECOSIA,
78 "zh-CN": ["baidu", 79 "zh-CN": ["baidu",
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 return None 150 return None
150 151
151 152
152 def _write_lines(filename, lines): 153 def _write_lines(filename, lines):
153 """Writes lines into file appending \\n""" 154 """Writes lines into file appending \\n"""
154 with open(filename, "w") as fd: 155 with open(filename, "w") as fd:
155 for l in lines: 156 for l in lines:
156 fd.write("%s\n" % l) 157 fd.write("%s\n" % l)
157 158
158 159
159 def _transform_locale(locale, build_dir, locale_path, logger): 160 def _transform_locale(data, locale, project_dir, locale_path, logger):
160 logger.info("Processing locale '%s'..." % locale) 161 logger.info("Processing locale '%s'..." % locale)
161 search_list_path = os.path.join(build_dir, _LISTJSON_PATH)
162 _check_path_exists(search_list_path, logger)
diegocarloslima 2017/12/13 10:44:41 I think it makes more sense to check for the exist
163 162
164 # Check for region.properties existence 163 # Check for region.properties existence
165 region_file_path = os.path.join(locale_path, _REGION_PROPS_PATH) 164 region_file_path = os.path.join(locale_path, _REGION_PROPS_PATH)
166 _check_path_exists(region_file_path, logger) 165 _check_path_exists(region_file_path, logger)
167 166
168 # Check for appstrings.properties existence 167 # Check for appstrings.properties existence
169 appstrings_file_path = os.path.join(locale_path, _APPSTRINGS_PROPS_PATH) 168 appstrings_file_path = os.path.join(locale_path, _APPSTRINGS_PROPS_PATH)
170 _check_path_exists(appstrings_file_path, logger) 169 _check_path_exists(appstrings_file_path, logger)
170
171 ecosia_dst = os.path.join(locale_path,
172 _LOCALE_SEARCHPLUGINS_PATH, "ecosia.xml")
171 173
172 # Get whitelist and build regex 174 # Get whitelist and build regex
173 whitelist = _SEARCH_ENGINE_ORDER.get(locale, 175 whitelist = _SEARCH_ENGINE_ORDER.get(locale,
174 _SEARCH_ENGINE_ORDER_DEFAULT) 176 _SEARCH_ENGINE_ORDER_DEFAULT)
175 white_re = re.compile("^(%s).*$" % "|".join(whitelist)) 177 white_re = re.compile("^(%s).*$" % "|".join(whitelist))
176 178
179 if _ECOSIA_ID in whitelist and not os.path.exists(ecosia_dst):
180 shutil.copyfile(os.path.join(project_dir, _ECOSIA_PATH), ecosia_dst)
181
177 all_engine_ids = [] 182 all_engine_ids = []
178 engine_ids = [] 183 engine_ids = []
179 removed_engine_ids = [] 184 removed_engine_ids = []
180 185
181 jsonFile = open(os.path.join(search_list_path, _LIST_JSON), 'r') 186 for item in data['locales'][locale]['default'][_DEF_ENGINES]:
182 data = json.load(jsonFile)
183 jsonFile.close()
diegocarloslima 2017/12/13 10:44:42 We could use the `with open` syntax here, to avoid
184
185 for item in data[_KEY_LOC][locale][_KEY_DEF][_KEY_VDF]:
186 all_engine_ids.append(item) 187 all_engine_ids.append(item)
187 if white_re.match(item): 188 if len(item) > 0:
188 engine_ids.append(item) 189 if white_re.match(item):
189 else: 190 engine_ids.append(item)
190 removed_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)
196 engine_ids.append(_ECOSIA_ID)
191 197
192 # Make sure we still have search engines left 198 # Make sure we still have search engines left
193 if len(engine_ids) == 0: 199 if len(engine_ids) == 0:
194 logger.fatal("No search engines left over for '%s'" % locale) 200 logger.fatal("No search engines left over for '%s'" % locale)
195 201
202 data['locales'][locale]['default'][_DEF_ENGINES] = all_engine_ids
203
196 # 'Parse' XML to get matching 'ShortName' for all engine IDs 204 # 'Parse' XML to get matching 'ShortName' for all engine IDs
197 engine_names = {} 205 engine_names = {}
198 search_plugins_path = os.path.join(build_dir, _SEARCHPLUGINS_PATH) 206 search_plugins_path = os.path.join(project_dir,
207 _GENERAL_SEARCHPLUGINS_PATH)
199 for eid in engine_ids[:]: 208 for eid in engine_ids[:]:
200 xml_file_path = os.path.join(search_plugins_path, "%s.xml" % eid) 209 xml_file_path = os.path.join(search_plugins_path, "%s.xml" % eid)
201 if not os.path.exists(xml_file_path): 210 if not os.path.exists(xml_file_path):
202 logger.info("Missing xml file for plugin %s. Searched in path %s" % 211 logger.info("Missing xml file for plugin %s. Searched in path %s" %
203 (eid, xml_file_path)) 212 (eid, xml_file_path))
204 engine_ids.remove(eid) 213 engine_ids.remove(eid)
205 continue 214 continue
206 short_name = None 215 short_name = None
207 with open(xml_file_path, "r") as fd: 216 with open(xml_file_path, "r") as fd:
208 for line in fd: 217 for line in fd:
(...skipping 26 matching lines...) Expand all
235 with open(region_file_path, "r") as fd: 244 with open(region_file_path, "r") as fd:
236 for line in fd: 245 for line in fd:
237 line = line.rstrip("\r\n") 246 line = line.rstrip("\r\n")
238 if not _SEARCH_PROPS_RE.match(line.strip()): 247 if not _SEARCH_PROPS_RE.match(line.strip()):
239 props.append(line) 248 props.append(line)
240 249
241 # Append default search engine name 250 # Append default search engine name
242 props.append("browser.search.defaultenginename=%s" % engine_order[0]) 251 props.append("browser.search.defaultenginename=%s" % engine_order[0])
243 252
244 # Append search engine order 253 # Append search engine order
245 for i in range(0, min(5, len(engine_order))): 254 for i in range(0, len(engine_order)):
diegocarloslima 2017/12/13 10:44:42 The condition here should be `for i in range(0, le
246 props.append("browser.search.order.%d=%s" % (i + 1, engine_order[i])) 255 props.append("browser.search.order.%d=%s" % (i + 1, engine_order[i]))
247 256
248 # Write back region.properties 257 # Write back region.properties
249 _write_lines(region_file_path, props) 258 _write_lines(region_file_path, props)
250 259
251 # Replaces ocurrences of 'Firefox' by 'Adblock Browser' in 260 # Replaces ocurrences of 'Firefox' by 'Adblock Browser' in
252 # 'appstrings.properties' 261 # 'appstrings.properties'
253 lines = [] 262 lines = []
254 replacement_count = 0 263 replacement_count = 0
255 264
256 with open(appstrings_file_path, "r") as fd: 265 with open(appstrings_file_path, "r") as fd:
257 for line in fd: 266 for line in fd:
258 line = line.rstrip("\r\n") 267 line = line.rstrip("\r\n")
259 replacement = _replace_in_value(_PROPERTY_FORMAT_RE, line, 268 replacement = _replace_in_value(_PROPERTY_FORMAT_RE, line,
260 _FIREFOX_REPLACE_STR, 269 _FIREFOX_REPLACE_STR,
261 _ABB_REPLACEMENT_STR) 270 _ABB_REPLACEMENT_STR)
262 if replacement: 271 if replacement:
263 line = replacement 272 line = replacement
264 replacement_count += 1 273 replacement_count += 1
265 lines.append(line) 274 lines.append(line)
266 275
267 # Apply changes to appstrings.properties 276 # Apply changes to appstrings.properties
268 _write_lines(appstrings_file_path, lines) 277 _write_lines(appstrings_file_path, lines)
269 logger.info("Replaced %d ocurrences of %s in 'appstrings.properties'" % 278 logger.info("Replaced %d ocurrences of %s in 'appstrings.properties'" %
270 (replacement_count, _FIREFOX_REPLACE_STR)) 279 (replacement_count, _FIREFOX_REPLACE_STR))
271 280
272 281
273 def _generate_browser_search(locale, locale_path, res_path, build_dir): 282 def _generate_browser_search(locale, locale_path, res_path, project_dir):
274 raw_dir = "raw" if locale == _DEFAULT_LOCALE else ( 283 raw_dir = "raw" if locale == _DEFAULT_LOCALE else (
275 "raw-%s" % locale.replace("-", "-r")) 284 "raw-%s" % locale.replace("-", "-r"))
276 285
277 browser_path = os.path.join(locale_path, _BROWSER_DIR) 286 browser_path = os.path.join(locale_path, _BROWSER_DIR)
278 browsersearch_file_path = os.path.join(res_path, raw_dir, 287 browsersearch_file_path = os.path.join(res_path, raw_dir,
279 "browsersearch.json") 288 "browsersearch.json")
280 289
281 sys.path.append(os.path.join(build_dir, _MOZBUILD_PATH)) 290 sys.path.append(os.path.join(project_dir, _MOZBUILD_PATH))
282 import mozbuild.action.generate_browsersearch as generate_browsersearch 291 import mozbuild.action.generate_browsersearch as generate_browsersearch
283 292
284 # Call generate_browsersearch.py script to regenerate 293 # Call generate_browsersearch.py script to regenerate
285 # res/raw-LOCALE/browsersearch.json with the updated search engines 294 # res/raw-LOCALE/browsersearch.json with the updated search engines
286 generate_browsersearch.main(["--verbose", "--srcdir", browser_path, 295 generate_browsersearch.main(["--verbose", "--srcdir", browser_path,
287 browsersearch_file_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])
288 310
289 311
290 def _transform_values_locale(locale, path, logger): 312 def _transform_values_locale(locale, path, logger):
291 logger.info("Processing values-%s..." % locale) 313 logger.info("Processing values-%s..." % locale)
292 314
293 # Check for strings.xml existence 315 # Check for strings.xml existence
294 strings_file_path = os.path.join(path, _STRINGS_XML_PATH) 316 strings_file_path = os.path.join(path, _STRINGS_XML_PATH)
295 _check_path_exists(strings_file_path, logger) 317 _check_path_exists(strings_file_path, logger)
296 318
297 # Replaces ocurrences of 'Firefox' by 'Adblock Browser' in 'strings.xml' 319 # Replaces ocurrences of 'Firefox' by 'Adblock Browser' in 'strings.xml'
(...skipping 30 matching lines...) Expand all
328 print "INFO: %s" % s 350 print "INFO: %s" % s
329 351
330 def error(self, s): 352 def error(self, s):
331 print "ERROR: %s" % s 353 print "ERROR: %s" % s
332 354
333 def fatal(self, s): 355 def fatal(self, s):
334 print "FATAL: %s" % s 356 print "FATAL: %s" % s
335 exit(1) 357 exit(1)
336 358
337 359
338 def transform_locales(build_dir, obj_dir, logger=MinimalLogger()): 360 def transform_locales(project_dir, obj_dir, logger=MinimalLogger()):
339 chrome_path = os.path.join(obj_dir, _CHROME_PATH) 361 chrome_path = os.path.join(obj_dir, _CHROME_PATH)
340 _check_path_exists(chrome_path, logger) 362 _check_path_exists(chrome_path, logger)
341 363
342 res_path = os.path.join(obj_dir, _RES_PATH) 364 res_path = os.path.join(obj_dir, _RES_PATH)
343 _check_path_exists(res_path, logger) 365 _check_path_exists(res_path, logger)
366
367 list_json_path = os.path.join(project_dir, _LISTJSON_PATH)
368 _check_path_exists(list_json_path, logger)
344 369
345 locales = _get_locales_from_path(chrome_path, _LOCALE_RE) 370 locales = _get_locales_from_path(chrome_path, _LOCALE_RE)
346 values_locales = _get_locales_from_path(res_path, _VALUES_LOCALE_RE) 371 values_locales = _get_locales_from_path(res_path, _VALUES_LOCALE_RE)
347 372
348 locales_found_msg = "Found %d locales in %s" 373 locales_found_msg = "Found %d locales in %s"
349 logger.info(locales_found_msg % (len(locales), chrome_path)) 374 logger.info(locales_found_msg % (len(locales), chrome_path))
350 logger.info(locales_found_msg % (len(values_locales), res_path)) 375 logger.info(locales_found_msg % (len(values_locales), res_path))
351 376
352 for locale in locales:
353 locale_path = os.path.join(chrome_path, locale, "locale", locale)
354 if os.path.exists(locale_path):
355 _transform_locale(locale, build_dir, locale_path, logger)
356 _generate_browser_search(locale, locale_path, res_path, build_dir)
357 else:
358 logger.error("Missing folder for locale '%s' in path: %s" %
359 (locale, locale_path))
360
361 for locale in values_locales:
362 locale_path = os.path.join(res_path, "values-" + locale)
363 _transform_values_locale(locale, locale_path, logger)
364
365
366 def transform_search_engines_list(abs_mozilla_dir, obj_dir,
diegocarloslima 2017/12/13 10:44:42 I see that you're using here the `abs_mozilla_dir`
367 logger=MinimalLogger()):
368 # open the Mozilla list of search engines, put it into a buffer and 377 # open the Mozilla list of search engines, put it into a buffer and
369 # close the JSON file after reading 378 # close the JSON file after reading
370 search_list_path = os.path.join(abs_mozilla_dir, _LISTJSON_PATH) 379 with open(list_json_path, 'r') as json_file:
371 jsonFile = open(os.path.join(search_list_path, _LIST_JSON), 'r') 380 data = json.load(json_file)
372 data = json.load(jsonFile) 381
373 jsonFile.close() 382 # set default search engine order
diegocarloslima 2017/12/13 10:44:41 We could use the `with open` syntax here, to avoid
374 383 data['default'][_DEF_ENGINES] = _SEARCH_ENGINE_ORDER_DEFAULT
375 chrome_path = os.path.join(abs_mozilla_dir, _I10N_PATH) 384
diegocarloslima 2017/12/13 10:44:42 Didn't really get why are you using a different ch
376 _check_path_exists(chrome_path, logger) 385 for locale in locales:
377 # get all locales we want to transform 386 locale_path = os.path.join(chrome_path, locale, "locale", locale)
378 locales = _get_locales_from_path(chrome_path, _LOCALE_RE) 387 if os.path.exists(locale_path):
379 388
380 # set default search engine order 389 # Mozilla default list does not contain locale bn-BD,
381 data[_KEY_DEF][_KEY_VDF] = _SEARCH_ENGINE_ORDER_DEFAULT 390 # so we create it and use the values from locale bn-IN
382 for loc in locales: 391 if locale == 'bn-BD':
diegocarloslima 2017/12/13 10:44:42 If we moved all the logic that is currently being
diegocarloslima 2017/12/13 10:55:29 Also, I think that this should be an internal func
383 whitelist = _SEARCH_ENGINE_ORDER.get(loc, 392 data['locales'].update({locale: {'default':
384 _SEARCH_ENGINE_ORDER_DEFAULT) 393 {_DEF_ENGINES:
385 white_re = re.compile("^(%s).*$" % "|".join(whitelist)) 394 data['locales']['bn-IN']['default'][_DEF_ENGINES]}}})
386 395 # Mozilla default list does not contain locale wo, so we use
387 # Read engine IDs from list.json, discard engines not on whitelist 396 # the default order. In case they will not support any other
388 all_engine_ids = [] 397 # locales in the future, we want the build to fail, to decide
389 engine_ids = [] 398 # which order to use
390 removed_engine_ids = [] 399 elif locale == 'wo':
391 400 data['locales'].update({locale: {'default':
392 # Mozilla default list does not contain locale bn-BD, so we create it 401 {_DEF_ENGINES:
393 # and use the values from locale bn-IN 402 _SEARCH_ENGINE_ORDER_DEFAULT}}})
394 if loc == "bn-BD": 403
395 data[_KEY_LOC].update({loc: {_KEY_DEF: {_KEY_VDF: data[_KEY_LOC] 404 _transform_locale(data, locale, project_dir, locale_path,
396 ["bn-IN"][_KEY_DEF][_KEY_VDF]}}}) 405 logger)
397 # Mozilla default list does not contain locale wo, so we use the 406 _generate_browser_search(locale, locale_path, res_path,
398 # default order. In case they will not support any other locales in 407 project_dir)
399 # the future, we want the build to fail, to decide which order to use 408 else:
400 elif loc == "wo": 409 logger.error("Missing folder for locale '%s' in path: %s" %
401 data[_KEY_LOC].update({loc: {_KEY_DEF: 410 (locale, locale_path))
402 {_KEY_VDF: _SEARCH_ENGINE_ORDER_DEFAULT}}}) 411
403 412 # Save changes to list.json
404 for item in data[_KEY_LOC][loc][_KEY_DEF][_KEY_VDF]: 413 with open(list_json_path, 'w') as outfile:
405 all_engine_ids.append(item) 414 json.dump(data, outfile, indent=4, sort_keys=True)
406 if len(item) > 0: 415
407 if white_re.match(item): 416 # Generate search.json for each locale
408 engine_ids.append(item) 417 for locale in locales:
409 else: 418 locale_path = os.path.join(chrome_path, locale, "locale", locale)
410 removed_engine_ids.append(item) 419 _generate_search_json(locale, locale_path, project_dir)
411 420
412 if _ECOSIA_ID in whitelist and _ECOSIA_ID not in all_engine_ids: 421 for locale in values_locales:
413 all_engine_ids.append(_ECOSIA_ID) 422 locale_path = os.path.join(res_path, "values-" + locale)
414 engine_ids.append(_ECOSIA_ID) 423 _transform_values_locale(locale, locale_path, logger)
415
416 # Make sure we still have search engines left
417 if len(engine_ids) == 0:
418 logger.fatal("No search engines left over for '%s'" % loc)
419
420 data[_KEY_LOC][loc][_KEY_DEF][_KEY_VDF] = all_engine_ids
421
422 # Save our changes to list.json
423 with open(os.path.join(search_list_path, _LIST_JSON), 'w') as outfile:
424 json.dump(data, outfile, indent=4, sort_keys=True)
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld