| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 | 2 |
| 3 """Tool to interact with recipe repositories. | 3 """Tool to interact with recipe repositories. |
| 4 | 4 |
| 5 This tool operates on the nearest ancestor directory containing an | 5 This tool operates on the nearest ancestor directory containing an |
| 6 infra/config/recipes.cfg. | 6 infra/config/recipes.cfg. |
| 7 """ | 7 """ |
| 8 | 8 |
| 9 import argparse | 9 import argparse |
| 10 import json | 10 import json |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 assert os.path.exists(args.package), ( | 24 assert os.path.exists(args.package), ( |
| 25 'Given recipes config file %s does not exist.' % args.package) | 25 'Given recipes config file %s does not exist.' % args.package) |
| 26 return ( | 26 return ( |
| 27 package.InfraRepoConfig().from_recipes_cfg(args.package), | 27 package.InfraRepoConfig().from_recipes_cfg(args.package), |
| 28 package.ProtoFile(args.package) | 28 package.ProtoFile(args.package) |
| 29 ) | 29 ) |
| 30 | 30 |
| 31 | 31 |
| 32 def simulation_test(package_deps, args): | 32 def simulation_test(package_deps, args): |
| 33 from recipe_engine import simulation_test | 33 from recipe_engine import simulation_test |
| 34 simulation_test.main(package_deps, args=json.loads(args.args)) | 34 from recipe_engine import loader |
| 35 |
| 36 _, config_file = get_package_config(args) |
| 37 universe = loader.RecipeUniverse(package_deps, config_file.path) |
| 38 |
| 39 simulation_test.main(universe, args=json.loads(args.args)) |
| 35 | 40 |
| 36 | 41 |
| 37 def lint(package_deps, args): | 42 def lint(package_deps, args): |
| 38 from recipe_engine import lint_test | 43 from recipe_engine import lint_test |
| 39 lint_test.main(package_deps, args.whitelist or []) | 44 lint_test.main(package_deps, args.whitelist or []) |
| 40 | 45 |
| 41 | 46 |
| 42 def handle_recipe_return(recipe_result, result_filename, stream): | 47 def handle_recipe_return(recipe_result, result_filename, stream): |
| 43 if 'recipe_result' in recipe_result.result: | 48 if 'recipe_result' in recipe_result.result: |
| 44 result_string = json.dumps( | 49 result_string = json.dumps( |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 elif args.properties_file: | 106 elif args.properties_file: |
| 102 properties = get_properties_from_file(args.properties_file) | 107 properties = get_properties_from_file(args.properties_file) |
| 103 else: | 108 else: |
| 104 properties = arg_properties | 109 properties = arg_properties |
| 105 | 110 |
| 106 properties['recipe'] = args.recipe | 111 properties['recipe'] = args.recipe |
| 107 | 112 |
| 108 os.environ['PYTHONUNBUFFERED'] = '1' | 113 os.environ['PYTHONUNBUFFERED'] = '1' |
| 109 os.environ['PYTHONIOENCODING'] = 'UTF-8' | 114 os.environ['PYTHONIOENCODING'] = 'UTF-8' |
| 110 | 115 |
| 111 universe = loader.RecipeUniverse(package_deps) | 116 _, config_file = get_package_config(args) |
| 117 universe = loader.RecipeUniverse(package_deps, config_file.path) |
| 112 | 118 |
| 113 workdir = (args.workdir or | 119 workdir = (args.workdir or |
| 114 os.path.join(os.path.dirname(os.path.realpath(__file__)), 'workdir')) | 120 os.path.join(os.path.dirname(os.path.realpath(__file__)), 'workdir')) |
| 115 logging.info('Using %s as work directory' % workdir) | 121 logging.info('Using %s as work directory' % workdir) |
| 116 if not os.path.exists(workdir): | 122 if not os.path.exists(workdir): |
| 117 os.makedirs(workdir) | 123 os.makedirs(workdir) |
| 118 | 124 |
| 119 old_cwd = os.getcwd() | 125 old_cwd = os.getcwd() |
| 120 os.chdir(workdir) | 126 os.chdir(workdir) |
| 121 stream = annotator.StructuredAnnotationStream() | 127 stream = annotator.StructuredAnnotationStream() |
| 122 | 128 |
| 123 try: | 129 try: |
| 124 ret = recipe_run.run_steps(properties, stream, universe=universe) | 130 ret = recipe_run.run_steps(properties, stream, universe=universe) |
| 125 | 131 |
| 126 finally: | 132 finally: |
| 127 os.chdir(old_cwd) | 133 os.chdir(old_cwd) |
| 128 | 134 |
| 129 return handle_recipe_return(ret, args.result_file, stream) | 135 return handle_recipe_return(ret, args.output_result_json, stream) |
| 130 | 136 |
| 131 | 137 |
| 132 def roll(args): | 138 def roll(args): |
| 133 from recipe_engine import package | 139 from recipe_engine import package |
| 134 repo_root, config_file = get_package_config(args) | 140 repo_root, config_file = get_package_config(args) |
| 135 context = package.PackageContext.from_proto_file(repo_root, config_file) | 141 context = package.PackageContext.from_proto_file(repo_root, config_file) |
| 136 package_spec = package.PackageSpec.load_proto(config_file) | 142 package_spec = package.PackageSpec.load_proto(config_file) |
| 137 | 143 |
| 138 for update in package_spec.iterate_consistent_updates(config_file, context): | 144 for update in package_spec.iterate_consistent_updates(config_file, context): |
| 139 config_file.write(update.spec.dump()) | 145 config_file.write(update.spec.dump()) |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 run_p.add_argument( | 262 run_p.add_argument( |
| 257 '--properties-file', | 263 '--properties-file', |
| 258 help='A file containing a json blob of properties') | 264 help='A file containing a json blob of properties') |
| 259 run_p.add_argument( | 265 run_p.add_argument( |
| 260 '--properties', | 266 '--properties', |
| 261 help='A json string containing the properties') | 267 help='A json string containing the properties') |
| 262 run_p.add_argument( | 268 run_p.add_argument( |
| 263 '--workdir', | 269 '--workdir', |
| 264 help='The working directory of recipe execution') | 270 help='The working directory of recipe execution') |
| 265 run_p.add_argument( | 271 run_p.add_argument( |
| 266 '--result-file', | 272 '--output-result-json', |
| 267 help='The file to write the JSON serialized returned value \ | 273 help='The file to write the JSON serialized returned value \ |
| 268 of the recipe to') | 274 of the recipe to') |
| 269 run_p.add_argument( | 275 run_p.add_argument( |
| 270 'recipe', | 276 'recipe', |
| 271 help='The recipe to execute') | 277 help='The recipe to execute') |
| 272 run_p.add_argument( | 278 run_p.add_argument( |
| 273 'props', nargs=argparse.REMAINDER, | 279 'props', nargs=argparse.REMAINDER, |
| 274 help='A list of property pairs; e.g. mastername=chromium.linux ' | 280 help='A list of property pairs; e.g. mastername=chromium.linux ' |
| 275 'issue=12345') | 281 'issue=12345') |
| 276 | 282 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 | 343 |
| 338 Warmly, | 344 Warmly, |
| 339 recipes.py | 345 recipes.py |
| 340 """ | 346 """ |
| 341 return 1 | 347 return 1 |
| 342 | 348 |
| 343 return 0 | 349 return 0 |
| 344 | 350 |
| 345 if __name__ == '__main__': | 351 if __name__ == '__main__': |
| 346 sys.exit(main()) | 352 sys.exit(main()) |
| OLD | NEW |