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

Side by Side Diff: build.py

Issue 29611593: Issue 5996 - Release consistent versions across WebExtensions (Closed) Base URL: https://codereview.adblockplus.org/29609559/
Patch Set: Created Nov. 17, 2017, 3:09 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 | localeTools.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # This Source Code Form is subject to the terms of the Mozilla Public 1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this 2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 4
5 import argparse 5 import argparse
6 import logging 6 import logging
7 import os 7 import os
8 import re 8 import re
9 import shutil 9 import shutil
10 import subprocess 10 import subprocess
11 import sys 11 import sys
12 from functools import partial 12 from functools import partial
13 from StringIO import StringIO 13 from StringIO import StringIO
14 from zipfile import ZipFile 14 from zipfile import ZipFile
15 from buildtools.localeTools import read_locale_config
15 16
16 KNOWN_PLATFORMS = {'chrome', 'gecko', 'edge', 'generic'} 17 KNOWN_PLATFORMS = {'chrome', 'gecko', 'edge', 'generic'}
17 18
18 MAIN_PARSER = argparse.ArgumentParser( 19 MAIN_PARSER = argparse.ArgumentParser(
19 description=__doc__, 20 description=__doc__,
20 formatter_class=argparse.RawDescriptionHelpFormatter) 21 formatter_class=argparse.RawDescriptionHelpFormatter)
21 22
22 SUB_PARSERS = MAIN_PARSER.add_subparsers(title='Commands', dest='action', 23 SUB_PARSERS = MAIN_PARSER.add_subparsers(title='Commands', dest='action',
23 metavar='[command]') 24 metavar='[command]')
24 25
25 ALL_COMMANDS = [] 26 ALL_COMMANDS = []
26 27
27 28
28 def make_argument(*args, **kwargs): 29 def make_argument(*args, **kwargs):
29 def _make_argument(*args, **kwargs): 30 def _make_argument(*args, **kwargs):
30 parser = kwargs.pop('parser') 31 parser = kwargs.pop('parser')
31 parser.add_argument(*args, **kwargs) 32 parser.add_argument(*args, **kwargs)
32 33
33 return partial(_make_argument, *args, **kwargs) 34 return partial(_make_argument, *args, **kwargs)
34 35
35 36
36 def argparse_command(valid_platforms=None, arguments=()): 37 def argparse_command(valid_platforms=None, multi_platform=False, arguments=()):
37 def wrapper(func): 38 def wrapper(func):
38 def func_wrapper(*args, **kwargs): 39 def func_wrapper(*args, **kwargs):
39 return func(*args, **kwargs) 40 return func(*args, **kwargs)
40 41
41 short_desc, long_desc = func.__doc__.split(os.linesep + os.linesep, 1) 42 short_desc, long_desc = func.__doc__.split(os.linesep + os.linesep, 1)
42 43
43 ALL_COMMANDS.append({ 44 ALL_COMMANDS.append({
44 'name': func.__name__, 45 'name': func.__name__,
45 'description': long_desc, 46 'description': long_desc,
46 'help_text': short_desc, 47 'help_text': short_desc,
47 'valid_platforms': valid_platforms or KNOWN_PLATFORMS, 48 'valid_platforms': valid_platforms or KNOWN_PLATFORMS,
49 'multi_platform': multi_platform,
48 'function': func, 50 'function': func,
49 'arguments': arguments, 51 'arguments': arguments,
50 }) 52 })
51 return func_wrapper 53 return func_wrapper
52
53 return wrapper 54 return wrapper
54 55
55 56
56 def make_subcommand(name, description, help_text, function, arguments): 57 def make_subcommand(name, description, help_text, function, arguments):
57 new_parser = SUB_PARSERS.add_parser( 58 new_parser = SUB_PARSERS.add_parser(
58 name, description=description, help=help_text, 59 name, description=description, help=help_text,
59 formatter_class=argparse.RawDescriptionHelpFormatter, 60 formatter_class=argparse.RawDescriptionHelpFormatter,
60 ) 61 )
61 62
62 for argument in arguments: 63 for argument in arguments:
(...skipping 23 matching lines...) Expand all
86 types.add(p) 87 types.add(p)
87 88
88 if len(types) == 0: 89 if len(types) == 0:
89 logging.error('No metadata file found in this repository. Expecting ' 90 logging.error('No metadata file found in this repository. Expecting '
90 'one or more of {} to be present.'.format( 91 'one or more of {} to be present.'.format(
91 ', '.join('metadata.' + p for p in KNOWN_PLATFORMS))) 92 ', '.join('metadata.' + p for p in KNOWN_PLATFORMS)))
92 build_available_subcommands._result = False 93 build_available_subcommands._result = False
93 return False 94 return False
94 95
95 for command_params in ALL_COMMANDS: 96 for command_params in ALL_COMMANDS:
97 multi_platform = command_params.pop('multi_platform')
96 platforms = types.intersection(command_params.pop('valid_platforms')) 98 platforms = types.intersection(command_params.pop('valid_platforms'))
97 if len(platforms) > 1: 99 if len(platforms) > 1:
100 if multi_platform:
101 help_text = ('Multiple types may be specifed (each preceded '
102 'by -t/--type)')
103 action = 'append'
104 else:
105 help_text = None
106 action = 'store'
107
98 command_params['arguments'] += ( 108 command_params['arguments'] += (
99 make_argument('-t', '--type', dest='platform', required=True, 109 make_argument('-t', '--type', dest='platform', required=True,
100 choices=platforms), 110 choices=platforms, action=action,
111 help=help_text),
101 ) 112 )
102 make_subcommand(**command_params) 113 make_subcommand(**command_params)
103 elif len(platforms) == 1: 114 elif len(platforms) == 1:
104 sub_parser = make_subcommand(**command_params) 115 sub_parser = make_subcommand(**command_params)
105 sub_parser.set_defaults(platform=platforms.pop()) 116 sub_parser.set_defaults(platform=platforms.pop())
106 117
107 build_available_subcommands._result = True 118 build_available_subcommands._result = True
108 return True 119 return True
109 120
110 121
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 from buildtools.packager import getDevEnvPath 183 from buildtools.packager import getDevEnvPath
173 devenv_dir = getDevEnvPath(base_dir, platform) 184 devenv_dir = getDevEnvPath(base_dir, platform)
174 185
175 shutil.rmtree(devenv_dir, ignore_errors=True) 186 shutil.rmtree(devenv_dir, ignore_errors=True)
176 187
177 file.seek(0) 188 file.seek(0)
178 with ZipFile(file, 'r') as zip_file: 189 with ZipFile(file, 'r') as zip_file:
179 zip_file.extractall(devenv_dir) 190 zip_file.extractall(devenv_dir)
180 191
181 192
182 def read_locale_config(base_dir, platform, metadata):
183 if platform != 'generic':
184 import buildtools.packagerChrome as packager
185 locale_dir = os.path.join(base_dir, '_locales')
186 locale_config = {
187 'default_locale': packager.defaultLocale,
188 }
189 else:
190 locale_dir = os.path.join(
191 base_dir, *metadata.get('locales', 'base_path').split('/')
192 )
193 locale_config = {
194 'default_locale': metadata.get('locales', 'default_locale')
195 }
196
197 locale_config['base_path'] = locale_dir
198
199 locales = [(locale.replace('_', '-'), os.path.join(locale_dir, locale))
200 for locale in os.listdir(locale_dir)]
201 locale_config['locales'] = dict(locales)
202
203 return locale_config
204
205
206 project_key_argument = make_argument( 193 project_key_argument = make_argument(
207 'project_key', help='The crowdin project key.' 194 'project_key', help='The crowdin project key.'
208 ) 195 )
209 196
210 197
211 @argparse_command( 198 @argparse_command(
212 arguments=(project_key_argument, ) 199 arguments=(project_key_argument, )
213 ) 200 )
214 def setuptrans(base_dir, project_key, platform, **kwargs): 201 def setuptrans(base_dir, project_key, platform, **kwargs):
215 """ 202 """
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 318
332 319
333 def valid_version_format(value): 320 def valid_version_format(value):
334 if re.search(r'[^\d\.]', value): 321 if re.search(r'[^\d\.]', value):
335 raise argparse.ArgumentTypeError('Wrong version number format') 322 raise argparse.ArgumentTypeError('Wrong version number format')
336 323
337 return value 324 return value
338 325
339 326
340 @argparse_command( 327 @argparse_command(
341 valid_platforms={'chrome', 'edge'}, 328 valid_platforms={'chrome', 'gecko', 'edge'}, multi_platform=True,
342 arguments=( 329 arguments=(
343 make_argument( 330 make_argument(
344 '-k', '--key', dest='key_file', 331 '-k', '--key', dest='key_file',
345 help=('File containing private key and certificates required to ' 332 help=('File containing private key and certificates required to '
346 'sign the release.')), 333 'sign the release.')),
347 make_argument( 334 make_argument(
348 '-d', '--downloads-repository', dest='downloads_repository', 335 '-d', '--downloads-repository', dest='downloads_repository',
349 help=('Directory containing downloads repository (if omitted ' 336 help=('Directory containing downloads repository (if omitted '
350 '../downloads is assumed)')), 337 '../downloads is assumed)')),
351 make_argument( 338 make_argument(
352 'version', help='Version number of the release', 339 'version', help='Version number of the release',
353 type=valid_version_format) 340 type=valid_version_format)
354 ) 341 )
355 ) 342 )
356 def release(base_dir, downloads_repository, key_file, platform, version, 343 def release(base_dir, downloads_repository, key_file, platform, version,
357 **kwargs): 344 **kwargs):
358 """ 345 """
359 Run release automation. 346 Run release automation.
360 347
361 Note: If you are not the project owner then you probably don't want to run 348 Note: If you are not the project owner then you probably don't want to run
362 this! 349 this!
363 350
364 Run release automation: create downloads for the new version, tag source 351 Run release automation: create downloads for the new version, tag source
365 code repository as well as downloads and buildtools repository. 352 code repository as well as downloads and buildtools repository.
366 """ 353 """
367 if downloads_repository is None: 354 if downloads_repository is None:
368 downloads_repository = os.path.join(base_dir, os.pardir, 'downloads') 355 downloads_repository = os.path.join(base_dir, os.pardir, 'downloads')
369 356
370 if platform == 'chrome' and key_file is None: 357 if 'chrome' in platform and key_file is None:
371 logging.error('You must specify a key file for this release') 358 logging.error('You must specify a key file for this release')
372 return 359 return
373 360
374 import buildtools.releaseAutomation as releaseAutomation 361 import buildtools.releaseAutomation as releaseAutomation
375 releaseAutomation.run(base_dir, platform, version, key_file, 362 releaseAutomation.run(base_dir, platform, version, key_file,
376 downloads_repository) 363 downloads_repository)
377 364
378 365
379 @argparse_command(valid_platforms={'chrome'}) 366 @argparse_command(valid_platforms={'chrome'})
380 def updatepsl(base_dir, **kwargs): 367 def updatepsl(base_dir, **kwargs):
(...skipping 10 matching lines...) Expand all
391 if build_available_subcommands(base_dir): 378 if build_available_subcommands(base_dir):
392 MAIN_PARSER.set_defaults(base_dir=base_dir) 379 MAIN_PARSER.set_defaults(base_dir=base_dir)
393 380
394 # If no args are provided, this module is run directly from the command 381 # If no args are provided, this module is run directly from the command
395 # line. argparse will take care of consuming sys.argv. 382 # line. argparse will take care of consuming sys.argv.
396 arguments = MAIN_PARSER.parse_args(args if len(args) > 0 else None) 383 arguments = MAIN_PARSER.parse_args(args if len(args) > 0 else None)
397 384
398 function = arguments.function 385 function = arguments.function
399 del arguments.function 386 del arguments.function
400 function(**vars(arguments)) 387 function(**vars(arguments))
OLDNEW
« no previous file with comments | « no previous file | localeTools.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld