| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """ | 6 """ |
| 7 Tool to perform checkouts in one easy command line! | 7 Tool to perform checkouts in one easy command line! |
| 8 | 8 |
| 9 Usage: | 9 Usage: |
| 10 fetch <recipe> [--property=value [--property2=value2 ...]] | 10 fetch <recipe> [--property=value [--property2=value2 ...]] |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 sys.exit(bool(msg)) | 153 sys.exit(bool(msg)) |
| 154 | 154 |
| 155 | 155 |
| 156 def handle_args(argv): | 156 def handle_args(argv): |
| 157 """Gets the recipe name from the command line arguments.""" | 157 """Gets the recipe name from the command line arguments.""" |
| 158 if len(argv) <= 1: | 158 if len(argv) <= 1: |
| 159 usage('Must specify a recipe.') | 159 usage('Must specify a recipe.') |
| 160 if argv[1] in ('-h', '--help', 'help'): | 160 if argv[1] in ('-h', '--help', 'help'): |
| 161 usage() | 161 usage() |
| 162 | 162 |
| 163 dryrun = False |
| 163 if argv[1] in ('-n', '--dry-run'): | 164 if argv[1] in ('-n', '--dry-run'): |
| 164 dryrun = True | 165 dryrun = True |
| 165 argv.pop(1) | 166 argv.pop(1) |
| 166 | 167 |
| 167 def looks_like_arg(arg): | 168 def looks_like_arg(arg): |
| 168 return arg.startswith('--') and arg.count('=') == 1 | 169 return arg.startswith('--') and arg.count('=') == 1 |
| 169 | 170 |
| 170 bad_parms = [x for x in argv[2:] if not looks_like_arg(x)] | 171 bad_parms = [x for x in argv[2:] if not looks_like_arg(x)] |
| 171 if bad_parms: | 172 if bad_parms: |
| 172 usage('Got bad arguments %s' % bad_parms) | 173 usage('Got bad arguments %s' % bad_parms) |
| 173 | 174 |
| 174 recipe = argv[1] | 175 recipe = argv[1] |
| 175 props = argv[2:] | 176 props = argv[2:] |
| 176 return dryrun, recipe, props | 177 return dryrun, recipe, props |
| 177 | 178 |
| 178 | 179 |
| 179 def run_recipe_fetch(recipe, props, aliased=False): | 180 def run_recipe_fetch(recipe, props, aliased=False): |
| 180 """Invoke a recipe's fetch method with the passed-through args | 181 """Invoke a recipe's fetch method with the passed-through args |
| 181 and return its json output as a python object.""" | 182 and return its json output as a python object.""" |
| 182 recipe_path = os.path.abspath(os.path.join(SCRIPT_PATH, 'recipes', recipe)) | 183 recipe_path = os.path.abspath(os.path.join(SCRIPT_PATH, 'recipes', recipe)) |
| 183 if not os.path.exists(recipe_path): | 184 if not os.path.exists(recipe_path + '.py'): |
| 184 print "Could not find a recipe for %s" % recipe | 185 print "Could not find a recipe for %s" % recipe |
| 185 sys.exit(1) | 186 sys.exit(1) |
| 186 | 187 |
| 187 cmd = [sys.executable, recipe_path + '.py', 'fetch'] + props | 188 cmd = [sys.executable, recipe_path + '.py', 'fetch'] + props |
| 188 result = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0] | 189 result = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0] |
| 189 | 190 |
| 190 spec = json.loads(result) | 191 spec = json.loads(result) |
| 191 if 'alias' in spec: | 192 if 'alias' in spec: |
| 192 assert not aliased | 193 assert not aliased |
| 193 return run_recipe_fetch( | 194 return run_recipe_fetch( |
| (...skipping 29 matching lines...) Expand all Loading... |
| 223 | 224 |
| 224 | 225 |
| 225 def main(): | 226 def main(): |
| 226 dryrun, recipe, props = handle_args(sys.argv) | 227 dryrun, recipe, props = handle_args(sys.argv) |
| 227 spec, root = run_recipe_fetch(recipe, props) | 228 spec, root = run_recipe_fetch(recipe, props) |
| 228 return run(dryrun, spec, root) | 229 return run(dryrun, spec, root) |
| 229 | 230 |
| 230 | 231 |
| 231 if __name__ == '__main__': | 232 if __name__ == '__main__': |
| 232 sys.exit(main()) | 233 sys.exit(main()) |
| OLD | NEW |