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 ...]] |
11 | 11 |
12 This script is a wrapper around various version control and repository | 12 This script is a wrapper around various version control and repository |
13 checkout commands. It requires a |recipe| name, fetches data from that | 13 checkout commands. It requires a |recipe| name, fetches data from that |
14 recipe in depot_tools/recipes, and then performs all necessary inits, | 14 recipe in depot_tools/recipes, and then performs all necessary inits, |
15 checkouts, pulls, fetches, etc. | 15 checkouts, pulls, fetches, etc. |
16 | 16 |
17 Optional arguments may be passed on the command line in key-value pairs. | 17 Optional arguments may be passed on the command line in key-value pairs. |
18 These parameters will be passed through to the recipe's main method. | 18 These parameters will be passed through to the recipe's main method. |
19 """ | 19 """ |
20 | 20 |
21 import json | 21 import json |
22 import optparse | 22 import optparse |
23 import os | 23 import os |
| 24 import pipes |
24 import subprocess | 25 import subprocess |
25 import sys | 26 import sys |
26 import pipes | 27 import textwrap |
27 | 28 |
28 from distutils import spawn | 29 from distutils import spawn |
29 | 30 |
30 | 31 |
31 SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__)) | 32 SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__)) |
32 | 33 |
33 ################################################# | 34 ################################################# |
34 # Checkout class definitions. | 35 # Checkout class definitions. |
35 ################################################# | 36 ################################################# |
36 class Checkout(object): | 37 class Checkout(object): |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 191 |
191 | 192 |
192 ################################################# | 193 ################################################# |
193 # Utility function and file entry point. | 194 # Utility function and file entry point. |
194 ################################################# | 195 ################################################# |
195 def usage(msg=None): | 196 def usage(msg=None): |
196 """Print help and exit.""" | 197 """Print help and exit.""" |
197 if msg: | 198 if msg: |
198 print 'Error:', msg | 199 print 'Error:', msg |
199 | 200 |
200 print ( | 201 print textwrap.dedent("""\ |
201 """ | 202 usage: %s [options] <recipe> [--property=value [--property2=value2 ...]] |
202 usage: %s [options] <recipe> [--property=value [--property2=value2 ...]] | |
203 | 203 |
204 This script can be used to download the Chromium sources. See | 204 This script can be used to download the Chromium sources. See |
205 http://www.chromium.org/developers/how-tos/get-the-code | 205 http://www.chromium.org/developers/how-tos/get-the-code |
206 for full usage instructions. | 206 for full usage instructions. |
207 | 207 |
208 Valid options: | 208 Valid options: |
209 -h, --help, help Print this message. | 209 -h, --help, help Print this message. |
210 --nohooks Don't run hooks after checkout. | 210 --nohooks Don't run hooks after checkout. |
211 -n, --dry-run Don't run commands, only print them. | 211 -n, --dry-run Don't run commands, only print them. |
212 --no-history Perform shallow clones, don't fetch the full git history. | 212 --no-history Perform shallow clones, don't fetch the full git histo
ry. |
213 """ % os.path.basename(sys.argv[0])) | 213 |
| 214 Valid fetch recipes:""") % os.path.basename(sys.argv[0]) |
| 215 for fname in os.listdir(os.path.join(SCRIPT_PATH, 'recipes')): |
| 216 if fname.endswith('.py'): |
| 217 print ' ' + fname[:-3] |
| 218 |
214 sys.exit(bool(msg)) | 219 sys.exit(bool(msg)) |
215 | 220 |
216 | 221 |
217 def handle_args(argv): | 222 def handle_args(argv): |
218 """Gets the recipe name from the command line arguments.""" | 223 """Gets the recipe name from the command line arguments.""" |
219 if len(argv) <= 1: | 224 if len(argv) <= 1: |
220 usage('Must specify a recipe.') | 225 usage('Must specify a recipe.') |
221 if argv[1] in ('-h', '--help', 'help'): | 226 if argv[1] in ('-h', '--help', 'help'): |
222 usage() | 227 usage() |
223 | 228 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 | 308 |
304 | 309 |
305 def main(): | 310 def main(): |
306 options, recipe, props = handle_args(sys.argv) | 311 options, recipe, props = handle_args(sys.argv) |
307 spec, root = run_recipe_fetch(recipe, props) | 312 spec, root = run_recipe_fetch(recipe, props) |
308 return run(options, spec, root) | 313 return run(options, spec, root) |
309 | 314 |
310 | 315 |
311 if __name__ == '__main__': | 316 if __name__ == '__main__': |
312 sys.exit(main()) | 317 sys.exit(main()) |
OLD | NEW |