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

Side by Side Diff: recipes.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 | « recipe_engine/autoroll.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2015 The LUCI Authors. All rights reserved. 2 # Copyright 2015 The LUCI Authors. All rights reserved.
3 # Use of this source code is governed under the Apache License, Version 2.0 3 # Use of this source code is governed under the Apache License, Version 2.0
4 # that can be found in the LICENSE file. 4 # that can be found in the LICENSE file.
5 5
6 """Tool to interact with recipe repositories. 6 """Tool to interact with recipe repositories.
7 7
8 This tool operates on the nearest ancestor directory containing an 8 This tool operates on the nearest ancestor directory containing an
9 infra/config/recipes.cfg. 9 infra/config/recipes.cfg.
10 """ 10 """
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 return handle_recipe_return( 219 return handle_recipe_return(
220 ret, args.output_result_json, stream_engine, engine_flags) 220 ret, args.output_result_json, stream_engine, engine_flags)
221 221
222 222
223 def remote(args): 223 def remote(args):
224 from recipe_engine import remote 224 from recipe_engine import remote
225 225
226 return remote.main(args) 226 return remote.main(args)
227 227
228 228
229 def autoroll(repo_root, config_file, args):
230 from recipe_engine import autoroll
231
232 if args.verbose_json and not args.output_json:
233 print >> sys.stderr, '--verbose-json passed without --output-json'
234 return 1
235
236 return autoroll.main(args, repo_root, config_file)
237
238
239 class ProjectOverrideAction(argparse.Action): 229 class ProjectOverrideAction(argparse.Action):
240 def __call__(self, parser, namespace, values, option_string=None): 230 def __call__(self, parser, namespace, values, option_string=None):
241 p = values.split('=', 2) 231 p = values.split('=', 2)
242 if len(p) != 2: 232 if len(p) != 2:
243 raise ValueError('Override must have the form: repo=path') 233 raise ValueError('Override must have the form: repo=path')
244 project_id, path = p 234 project_id, path = p
245 235
246 v = getattr(namespace, self.dest, None) 236 v = getattr(namespace, self.dest, None)
247 if v is None: 237 if v is None:
248 v = {} 238 v = {}
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 373
384 return post_process_args 374 return post_process_args
385 375
386 376
387 def main(): 377 def main():
388 parser = argparse.ArgumentParser( 378 parser = argparse.ArgumentParser(
389 description='Interact with the recipe system.') 379 description='Interact with the recipe system.')
390 380
391 common_postprocess_func = add_common_args(parser) 381 common_postprocess_func = add_common_args(parser)
392 382
393 from recipe_engine import fetch, lint_test, bundle, depgraph 383 from recipe_engine import fetch, lint_test, bundle, depgraph, autoroll
394 to_add = [fetch, lint_test, bundle, depgraph] 384 to_add = [fetch, lint_test, bundle, depgraph, autoroll]
395 385
396 subp = parser.add_subparsers() 386 subp = parser.add_subparsers()
397 for module in to_add: 387 for module in to_add:
398 module.add_subparser(subp) 388 module.add_subparser(subp)
399 389
400 test_p = subp.add_parser( 390 test_p = subp.add_parser(
401 'test', 391 'test',
402 description='Generate or check expectations by simulation') 392 description='Generate or check expectations by simulation')
403 test_p.set_defaults(command='test') 393 test_p.set_defaults(command='test')
404 test_p.add_argument('args', nargs=argparse.REMAINDER) 394 test_p.add_argument('args', nargs=argparse.REMAINDER)
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 type=os.path.abspath, 483 type=os.path.abspath,
494 help='The working directory of repo checkout') 484 help='The working directory of repo checkout')
495 remote_p.add_argument( 485 remote_p.add_argument(
496 '--use-gitiles', action='store_true', 486 '--use-gitiles', action='store_true',
497 help='Use Gitiles-specific way to fetch repo (potentially cheaper for ' 487 help='Use Gitiles-specific way to fetch repo (potentially cheaper for '
498 'large repos)') 488 'large repos)')
499 remote_p.add_argument( 489 remote_p.add_argument(
500 'remote_args', nargs='*', 490 'remote_args', nargs='*',
501 help='Arguments to pass to fetched repo\'s recipes.py') 491 help='Arguments to pass to fetched repo\'s recipes.py')
502 492
503 autoroll_p = subp.add_parser(
504 'autoroll',
505 help='Roll dependencies of a recipe package forward (implies fetch)')
506 autoroll_p.set_defaults(command='autoroll')
507 autoroll_p.add_argument(
508 '--output-json',
509 type=os.path.abspath,
510 help='A json file to output information about the roll to.')
511 autoroll_p.add_argument(
512 '--verbose-json',
513 action='store_true',
514 help=('Emit even more data in the output-json file. '
515 'Requires --output-json.'))
516 493
517 refs_p = subp.add_parser( 494 refs_p = subp.add_parser(
518 'refs', 495 'refs',
519 description='List places referencing given recipe module(s).') 496 description='List places referencing given recipe module(s).')
520 refs_p.set_defaults(command='refs') 497 refs_p.set_defaults(command='refs')
521 refs_p.add_argument('modules', nargs='+', help='Module(s) to query for') 498 refs_p.add_argument('modules', nargs='+', help='Module(s) to query for')
522 refs_p.add_argument('--transitive', action='store_true', 499 refs_p.add_argument('--transitive', action='store_true',
523 help='Compute transitive closure of the references') 500 help='Compute transitive closure of the references')
524 501
525 doc_kinds=('binarypb', 'jsonpb', 'textpb', 'markdown(github)', 502 doc_kinds=('binarypb', 'jsonpb', 'textpb', 'markdown(github)',
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 # an infra failure, rather than a test failure. 628 # an infra failure, rather than a test failure.
652 return 2 629 return 2
653 630
654 if hasattr(args, 'func'): 631 if hasattr(args, 'func'):
655 return args.func(package_deps, args) 632 return args.func(package_deps, args)
656 633
657 if args.command == 'test': 634 if args.command == 'test':
658 return test(config_file, package_deps, args) 635 return test(config_file, package_deps, args)
659 elif args.command == 'run': 636 elif args.command == 'run':
660 return run(config_file, package_deps, args) 637 return run(config_file, package_deps, args)
661 elif args.command == 'autoroll':
662 return autoroll(repo_root, config_file, args)
663 elif args.command == 'refs': 638 elif args.command == 'refs':
664 return refs(config_file, package_deps, args) 639 return refs(config_file, package_deps, args)
665 elif args.command == 'doc': 640 elif args.command == 'doc':
666 return doc(config_file, package_deps, args) 641 return doc(config_file, package_deps, args)
667 else: 642 else:
668 print """Dear sir or madam, 643 print """Dear sir or madam,
669 It has come to my attention that a quite impossible condition has come 644 It has come to my attention that a quite impossible condition has come
670 to pass in the specification you have issued a request for us to fulfill. 645 to pass in the specification you have issued a request for us to fulfill.
671 It is with a heavy heart that I inform you that, at the present juncture, 646 It is with a heavy heart that I inform you that, at the present juncture,
672 there is no conceivable next action to be taken upon your request, and as 647 there is no conceivable next action to be taken upon your request, and as
(...skipping 23 matching lines...) Expand all
696 671
697 if not isinstance(ret, int): 672 if not isinstance(ret, int):
698 if ret is None: 673 if ret is None:
699 ret = 0 674 ret = 0
700 else: 675 else:
701 print >> sys.stderr, ret 676 print >> sys.stderr, ret
702 ret = 1 677 ret = 1
703 sys.stdout.flush() 678 sys.stdout.flush()
704 sys.stderr.flush() 679 sys.stderr.flush()
705 os._exit(ret) 680 os._exit(ret)
OLDNEW
« no previous file with comments | « recipe_engine/autoroll.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698