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 some further feedback from Wladimir Created Feb. 12, 2016, 7:39 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 localeDir = packager.getLocalesDir(baseDir) 242 localeDir = packager.getLocalesDir(baseDir)
243 localeConfig = { 243 localeConfig = {
244 'name_format': 'BCP-47', 244 'name_format': 'BCP-47',
245 'file_format': 'gecko-dtd', 245 'file_format': 'gecko-dtd',
246 'target_platforms': {'gecko'}, 246 'target_platforms': {'gecko'},
247 'default_locale': packager.defaultLocale 247 'default_locale': packager.defaultLocale
248 } 248 }
249 elif type == 'chrome' or type == 'opera': 249 elif type == 'chrome' or type == 'opera':
(...skipping 12 matching lines...) Expand all
262 'name_format': metadata.get('locales', 'name_format'), 262 'name_format': metadata.get('locales', 'name_format'),
263 'file_format': metadata.get('locales', 'file_format'), 263 'file_format': metadata.get('locales', 'file_format'),
264 'target_platforms': set(metadata.get('locales', 264 'target_platforms': set(metadata.get('locales',
265 'target_platforms').split()), 265 'target_platforms').split()),
266 'default_locale': metadata.get('locales', 'default_locale') 266 'default_locale': metadata.get('locales', 'default_locale')
267 } 267 }
268 268
269 localeConfig['base_path'] = localeDir 269 localeConfig['base_path'] = localeDir
270 270
271 locales = [(locale, os.path.join(localeDir, locale)) 271 locales = [(locale, os.path.join(localeDir, locale))
272 for locale in os.listdir(localeDir)] 272 for locale in os.listdir(localeDir)]
Wladimir Palant 2016/02/12 19:49:34 This is actually fine for the use cases so far, bu
kzar 2016/02/12 20:05:36 Done but I omitted this parameter accidentally, ar
273 if localeConfig['name_format'] == 'ISO-15897': 273 if localeConfig['name_format'] == 'ISO-15897':
274 locales = [(locale.replace('_', '-'), localePath) 274 locales = [(locale.replace('_', '-'), localePath)
275 for locale, localePath in locales] 275 for locale, localePath in locales]
276 localeConfig['locales'] = dict(locales) 276 localeConfig['locales'] = dict(locales)
277 277
278 return localeConfig 278 return localeConfig
279 279
280 def setupTranslations(baseDir, scriptName, opts, args, type): 280 def setupTranslations(baseDir, scriptName, opts, args, type):
281 if len(args) < 1: 281 if len(args) < 1:
282 print 'Project key is required to update translation master files.' 282 print 'Project key is required to update translation master files.'
283 usage(scriptName, type, 'setuptrans') 283 usage(scriptName, type, 'setuptrans')
284 return 284 return
285 285
286 key = args[0] 286 key = args[0]
287 287
288 from buildtools.packager import readMetadata 288 from buildtools.packager import readMetadata
289 metadata = readMetadata(baseDir, type) 289 metadata = readMetadata(baseDir, type)
290 290
291 basename = metadata.get('general', 'basename') 291 basename = metadata.get('general', 'basename')
292 localeConfig = readLocaleConfig(baseDir, type, metadata, True) 292 localeConfig = readLocaleConfig(baseDir, type, metadata)
293 293
294 import buildtools.localeTools as localeTools 294 import buildtools.localeTools as localeTools
295 localeTools.setupTranslations(localeConfig, basename, key) 295 localeTools.setupTranslations(localeConfig, basename, key)
296 296
297 297
298 def updateTranslationMaster(baseDir, scriptName, opts, args, type): 298 def updateTranslationMaster(baseDir, scriptName, opts, args, type):
299 if len(args) < 1: 299 if len(args) < 1:
300 print 'Project key is required to update translation master files.' 300 print 'Project key is required to update translation master files.'
301 usage(scriptName, type, 'translate') 301 usage(scriptName, type, 'translate')
302 return 302 return
(...skipping 19 matching lines...) Expand all
322 print 'Project key is required to upload existing translations.' 322 print 'Project key is required to upload existing translations.'
323 usage(scriptName, type, 'uploadtrans') 323 usage(scriptName, type, 'uploadtrans')
324 return 324 return
325 325
326 key = args[0] 326 key = args[0]
327 327
328 from buildtools.packager import readMetadata 328 from buildtools.packager import readMetadata
329 metadata = readMetadata(baseDir, type) 329 metadata = readMetadata(baseDir, type)
330 330
331 basename = metadata.get('general', 'basename') 331 basename = metadata.get('general', 'basename')
332 localeConfig = readLocaleConfig(baseDir, type, metadata, True) 332 localeConfig = readLocaleConfig(baseDir, type, metadata)
333 333
334 import buildtools.localeTools as localeTools 334 import buildtools.localeTools as localeTools
335 for locale, localeDir in localeConfig['locales'].iteritems(): 335 for locale, localeDir in localeConfig['locales'].iteritems():
336 if locale != localeConfig['default_locale']: 336 if locale != localeConfig['default_locale']:
337 localeTools.uploadTranslations(localeConfig, metadata, localeDir, locale, 337 localeTools.uploadTranslations(localeConfig, metadata, localeDir, locale,
338 basename, key) 338 basename, key)
339 339
340 340
341 def getTranslations(baseDir, scriptName, opts, args, type): 341 def getTranslations(baseDir, scriptName, opts, args, type):
342 if len(args) < 1: 342 if len(args) < 1:
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 if option in ('-h', '--help'): 595 if option in ('-h', '--help'):
596 usage(scriptName, type, command) 596 usage(scriptName, type, command)
597 sys.exit() 597 sys.exit()
598 commands[command](baseDir, scriptName, opts, args, type) 598 commands[command](baseDir, scriptName, opts, args, type)
599 else: 599 else:
600 print 'Command %s is not supported for this application type' % command 600 print 'Command %s is not supported for this application type' % command
601 usage(scriptName, type) 601 usage(scriptName, type)
602 else: 602 else:
603 print 'Command %s is unrecognized' % command 603 print 'Command %s is unrecognized' % command
604 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