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

Delta Between Two Patch Sets: build.py

Issue 29336281: Issue 2109 - Allow for translation of app independent repositories (Closed)
Left Patch Set: Addressed Wladimir's initial feedback Created Feb. 12, 2016, 6:23 p.m.
Right Patch Set: Fixed typo spotted during testing Created Feb. 13, 2016, 12:31 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 | localeTools.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # coding: utf-8 1 # coding: utf-8
2 2
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 4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 6
7 import os, sys, re, subprocess, shutil, buildtools 7 import os, sys, re, subprocess, shutil, buildtools
8 from getopt import getopt, GetoptError 8 from getopt import getopt, GetoptError
9 from StringIO import StringIO 9 from StringIO import StringIO
10 from zipfile import ZipFile 10 from zipfile import ZipFile
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 from buildtools.packager import getDevEnvPath 229 from buildtools.packager import getDevEnvPath
230 devenv_dir = getDevEnvPath(baseDir, type) 230 devenv_dir = getDevEnvPath(baseDir, type)
231 231
232 shutil.rmtree(devenv_dir, ignore_errors=True) 232 shutil.rmtree(devenv_dir, ignore_errors=True)
233 233
234 file.seek(0) 234 file.seek(0)
235 with ZipFile(file, 'r') as zip_file: 235 with ZipFile(file, 'r') as zip_file:
236 zip_file.extractall(devenv_dir) 236 zip_file.extractall(devenv_dir)
237 237
238 238
239 def readLocaleConfig(baseDir, type, metadata, includeIncomplete=False): 239 def readLocaleConfig(baseDir, type, metadata):
240 if type == 'gecko': 240 if type == 'gecko':
241 import buildtools.packagerGecko as packager 241 import buildtools.packagerGecko as packager
242 basePath = packager.getLocalesDir(baseDir) 242 localeDir = packager.getLocalesDir(baseDir)
243 return { 243 localeConfig = {
244 'base_path': basePath,
245 'name_format': 'BCP-47', 244 'name_format': 'BCP-47',
246 'file_format': 'gecko-dtd', 245 'file_format': 'gecko-dtd',
247 'target_platforms': {'gecko'}, 246 'target_platforms': {'gecko'},
248 'default_locale': packager.defaultLocale, 247 'default_locale': packager.defaultLocale
249 'locales': {locale: os.path.join(basePath, locale)
250 for locale in packager.getLocales(baseDir, includeIncomplete)}
251 } 248 }
Wladimir Palant 2016/02/12 19:05:43 Gecko is still being treated as a special case her
kzar 2016/02/12 19:40:26 Done.
252 249 elif type == 'chrome' or type == 'opera':
253 if type == 'chrome' or type == 'opera':
254 import buildtools.packagerChrome as packager 250 import buildtools.packagerChrome as packager
255 localeDir = '_locales' 251 localeDir = os.path.join(baseDir, '_locales')
256 localeConfig = { 252 localeConfig = {
257 'name_format': 'ISO-15897', 253 'name_format': 'ISO-15897',
258 'file_format': 'chrome-json', 254 'file_format': 'chrome-json',
259 'target_platforms': {'chrome'}, 255 'target_platforms': {'chrome'},
260 'default_locale': packager.defaultLocale, 256 'default_locale': packager.defaultLocale,
261 } 257 }
262 else: 258 else:
263 localeDir = metadata.get('locales', 'base_path') 259 localeDir = os.path.join(baseDir,
260 *metadata.get('locales', 'base_path').split('/'))
264 localeConfig = { 261 localeConfig = {
265 'name_format': metadata.get('locales', 'name_format'), 262 'name_format': metadata.get('locales', 'name_format'),
266 'file_format': metadata.get('locales', 'file_format'), 263 'file_format': metadata.get('locales', 'file_format'),
267 'target_platforms': set(metadata.get('locales', 264 'target_platforms': set(metadata.get('locales',
268 'target_platforms').split()), 265 'target_platforms').split()),
269 'default_locale': metadata.get('locales', 'default_locale') 266 'default_locale': metadata.get('locales', 'default_locale')
270 } 267 }
271 268
272 localeConfig['base_path'] = fullBasePath = os.path.join(baseDir, localeDir) 269 localeConfig['base_path'] = localeDir
273 270
274 locales = [(locale, os.path.join(fullBasePath, locale)) 271 locales = [(locale, os.path.join(localeDir, locale))
275 for locale in os.listdir(fullBasePath)] 272 for locale in os.listdir(localeDir)]
276 if localeConfig['name_format'] == 'ISO-15897': 273 if localeConfig['name_format'] == 'ISO-15897':
277 locales = [(locale.replace('_', '-'), localePath) 274 locales = [(locale.replace('_', '-'), localePath)
278 for locale, localePath in locales] 275 for locale, localePath in locales]
279 localeConfig['locales'] = dict(locales) 276 localeConfig['locales'] = dict(locales)
280 277
281 return localeConfig 278 return localeConfig
282 279
283 def setupTranslations(baseDir, scriptName, opts, args, type): 280 def setupTranslations(baseDir, scriptName, opts, args, type):
284 if len(args) < 1: 281 if len(args) < 1:
285 print 'Project key is required to update translation master files.' 282 print 'Project key is required to update translation master files.'
286 usage(scriptName, type, 'setuptrans') 283 usage(scriptName, type, 'setuptrans')
287 return 284 return
288 285
289 key = args[0] 286 key = args[0]
290 287
291 from buildtools.packager import readMetadata 288 from buildtools.packager import readMetadata
292 metadata = readMetadata(baseDir, type) 289 metadata = readMetadata(baseDir, type)
293 290
294 basename = metadata.get('general', 'basename') 291 basename = metadata.get('general', 'basename')
295 localeConfig = readLocaleConfig(baseDir, type, metadata, True) 292 localeConfig = readLocaleConfig(baseDir, type, metadata)
296 293
297 import buildtools.localeTools as localeTools 294 import buildtools.localeTools as localeTools
298 localeTools.setupTranslations(localeConfig, basename, key) 295 localeTools.setupTranslations(localeConfig, basename, key)
299 296
300 297
301 def updateTranslationMaster(baseDir, scriptName, opts, args, type): 298 def updateTranslationMaster(baseDir, scriptName, opts, args, type):
302 if len(args) < 1: 299 if len(args) < 1:
303 print 'Project key is required to update translation master files.' 300 print 'Project key is required to update translation master files.'
304 usage(scriptName, type, 'translate') 301 usage(scriptName, type, 'translate')
305 return 302 return
(...skipping 19 matching lines...) Expand all
325 print 'Project key is required to upload existing translations.' 322 print 'Project key is required to upload existing translations.'
326 usage(scriptName, type, 'uploadtrans') 323 usage(scriptName, type, 'uploadtrans')
327 return 324 return
328 325
329 key = args[0] 326 key = args[0]
330 327
331 from buildtools.packager import readMetadata 328 from buildtools.packager import readMetadata
332 metadata = readMetadata(baseDir, type) 329 metadata = readMetadata(baseDir, type)
333 330
334 basename = metadata.get('general', 'basename') 331 basename = metadata.get('general', 'basename')
335 localeConfig = readLocaleConfig(baseDir, type, metadata, True) 332 localeConfig = readLocaleConfig(baseDir, type, metadata)
336 333
337 import buildtools.localeTools as localeTools 334 import buildtools.localeTools as localeTools
338 for locale, localeDir in localeConfig['locales'].iteritems(): 335 for locale, localeDir in localeConfig['locales'].iteritems():
339 if locale != localeConfig['default_locale']: 336 if locale != localeConfig['default_locale']:
340 localeTools.uploadTranslations(localeConfig, metadata, localeDir, locale, 337 localeTools.uploadTranslations(localeConfig, metadata, localeDir, locale,
341 basename, key) 338 basename, key)
342 339
343 340
344 def getTranslations(baseDir, scriptName, opts, args, type): 341 def getTranslations(baseDir, scriptName, opts, args, type):
345 if len(args) < 1: 342 if len(args) < 1:
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 if option in ('-h', '--help'): 595 if option in ('-h', '--help'):
599 usage(scriptName, type, command) 596 usage(scriptName, type, command)
600 sys.exit() 597 sys.exit()
601 commands[command](baseDir, scriptName, opts, args, type) 598 commands[command](baseDir, scriptName, opts, args, type)
602 else: 599 else:
603 print 'Command %s is not supported for this application type' % command 600 print 'Command %s is not supported for this application type' % command
604 usage(scriptName, type) 601 usage(scriptName, type)
605 else: 602 else:
606 print 'Command %s is unrecognized' % command 603 print 'Command %s is unrecognized' % command
607 usage(scriptName, type) 604 usage(scriptName, type)
LEFTRIGHT
« no previous file | localeTools.py » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld