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

Side by Side Diff: build.py

Issue 29756673: Noissue - Adapt best practices for trailing commas (buildtools) (Closed)
Patch Set: Created April 19, 2018, 12:58 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 | chainedconfigparser.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
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 '-b', '--build-num', dest='build_num', 129 '-b', '--build-num', dest='build_num',
130 help='Use given build number (if omitted the build number will ' 130 help='Use given build number (if omitted the build number will '
131 'be retrieved from Mercurial)'), 131 'be retrieved from Mercurial)'),
132 make_argument( 132 make_argument(
133 '-k', '--key', dest='key_file', 133 '-k', '--key', dest='key_file',
134 help='File containing private key and certificates required to ' 134 help='File containing private key and certificates required to '
135 'sign the package'), 135 'sign the package'),
136 make_argument( 136 make_argument(
137 '-r', '--release', action='store_true', 137 '-r', '--release', action='store_true',
138 help='Create a release build'), 138 help='Create a release build'),
139 make_argument('output_file', nargs='?') 139 make_argument('output_file', nargs='?'),
140 ) 140 ),
141 ) 141 )
142 def build(base_dir, build_num, key_file, release, output_file, platform, 142 def build(base_dir, build_num, key_file, release, output_file, platform,
143 **kwargs): 143 **kwargs):
144 """ 144 """
145 Create a build. 145 Create a build.
146 146
147 Creates an extension build with given file name. If output_file is missing 147 Creates an extension build with given file name. If output_file is missing
148 a default name will be chosen. 148 a default name will be chosen.
149 """ 149 """
150 kwargs = {} 150 kwargs = {}
151 if platform == 'edge': 151 if platform == 'edge':
152 import buildtools.packagerEdge as packager 152 import buildtools.packagerEdge as packager
153 else: 153 else:
154 import buildtools.packagerChrome as packager 154 import buildtools.packagerChrome as packager
155 155
156 kwargs['keyFile'] = key_file 156 kwargs['keyFile'] = key_file
157 kwargs['outFile'] = output_file 157 kwargs['outFile'] = output_file
158 kwargs['releaseBuild'] = release 158 kwargs['releaseBuild'] = release
159 kwargs['buildNum'] = build_num 159 kwargs['buildNum'] = build_num
160 160
161 packager.createBuild(base_dir, type=platform, **kwargs) 161 packager.createBuild(base_dir, type=platform, **kwargs)
162 162
163 163
164 @argparse_command( 164 @argparse_command(
165 valid_platforms={'chrome', 'gecko', 'edge'} 165 valid_platforms={'chrome', 'gecko', 'edge'},
166 ) 166 )
167 def devenv(base_dir, platform, **kwargs): 167 def devenv(base_dir, platform, **kwargs):
168 """ 168 """
169 Set up a development environment. 169 Set up a development environment.
170 170
171 Will set up or update the devenv folder as an unpacked extension folder ' 171 Will set up or update the devenv folder as an unpacked extension folder '
172 for development. 172 for development.
173 """ 173 """
174 if platform == 'edge': 174 if platform == 'edge':
175 import buildtools.packagerEdge as packager 175 import buildtools.packagerEdge as packager
176 else: 176 else:
177 import buildtools.packagerChrome as packager 177 import buildtools.packagerChrome as packager
178 178
179 file = StringIO() 179 file = StringIO()
180 packager.createBuild(base_dir, type=platform, outFile=file, devenv=True, 180 packager.createBuild(base_dir, type=platform, outFile=file, devenv=True,
181 releaseBuild=True) 181 releaseBuild=True)
182 182
183 from buildtools.packager import getDevEnvPath 183 from buildtools.packager import getDevEnvPath
184 devenv_dir = getDevEnvPath(base_dir, platform) 184 devenv_dir = getDevEnvPath(base_dir, platform)
185 185
186 shutil.rmtree(devenv_dir, ignore_errors=True) 186 shutil.rmtree(devenv_dir, ignore_errors=True)
187 187
188 file.seek(0) 188 file.seek(0)
189 with ZipFile(file, 'r') as zip_file: 189 with ZipFile(file, 'r') as zip_file:
190 zip_file.extractall(devenv_dir) 190 zip_file.extractall(devenv_dir)
191 191
192 192
193 project_key_argument = make_argument( 193 project_key_argument = make_argument(
194 'project_key', help='The crowdin project key.' 194 'project_key', help='The crowdin project key.',
195 ) 195 )
196 196
197 197
198 @argparse_command( 198 @argparse_command(
199 arguments=(project_key_argument, ) 199 arguments=(project_key_argument, ),
200 ) 200 )
201 def setuptrans(base_dir, project_key, platform, **kwargs): 201 def setuptrans(base_dir, project_key, platform, **kwargs):
202 """ 202 """
203 Set up translation languages. 203 Set up translation languages.
204 204
205 Set up translation languages for the project on crowdin.com. 205 Set up translation languages for the project on crowdin.com.
206 """ 206 """
207 from buildtools.packager import readMetadata 207 from buildtools.packager import readMetadata
208 metadata = readMetadata(base_dir, platform) 208 metadata = readMetadata(base_dir, platform)
209 209
210 basename = metadata.get('general', 'basename') 210 basename = metadata.get('general', 'basename')
211 locale_config = read_locale_config(base_dir, platform, metadata) 211 locale_config = read_locale_config(base_dir, platform, metadata)
212 212
213 import buildtools.localeTools as localeTools 213 import buildtools.localeTools as localeTools
214 localeTools.setupTranslations(locale_config, basename, project_key) 214 localeTools.setupTranslations(locale_config, basename, project_key)
215 215
216 216
217 @argparse_command( 217 @argparse_command(
218 arguments=(project_key_argument, ) 218 arguments=(project_key_argument, ),
219 ) 219 )
220 def translate(base_dir, project_key, platform, **kwargs): 220 def translate(base_dir, project_key, platform, **kwargs):
221 """ 221 """
222 Update translation master files. 222 Update translation master files.
223 223
224 Update the translation master files in the project on crowdin.com. 224 Update the translation master files in the project on crowdin.com.
225 """ 225 """
226 from buildtools.packager import readMetadata 226 from buildtools.packager import readMetadata
227 metadata = readMetadata(base_dir, platform) 227 metadata = readMetadata(base_dir, platform)
228 228
229 basename = metadata.get('general', 'basename') 229 basename = metadata.get('general', 'basename')
230 locale_config = read_locale_config(base_dir, platform, metadata) 230 locale_config = read_locale_config(base_dir, platform, metadata)
231 231
232 default_locale_dir = os.path.join(locale_config['base_path'], 232 default_locale_dir = os.path.join(locale_config['base_path'],
233 locale_config['default_locale']) 233 locale_config['default_locale'])
234 234
235 import buildtools.localeTools as localeTools 235 import buildtools.localeTools as localeTools
236 localeTools.updateTranslationMaster(locale_config, metadata, 236 localeTools.updateTranslationMaster(locale_config, metadata,
237 default_locale_dir, basename, 237 default_locale_dir, basename,
238 project_key) 238 project_key)
239 239
240 240
241 @argparse_command( 241 @argparse_command(
242 arguments=(project_key_argument, ) 242 arguments=(project_key_argument, ),
243 ) 243 )
244 def uploadtrans(base_dir, project_key, platform, **kwargs): 244 def uploadtrans(base_dir, project_key, platform, **kwargs):
245 """ 245 """
246 Upload existing translations. 246 Upload existing translations.
247 247
248 Upload already existing translations to the project on crowdin.com. 248 Upload already existing translations to the project on crowdin.com.
249 """ 249 """
250 from buildtools.packager import readMetadata 250 from buildtools.packager import readMetadata
251 metadata = readMetadata(base_dir, platform) 251 metadata = readMetadata(base_dir, platform)
252 252
253 basename = metadata.get('general', 'basename') 253 basename = metadata.get('general', 'basename')
254 locale_config = read_locale_config(base_dir, platform, metadata) 254 locale_config = read_locale_config(base_dir, platform, metadata)
255 255
256 import buildtools.localeTools as localeTools 256 import buildtools.localeTools as localeTools
257 for locale, locale_dir in locale_config['locales'].iteritems(): 257 for locale, locale_dir in locale_config['locales'].iteritems():
258 if locale != locale_config['default_locale'].replace('_', '-'): 258 if locale != locale_config['default_locale'].replace('_', '-'):
259 localeTools.uploadTranslations(locale_config, metadata, locale_dir, 259 localeTools.uploadTranslations(locale_config, metadata, locale_dir,
260 locale, basename, project_key) 260 locale, basename, project_key)
261 261
262 262
263 @argparse_command( 263 @argparse_command(
264 arguments=(project_key_argument, ) 264 arguments=(project_key_argument, ),
265 ) 265 )
266 def gettranslations(base_dir, project_key, platform, **kwargs): 266 def gettranslations(base_dir, project_key, platform, **kwargs):
267 """ 267 """
268 Download translation updates. 268 Download translation updates.
269 269
270 Download updated translations from crowdin.com. 270 Download updated translations from crowdin.com.
271 """ 271 """
272 from buildtools.packager import readMetadata 272 from buildtools.packager import readMetadata
273 metadata = readMetadata(base_dir, platform) 273 metadata = readMetadata(base_dir, platform)
274 274
275 basename = metadata.get('general', 'basename') 275 basename = metadata.get('general', 'basename')
276 locale_config = read_locale_config(base_dir, platform, metadata) 276 locale_config = read_locale_config(base_dir, platform, metadata)
277 277
278 import buildtools.localeTools as localeTools 278 import buildtools.localeTools as localeTools
279 localeTools.getTranslations(locale_config, basename, project_key) 279 localeTools.getTranslations(locale_config, basename, project_key)
280 280
281 281
282 @argparse_command( 282 @argparse_command(
283 valid_platforms={'chrome'}, 283 valid_platforms={'chrome'},
284 arguments=( 284 arguments=(
285 make_argument('target_dir'), 285 make_argument('target_dir'),
286 make_argument('-q', '--quiet', help='Suppress JsDoc output', 286 make_argument('-q', '--quiet', help='Suppress JsDoc output',
287 action='store_true', default=False), 287 action='store_true', default=False),
288 ) 288 ),
289 ) 289 )
290 def docs(base_dir, target_dir, quiet, platform, **kwargs): 290 def docs(base_dir, target_dir, quiet, platform, **kwargs):
291 """ 291 """
292 Generate documentation (requires node.js). 292 Generate documentation (requires node.js).
293 293
294 Generate documentation files and write them into the specified directory. 294 Generate documentation files and write them into the specified directory.
295 """ 295 """
296 source_dir = os.path.join(base_dir, 'lib') 296 source_dir = os.path.join(base_dir, 'lib')
297 297
298 # JSDoc struggles wih huge objects: 298 # JSDoc struggles wih huge objects:
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 make_argument( 331 make_argument(
332 '-k', '--key', dest='key_file', 332 '-k', '--key', dest='key_file',
333 help='File containing private key and certificates required to ' 333 help='File containing private key and certificates required to '
334 'sign the release.'), 334 'sign the release.'),
335 make_argument( 335 make_argument(
336 '-d', '--downloads-repository', dest='downloads_repository', 336 '-d', '--downloads-repository', dest='downloads_repository',
337 help='Directory containing downloads repository (if omitted ' 337 help='Directory containing downloads repository (if omitted '
338 '../downloads is assumed)'), 338 '../downloads is assumed)'),
339 make_argument( 339 make_argument(
340 'version', help='Version number of the release', 340 'version', help='Version number of the release',
341 type=valid_version_format) 341 type=valid_version_format),
342 ) 342 ),
343 ) 343 )
344 def release(base_dir, downloads_repository, key_file, platform, version, 344 def release(base_dir, downloads_repository, key_file, platform, version,
345 **kwargs): 345 **kwargs):
346 """ 346 """
347 Run release automation. 347 Run release automation.
348 348
349 Note: If you are not the project owner then you probably don't want to run 349 Note: If you are not the project owner then you probably don't want to run
350 this! 350 this!
351 351
352 Run release automation: create downloads for the new version, tag source 352 Run release automation: create downloads for the new version, tag source
(...skipping 26 matching lines...) Expand all
379 if build_available_subcommands(base_dir): 379 if build_available_subcommands(base_dir):
380 MAIN_PARSER.set_defaults(base_dir=base_dir) 380 MAIN_PARSER.set_defaults(base_dir=base_dir)
381 381
382 # If no args are provided, this module is run directly from the command 382 # If no args are provided, this module is run directly from the command
383 # line. argparse will take care of consuming sys.argv. 383 # line. argparse will take care of consuming sys.argv.
384 arguments = MAIN_PARSER.parse_args(args if len(args) > 0 else None) 384 arguments = MAIN_PARSER.parse_args(args if len(args) > 0 else None)
385 385
386 function = arguments.function 386 function = arguments.function
387 del arguments.function 387 del arguments.function
388 function(**vars(arguments)) 388 function(**vars(arguments))
OLDNEW
« no previous file with comments | « no previous file | chainedconfigparser.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld