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( |
45 recipe_result.result['recipe_result'], indent=2) | 50 recipe_result.result['recipe_result'], indent=2) |
46 if result_filename: | 51 if result_filename: |
47 with open(result_filename, 'w') as f: | 52 with open(result_filename, 'w') as f: |
48 f.write(result_string) | 53 f.write(result_string) |
49 else: | 54 with stream.step('recipe result') as s: |
50 with stream.step('recipe result') as s: | 55 s.write_log_lines('result', [result_string]) |
51 s.write_log_lines('result', [result_string]) | |
52 | 56 |
53 if 'reason' in recipe_result.result: | 57 if 'reason' in recipe_result.result: |
54 with stream.step('recipe failure reason') as s: | 58 with stream.step('recipe failure reason') as s: |
55 s.write_log_lines( | 59 s.write_log_lines( |
56 'failure reason', | 60 'failure reason', |
57 [recipe_result.result['reason']]) | 61 [recipe_result.result['reason']]) |
58 return 1 | 62 return 1 |
59 elif 'status_code' in recipe_result.result: | 63 elif 'status_code' in recipe_result.result: |
60 return recipe_result.result['status_code'] | 64 return recipe_result.result['status_code'] |
61 else: | 65 else: |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 elif args.properties_file: | 98 elif args.properties_file: |
95 properties = get_properties_from_file(args.properties_file) | 99 properties = get_properties_from_file(args.properties_file) |
96 else: | 100 else: |
97 properties = arg_properties | 101 properties = arg_properties |
98 | 102 |
99 properties['recipe'] = args.recipe | 103 properties['recipe'] = args.recipe |
100 | 104 |
101 os.environ['PYTHONUNBUFFERED'] = '1' | 105 os.environ['PYTHONUNBUFFERED'] = '1' |
102 os.environ['PYTHONIOENCODING'] = 'UTF-8' | 106 os.environ['PYTHONIOENCODING'] = 'UTF-8' |
103 | 107 |
104 universe = loader.RecipeUniverse(package_deps) | 108 _, config_file = get_package_config(args) |
| 109 universe = loader.RecipeUniverse(package_deps, config_file.path) |
105 | 110 |
106 workdir = (args.workdir or | 111 workdir = (args.workdir or |
107 os.path.join(os.path.dirname(os.path.realpath(__file__)), 'workdir')) | 112 os.path.join(os.path.dirname(os.path.realpath(__file__)), 'workdir')) |
108 logging.info('Using %s as work directory' % workdir) | 113 logging.info('Using %s as work directory' % workdir) |
109 if not os.path.exists(workdir): | 114 if not os.path.exists(workdir): |
110 os.makedirs(workdir) | 115 os.makedirs(workdir) |
111 | 116 |
112 old_cwd = os.getcwd() | 117 old_cwd = os.getcwd() |
113 os.chdir(workdir) | 118 os.chdir(workdir) |
114 stream = annotator.StructuredAnnotationStream() | 119 stream = annotator.StructuredAnnotationStream() |
115 | 120 |
116 try: | 121 try: |
117 ret = recipe_run.run_steps(properties, stream, universe=universe) | 122 ret = recipe_run.run_steps(properties, stream, universe=universe) |
118 | |
119 finally: | 123 finally: |
120 os.chdir(old_cwd) | 124 os.chdir(old_cwd) |
121 | 125 |
122 return handle_recipe_return(ret, args.result_file, stream) | 126 return handle_recipe_return(ret, args.result_file, stream) |
123 | 127 |
124 | 128 |
125 def roll(args): | 129 def roll(args): |
126 from recipe_engine import package | 130 from recipe_engine import package |
127 repo_root, config_file = get_package_config(args) | 131 repo_root, config_file = get_package_config(args) |
128 context = package.PackageContext.from_proto_file(repo_root, config_file) | 132 context = package.PackageContext.from_proto_file(repo_root, config_file) |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 | 334 |
331 Warmly, | 335 Warmly, |
332 recipes.py | 336 recipes.py |
333 """ | 337 """ |
334 return 1 | 338 return 1 |
335 | 339 |
336 return 0 | 340 return 0 |
337 | 341 |
338 if __name__ == '__main__': | 342 if __name__ == '__main__': |
339 sys.exit(main()) | 343 sys.exit(main()) |
OLD | NEW |