Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(714)

Side by Side Diff: recipe_engine/autoroll.py

Issue 2845873002: [recipes.py] move autoroll arg parsing to its module (Closed)
Patch Set: rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | recipes.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 # Copyright 2016 The LUCI Authors. All rights reserved. 1 # Copyright 2016 The LUCI Authors. All rights reserved.
2 # Use of this source code is governed under the Apache License, Version 2.0 2 # Use of this source code is governed under the Apache License, Version 2.0
3 # that can be found in the LICENSE file. 3 # that can be found in the LICENSE file.
4 4
5 from __future__ import print_function 5 from __future__ import print_function
6 6
7 import copy 7 import copy
8 import json 8 import json
9 import logging 9 import logging
10 import os 10 import os
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 'roll_details': roll_details, 260 'roll_details': roll_details,
261 'picked_roll_details': picked_roll_details, 261 'picked_roll_details': picked_roll_details,
262 'rejected_candidates_count': len(rejected_candidates), 262 'rejected_candidates_count': len(rejected_candidates),
263 } 263 }
264 if verbose_json: 264 if verbose_json:
265 ret['rejected_candidate_specs'] = [ 265 ret['rejected_candidate_specs'] = [
266 package_io.dump_obj(c.package_pb) for c in rejected_candidates] 266 package_io.dump_obj(c.package_pb) for c in rejected_candidates]
267 return ret 267 return ret
268 268
269 269
270 def main(args, repo_root, config_file): 270 def add_subparser(parser):
271 autoroll_p = parser.add_parser(
272 'autoroll',
273 help='Roll dependencies of a recipe package forward (implies fetch)')
274 autoroll_p.add_argument(
275 '--output-json',
276 type=os.path.abspath,
277 help='A json file to output information about the roll to.')
278 autoroll_p.add_argument(
279 '--verbose-json',
280 action='store_true',
281 help=('Emit even more data in the output-json file. '
282 'Requires --output-json.'))
283
284 def postprocess_func(parser, args):
285 if args.verbose_json and not args.output_json:
286 parser.error('--verbose-json passed without --output-json')
287
288 autoroll_p.set_defaults(
289 command='autoroll', func=main, postprocess_func=postprocess_func)
290
291
292 def main(_package_deps, args):
293 config_file = args.package
294 repo_root = package.InfraRepoConfig().from_recipes_cfg(config_file.path)
295
271 package_pb = config_file.read() 296 package_pb = config_file.read()
272 297
273 context = package.PackageContext.from_package_pb( 298 context = package.PackageContext.from_package_pb(
274 repo_root, package_pb, allow_fetch=not args.no_fetch) 299 repo_root, package_pb, allow_fetch=not args.no_fetch)
275 package_spec = package.PackageSpec.from_package_pb(context, package_pb) 300 package_spec = package.PackageSpec.from_package_pb(context, package_pb)
276 for repo_spec in package_spec.deps.values(): 301 for repo_spec in package_spec.deps.values():
277 repo_spec.fetch() 302 repo_spec.fetch()
278 303
279 repo_cfg_block = extract_repo_cfg_block(context) 304 repo_cfg_block = extract_repo_cfg_block(context)
280 305
281 results = {} 306 results = {}
282 try: 307 try:
283 results = test_rolls( 308 results = test_rolls(
284 repo_cfg_block, config_file, context, package_spec, args.verbose_json) 309 repo_cfg_block, config_file, context, package_spec, args.verbose_json)
285 finally: 310 finally:
286 if not results.get('success'): 311 if not results.get('success'):
287 # Restore initial state. Since we could be running simulation tests 312 # Restore initial state. Since we could be running simulation tests
288 # on other revisions, re-run them now as well. 313 # on other revisions, re-run them now as well.
289 write_spec_to_disk(context, repo_cfg_block, config_file, package_pb) 314 write_spec_to_disk(context, repo_cfg_block, config_file, package_pb)
290 run_simulation_test(repo_root, package_spec.recipes_path, ['train']) 315 run_simulation_test(repo_root, package_spec.recipes_path, ['train'])
291 316
292 if args.output_json: 317 if args.output_json:
293 with open(args.output_json, 'w') as f: 318 with open(args.output_json, 'w') as f:
294 json.dump(results, f, sort_keys=True, indent=2) 319 json.dump(results, f, sort_keys=True, indent=2)
295 320
296 return 0 321 return 0
OLDNEW
« no previous file with comments | « no previous file | recipes.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698