OLD | NEW |
1 # Copyright 2016 The LUCI Authors. All rights reserved. | 1 # Copyright 2017 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 """Entry point for fully-annotated builds. | 5 """Entry point for fully-annotated builds. |
6 | 6 |
7 This script is part of the effort to move all builds to annotator-based | 7 This script is part of the effort to move all builds to annotator-based |
8 systems. Any builder configured to use the AnnotatorFactory.BaseFactory() | 8 systems. Any builder configured to use the AnnotatorFactory.BaseFactory() |
9 found in scripts/master/factory/annotator_factory.py executes a single | 9 found in scripts/master/factory/annotator_factory.py executes a single |
10 AddAnnotatedScript step. That step (found in annotator_commands.py) calls | 10 AddAnnotatedScript step. That step (found in annotator_commands.py) calls |
11 this script with the build- and factory-properties passed on the command | 11 this script with the build- and factory-properties passed on the command |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 except (ValueError, SyntaxError): | 461 except (ValueError, SyntaxError): |
462 pass # If a value couldn't be evaluated, keep the string version | 462 pass # If a value couldn't be evaluated, keep the string version |
463 return {key: val} | 463 return {key: val} |
464 | 464 |
465 def properties_type(value): | 465 def properties_type(value): |
466 obj = json.loads(value) | 466 obj = json.loads(value) |
467 if not isinstance(obj, dict): | 467 if not isinstance(obj, dict): |
468 raise argparse.ArgumentTypeError('must contain a JSON object, i.e. `{}`.') | 468 raise argparse.ArgumentTypeError('must contain a JSON object, i.e. `{}`.') |
469 return obj | 469 return obj |
470 | 470 |
| 471 helpstr='Run a recipe locally.' |
471 run_p = parser.add_parser( | 472 run_p = parser.add_parser( |
472 'run', | 473 'run', help=helpstr, description=helpstr) |
473 description='Run a recipe locally') | |
474 | 474 |
475 run_p.add_argument( | 475 run_p.add_argument( |
476 '--workdir', | 476 '--workdir', |
477 type=os.path.abspath, | 477 type=os.path.abspath, |
478 help='The working directory of recipe execution') | 478 help='The working directory of recipe execution') |
479 run_p.add_argument( | 479 run_p.add_argument( |
480 '--output-result-json', | 480 '--output-result-json', |
481 type=os.path.abspath, | 481 type=os.path.abspath, |
482 help='The file to write the JSON serialized returned value \ | 482 help=( |
483 of the recipe to') | 483 'The file to write the JSON serialized returned value ' |
| 484 ' of the recipe to')) |
484 run_p.add_argument( | 485 run_p.add_argument( |
485 '--timestamps', | 486 '--timestamps', |
486 action='store_true', | 487 action='store_true', |
487 help='If true, emit CURRENT_TIMESTAMP annotations. ' | 488 help=( |
488 'Default: false. ' | 489 'If true, emit CURRENT_TIMESTAMP annotations. ' |
489 'CURRENT_TIMESTAMP annotation has one parameter, current time in ' | 490 'Default: false. ' |
490 'Unix timestamp format. ' | 491 'CURRENT_TIMESTAMP annotation has one parameter, current time in ' |
491 'CURRENT_TIMESTAMP annotation will be printed at the beginning and ' | 492 'Unix timestamp format. ' |
492 'end of the annotation stream and also immediately before each ' | 493 'CURRENT_TIMESTAMP annotation will be printed at the beginning and ' |
493 'STEP_STARTED and STEP_CLOSED annotations.', | 494 'end of the annotation stream and also immediately before each ' |
494 ) | 495 'STEP_STARTED and STEP_CLOSED annotations.')) |
495 prop_group = run_p.add_mutually_exclusive_group() | 496 prop_group = run_p.add_mutually_exclusive_group() |
496 prop_group.add_argument( | 497 prop_group.add_argument( |
497 '--properties-file', | 498 '--properties-file', |
498 dest='properties', | 499 dest='properties', |
499 type=properties_file_type, | 500 type=properties_file_type, |
500 help=('A file containing a json blob of properties. ' | 501 help=( |
501 'Pass "-" to read from stdin')) | 502 'A file containing a json blob of properties. ' |
| 503 'Pass "-" to read from stdin')) |
502 prop_group.add_argument( | 504 prop_group.add_argument( |
503 '--properties', | 505 '--properties', |
504 type=properties_type, | 506 type=properties_type, |
505 help='A json string containing the properties') | 507 help='A json string containing the properties') |
506 | 508 |
507 run_p.add_argument( | 509 run_p.add_argument( |
508 'recipe', | 510 'recipe', |
509 help='The recipe to execute') | 511 help='The recipe to execute') |
510 run_p.add_argument( | 512 run_p.add_argument( |
511 'props', | 513 'props', |
512 nargs=argparse.REMAINDER, | 514 nargs=argparse.REMAINDER, |
513 type=parse_prop, | 515 type=parse_prop, |
514 help='A list of property pairs; e.g. mastername=chromium.linux ' | 516 help=( |
515 'issue=12345. The property value will be decoded as JSON, but if ' | 517 'A list of property pairs; e.g. mastername=chromium.linux ' |
516 'this decoding fails the value will be interpreted as a string.') | 518 'issue=12345. The property value will be decoded as JSON, but if ' |
| 519 'this decoding fails the value will be interpreted as a string.')) |
517 | 520 |
518 run_p.set_defaults(command='run', properties={}, func=main) | 521 run_p.set_defaults(command='run', properties={}, func=main) |
519 | 522 |
520 | 523 |
521 def handle_recipe_return(recipe_result, result_filename, stream_engine, | 524 def handle_recipe_return(recipe_result, result_filename, stream_engine, |
522 engine_flags): | 525 engine_flags): |
523 if engine_flags and engine_flags.use_result_proto: | 526 if engine_flags and engine_flags.use_result_proto: |
524 return new_handle_recipe_return( | 527 return new_handle_recipe_return( |
525 recipe_result, result_filename, stream_engine) | 528 recipe_result, result_filename, stream_engine) |
526 | 529 |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 ret = run_steps( | 719 ret = run_steps( |
717 properties, stream_engine, | 720 properties, stream_engine, |
718 step_runner.SubprocessStepRunner(stream_engine, engine_flags), | 721 step_runner.SubprocessStepRunner(stream_engine, engine_flags), |
719 universe_view, engine_flags=engine_flags, | 722 universe_view, engine_flags=engine_flags, |
720 emit_initial_properties=emit_initial_properties) | 723 emit_initial_properties=emit_initial_properties) |
721 finally: | 724 finally: |
722 os.chdir(old_cwd) | 725 os.chdir(old_cwd) |
723 | 726 |
724 return handle_recipe_return( | 727 return handle_recipe_return( |
725 ret, args.output_result_json, stream_engine, engine_flags) | 728 ret, args.output_result_json, stream_engine, engine_flags) |
OLD | NEW |