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

Side by Side Diff: mozharness/mozilla/l10n/locales.py

Issue 29527865: Issue 5579 - Download json file with locale revisions for multilocale build (Closed)
Patch Set: Created Aug. 25, 2017, 9:49 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # ***** BEGIN LICENSE BLOCK ***** 2 # ***** BEGIN LICENSE BLOCK *****
3 # This Source Code Form is subject to the terms of the Mozilla Public 3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this file, 4 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 # You can obtain one at http://mozilla.org/MPL/2.0/. 5 # You can obtain one at http://mozilla.org/MPL/2.0/.
6 # ***** END LICENSE BLOCK ***** 6 # ***** END LICENSE BLOCK *****
7 """Localization. 7 """Localization.
8 """ 8 """
9 9
10 import os 10 import os
11 from urlparse import urljoin 11 from urlparse import urljoin
12 import sys 12 import sys
13 from copy import deepcopy 13 from copy import deepcopy
14 14
15 sys.path.insert(1, os.path.dirname(sys.path[0])) 15 sys.path.insert(1, os.path.dirname(sys.path[0]))
16 16
17 # Added import. See https://issues.adblockplus.org/ticket/5579
18 from mozharness.base.config import download_config_file
17 from mozharness.base.config import parse_config_file 19 from mozharness.base.config import parse_config_file
18 from mozharness.base.errors import PythonErrorList 20 from mozharness.base.errors import PythonErrorList
19 from mozharness.base.parallel import ChunkingMixin 21 from mozharness.base.parallel import ChunkingMixin
20 22
21 23
22 # LocalesMixin {{{1 24 # LocalesMixin {{{1
23 class LocalesMixin(ChunkingMixin): 25 class LocalesMixin(ChunkingMixin):
24 def __init__(self, **kwargs): 26 def __init__(self, **kwargs):
25 """ Mixins generally don't have an __init__. 27 """ Mixins generally don't have an __init__.
26 This breaks super().__init__() for children. 28 This breaks super().__init__() for children.
(...skipping 11 matching lines...) Expand all
38 ignore_locales = c.get("ignore_locales", []) 40 ignore_locales = c.get("ignore_locales", [])
39 additional_locales = c.get("additional_locales", []) 41 additional_locales = c.get("additional_locales", [])
40 42
41 if locales is None: 43 if locales is None:
42 locales = [] 44 locales = []
43 if 'locales_file' in c: 45 if 'locales_file' in c:
44 # Best way to get abs/relative path to this? 46 # Best way to get abs/relative path to this?
45 locales_file = os.path.join(c['base_work_dir'], c['work_dir'], 47 locales_file = os.path.join(c['base_work_dir'], c['work_dir'],
46 c['locales_file']) 48 c['locales_file'])
47 locales = self.parse_locales_file(locales_file) 49 locales = self.parse_locales_file(locales_file)
50 # Added locales_json_url configuration
51 # See https://issues.adblockplus.org/ticket/5579
52 elif 'locales_json_url' in c:
53 locales_json_file = os.path.join(c['base_work_dir'],
54 c['work_dir'],
55 "generated",
56 "locales.json")
57 download_config_file(c['locales_json_url'], locales_json_file)
58 locales = self.parse_locales_json(locales_json_file)
48 else: 59 else:
49 self.fatal("No way to determine locales!") 60 self.fatal("No way to determine locales!")
50 for locale in ignore_locales: 61 for locale in ignore_locales:
51 if locale in locales: 62 if locale in locales:
52 self.debug("Ignoring locale %s." % locale) 63 self.debug("Ignoring locale %s." % locale)
53 locales.remove(locale) 64 locales.remove(locale)
54 for locale in additional_locales: 65 for locale in additional_locales:
55 if locale not in locales: 66 if locale not in locales:
56 self.debug("Adding locale %s." % locale) 67 self.debug("Adding locale %s." % locale)
57 locales.append(locale) 68 locales.append(locale)
(...skipping 28 matching lines...) Expand all
86 continue 97 continue
87 self.locale_dict[locale] = locales_json[locale]['revision'] 98 self.locale_dict[locale] = locales_json[locale]['revision']
88 else: 99 else:
89 # some other way of getting this? 100 # some other way of getting this?
90 self.locale_dict[locale] = 'default' 101 self.locale_dict[locale] = 'default'
91 locales.append(locale) 102 locales.append(locale)
92 else: 103 else:
93 locales = self.read_from_file(locales_file).split() 104 locales = self.read_from_file(locales_file).split()
94 return locales 105 return locales
95 106
107 # Parses the appropriate revision/changeset for each locale
108 # See https://issues.adblockplus.org/ticket/5579
109 def parse_locales_json(self, locales_json_file):
110 locales = []
111 locales_json = parse_config_file(locales_json_file)
112 self.locale_dict = {}
113 locales_dict = locales_json['locales']
114 for locale in locales_dict.keys():
115 self.locale_dict[locale] = locales_dict[locale]['changeset']
116 locales.append(locale)
117 return locales
118
96 def run_compare_locales(self, locale, halt_on_failure=False): 119 def run_compare_locales(self, locale, halt_on_failure=False):
97 dirs = self.query_abs_dirs() 120 dirs = self.query_abs_dirs()
98 compare_locales_script = os.path.join(dirs['abs_compare_locales_dir'], 121 compare_locales_script = os.path.join(dirs['abs_compare_locales_dir'],
99 'scripts', 'compare-locales') 122 'scripts', 'compare-locales')
100 env = self.query_env(partial_env={'PYTHONPATH': 123 env = self.query_env(partial_env={'PYTHONPATH':
101 os.path.join(dirs['abs_compare_locales_dir'], 124 os.path.join(dirs['abs_compare_locales_dir'],
102 'lib')}) 125 'lib')})
103 compare_locales_error_list = list(PythonErrorList) 126 compare_locales_error_list = list(PythonErrorList)
104 self.rmtree(dirs['abs_merge_dir']) 127 self.rmtree(dirs['abs_merge_dir'])
105 self.mkdir_p(dirs['abs_merge_dir']) 128 self.mkdir_p(dirs['abs_merge_dir'])
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 'vcs': vcs, 232 'vcs': vcs,
210 'env': env, 233 'env': env,
211 }) 234 })
212 self.gaia_locale_revisions = self.vcs_checkout_repos(repo_list=repos, pa rent_dir=base_dir) 235 self.gaia_locale_revisions = self.vcs_checkout_repos(repo_list=repos, pa rent_dir=base_dir)
213 236
214 237
215 # __main__ {{{1 238 # __main__ {{{1
216 239
217 if __name__ == '__main__': 240 if __name__ == '__main__':
218 pass 241 pass
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld