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 from recipe_engine import loader |
| 45 |
| 46 _, config_file = get_package_config(args) |
| 47 universe = loader.RecipeUniverse(package_deps, config_file.path) |
| 48 |
| 49 lint_test.main(universe, args.whitelist or []) |
40 | 50 |
41 | 51 |
42 def handle_recipe_return(recipe_result, result_filename, stream): | 52 def handle_recipe_return(recipe_result, result_filename, stream): |
43 if 'recipe_result' in recipe_result.result: | 53 if 'recipe_result' in recipe_result.result: |
44 result_string = json.dumps( | 54 result_string = json.dumps( |
45 recipe_result.result['recipe_result'], indent=2) | 55 recipe_result.result['recipe_result'], indent=2) |
46 if result_filename: | 56 if result_filename: |
47 with open(result_filename, 'w') as f: | 57 with open(result_filename, 'w') as f: |
48 f.write(result_string) | 58 f.write(result_string) |
49 else: | 59 with stream.step('recipe result') as s: |
50 with stream.step('recipe result') as s: | 60 s.write_log_lines('result', [result_string]) |
51 s.write_log_lines('result', [result_string]) | |
52 | 61 |
53 if 'reason' in recipe_result.result: | 62 if 'reason' in recipe_result.result: |
54 with stream.step('recipe failure reason') as s: | 63 with stream.step('recipe failure reason') as s: |
55 s.write_log_lines( | 64 s.write_log_lines( |
56 'failure reason', | 65 'failure reason', |
57 [recipe_result.result['reason']]) | 66 [recipe_result.result['reason']]) |
58 | 67 |
59 code = recipe_result.result.get('status_code', 1) | 68 code = recipe_result.result.get('status_code', 1) |
60 if code == -1: | 69 if code == -1: |
61 s.step_exception() | 70 s.step_exception() |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 elif args.properties_file: | 110 elif args.properties_file: |
102 properties = get_properties_from_file(args.properties_file) | 111 properties = get_properties_from_file(args.properties_file) |
103 else: | 112 else: |
104 properties = arg_properties | 113 properties = arg_properties |
105 | 114 |
106 properties['recipe'] = args.recipe | 115 properties['recipe'] = args.recipe |
107 | 116 |
108 os.environ['PYTHONUNBUFFERED'] = '1' | 117 os.environ['PYTHONUNBUFFERED'] = '1' |
109 os.environ['PYTHONIOENCODING'] = 'UTF-8' | 118 os.environ['PYTHONIOENCODING'] = 'UTF-8' |
110 | 119 |
111 universe = loader.RecipeUniverse(package_deps) | 120 _, config_file = get_package_config(args) |
| 121 universe = loader.RecipeUniverse(package_deps, config_file.path) |
112 | 122 |
113 workdir = (args.workdir or | 123 workdir = (args.workdir or |
114 os.path.join(os.path.dirname(os.path.realpath(__file__)), 'workdir')) | 124 os.path.join(os.path.dirname(os.path.realpath(__file__)), 'workdir')) |
115 logging.info('Using %s as work directory' % workdir) | 125 logging.info('Using %s as work directory' % workdir) |
116 if not os.path.exists(workdir): | 126 if not os.path.exists(workdir): |
117 os.makedirs(workdir) | 127 os.makedirs(workdir) |
118 | 128 |
119 old_cwd = os.getcwd() | 129 old_cwd = os.getcwd() |
120 os.chdir(workdir) | 130 os.chdir(workdir) |
121 stream = annotator.StructuredAnnotationStream() | 131 stream = annotator.StructuredAnnotationStream() |
122 | 132 |
123 try: | 133 try: |
124 ret = recipe_run.run_steps(properties, stream, universe=universe) | 134 ret = recipe_run.run_steps(properties, stream, universe=universe) |
125 | 135 |
126 finally: | 136 finally: |
127 os.chdir(old_cwd) | 137 os.chdir(old_cwd) |
128 | 138 |
129 return handle_recipe_return(ret, args.result_file, stream) | 139 return handle_recipe_return(ret, args.output_result_json, stream) |
130 | 140 |
131 | 141 |
132 def roll(args): | 142 def roll(args): |
133 from recipe_engine import package | 143 from recipe_engine import package |
134 repo_root, config_file = get_package_config(args) | 144 repo_root, config_file = get_package_config(args) |
135 context = package.PackageContext.from_proto_file(repo_root, config_file) | 145 context = package.PackageContext.from_proto_file(repo_root, config_file) |
136 package_spec = package.PackageSpec.load_proto(config_file) | 146 package_spec = package.PackageSpec.load_proto(config_file) |
137 | 147 |
138 for update in package_spec.iterate_consistent_updates(config_file, context): | 148 for update in package_spec.iterate_consistent_updates(config_file, context): |
139 config_file.write(update.spec.dump()) | 149 config_file.write(update.spec.dump()) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 raise ValueError("An override is already defined for [%s] (%s)" % ( | 190 raise ValueError("An override is already defined for [%s] (%s)" % ( |
181 project_id, v[project_id])) | 191 project_id, v[project_id])) |
182 path = os.path.abspath(os.path.expanduser(path)) | 192 path = os.path.abspath(os.path.expanduser(path)) |
183 if not os.path.isdir(path): | 193 if not os.path.isdir(path): |
184 raise ValueError("Override path [%s] is not a directory" % (path,)) | 194 raise ValueError("Override path [%s] is not a directory" % (path,)) |
185 v[project_id] = path | 195 v[project_id] = path |
186 | 196 |
187 | 197 |
188 def doc(package_deps, args): | 198 def doc(package_deps, args): |
189 from recipe_engine import doc | 199 from recipe_engine import doc |
190 doc.main(package_deps) | 200 from recipe_engine import loader |
| 201 |
| 202 _, config_file = get_package_config(args) |
| 203 universe = loader.RecipeUniverse(package_deps, config_file) |
| 204 |
| 205 doc.main(universe) |
191 | 206 |
192 | 207 |
193 def info(args): | 208 def info(args): |
194 from recipe_engine import package | 209 from recipe_engine import package |
195 repo_root, config_file = get_package_config(args) | 210 repo_root, config_file = get_package_config(args) |
196 package_spec = package.PackageSpec.load_proto(config_file) | 211 package_spec = package.PackageSpec.load_proto(config_file) |
197 | 212 |
198 if args.recipes_dir: | 213 if args.recipes_dir: |
199 print package_spec.recipes_path | 214 print package_spec.recipes_path |
200 | 215 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 run_p.add_argument( | 271 run_p.add_argument( |
257 '--properties-file', | 272 '--properties-file', |
258 help='A file containing a json blob of properties') | 273 help='A file containing a json blob of properties') |
259 run_p.add_argument( | 274 run_p.add_argument( |
260 '--properties', | 275 '--properties', |
261 help='A json string containing the properties') | 276 help='A json string containing the properties') |
262 run_p.add_argument( | 277 run_p.add_argument( |
263 '--workdir', | 278 '--workdir', |
264 help='The working directory of recipe execution') | 279 help='The working directory of recipe execution') |
265 run_p.add_argument( | 280 run_p.add_argument( |
266 '--result-file', | 281 '--output-result-json', |
267 help='The file to write the JSON serialized returned value \ | 282 help='The file to write the JSON serialized returned value \ |
268 of the recipe to') | 283 of the recipe to') |
269 run_p.add_argument( | 284 run_p.add_argument( |
270 'recipe', | 285 'recipe', |
271 help='The recipe to execute') | 286 help='The recipe to execute') |
272 run_p.add_argument( | 287 run_p.add_argument( |
273 'props', nargs=argparse.REMAINDER, | 288 'props', nargs=argparse.REMAINDER, |
274 help='A list of property pairs; e.g. mastername=chromium.linux ' | 289 help='A list of property pairs; e.g. mastername=chromium.linux ' |
275 'issue=12345') | 290 'issue=12345') |
276 | 291 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 | 352 |
338 Warmly, | 353 Warmly, |
339 recipes.py | 354 recipes.py |
340 """ | 355 """ |
341 return 1 | 356 return 1 |
342 | 357 |
343 return 0 | 358 return 0 |
344 | 359 |
345 if __name__ == '__main__': | 360 if __name__ == '__main__': |
346 sys.exit(main()) | 361 sys.exit(main()) |
OLD | NEW |