agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 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 |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | """ |
| 7 | Tool to perform checkouts in one easy command line! |
| 8 | |
| 9 | Usage: |
luqui@chromium.org | b371a1c | 2015-12-04 01:42:48 +0000 | [diff] [blame] | 10 | fetch <config> [--property=value [--property2=value2 ...]] |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 11 | |
| 12 | This script is a wrapper around various version control and repository |
luqui@chromium.org | b371a1c | 2015-12-04 01:42:48 +0000 | [diff] [blame] | 13 | checkout commands. It requires a |config| name, fetches data from that |
| 14 | config in depot_tools/fetch_configs, and then performs all necessary inits, |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 15 | checkouts, pulls, fetches, etc. |
| 16 | |
| 17 | Optional arguments may be passed on the command line in key-value pairs. |
luqui@chromium.org | b371a1c | 2015-12-04 01:42:48 +0000 | [diff] [blame] | 18 | These parameters will be passed through to the config's main method. |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 19 | """ |
| 20 | |
| 21 | import json |
digit@chromium.org | 3596d58 | 2013-12-13 17:07:33 +0000 | [diff] [blame] | 22 | import optparse |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 23 | import os |
iannucci@chromium.org | cc2d3e3 | 2014-08-06 19:47:54 +0000 | [diff] [blame] | 24 | import pipes |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 25 | import subprocess |
| 26 | import sys |
iannucci@chromium.org | cc2d3e3 | 2014-08-06 19:47:54 +0000 | [diff] [blame] | 27 | import textwrap |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 28 | |
Dan Jacques | 209a681 | 2017-07-12 11:40:20 -0700 | [diff] [blame] | 29 | import git_common |
| 30 | |
dpranke@chromium.org | 6cc97a1 | 2013-04-12 06:15:58 +0000 | [diff] [blame] | 31 | from distutils import spawn |
| 32 | |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 33 | |
| 34 | SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__)) |
| 35 | |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 36 | ################################################# |
| 37 | # Checkout class definitions. |
| 38 | ################################################# |
| 39 | class Checkout(object): |
| 40 | """Base class for implementing different types of checkouts. |
| 41 | |
| 42 | Attributes: |
| 43 | |base|: the absolute path of the directory in which this script is run. |
luqui@chromium.org | b371a1c | 2015-12-04 01:42:48 +0000 | [diff] [blame] | 44 | |spec|: the spec for this checkout as returned by the config. Different |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 45 | subclasses will expect different keys in this dictionary. |
| 46 | |root|: the directory into which the checkout will be performed, as returned |
luqui@chromium.org | b371a1c | 2015-12-04 01:42:48 +0000 | [diff] [blame] | 47 | by the config. This is a relative path from |base|. |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 48 | """ |
digit@chromium.org | 3596d58 | 2013-12-13 17:07:33 +0000 | [diff] [blame] | 49 | def __init__(self, options, spec, root): |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 50 | self.base = os.getcwd() |
digit@chromium.org | 3596d58 | 2013-12-13 17:07:33 +0000 | [diff] [blame] | 51 | self.options = options |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 52 | self.spec = spec |
| 53 | self.root = root |
| 54 | |
| 55 | def exists(self): |
| 56 | pass |
| 57 | |
| 58 | def init(self): |
| 59 | pass |
| 60 | |
| 61 | def sync(self): |
| 62 | pass |
| 63 | |
dpranke@chromium.org | 6cc97a1 | 2013-04-12 06:15:58 +0000 | [diff] [blame] | 64 | def run(self, cmd, **kwargs): |
| 65 | print 'Running: %s' % (' '.join(pipes.quote(x) for x in cmd)) |
wtc@chromium.org | 38e9461 | 2014-02-12 22:19:41 +0000 | [diff] [blame] | 66 | if self.options.dry_run: |
mmoss@chromium.org | 294c783 | 2015-06-17 16:16:32 +0000 | [diff] [blame] | 67 | return '' |
mmoss@chromium.org | 5a44776 | 2015-06-10 20:01:39 +0000 | [diff] [blame] | 68 | return subprocess.check_output(cmd, **kwargs) |
dpranke@chromium.org | 6cc97a1 | 2013-04-12 06:15:58 +0000 | [diff] [blame] | 69 | |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 70 | |
| 71 | class GclientCheckout(Checkout): |
| 72 | |
dpranke@chromium.org | d88d7f5 | 2013-04-03 21:09:07 +0000 | [diff] [blame] | 73 | def run_gclient(self, *cmd, **kwargs): |
dpranke@chromium.org | 6cc97a1 | 2013-04-12 06:15:58 +0000 | [diff] [blame] | 74 | if not spawn.find_executable('gclient'): |
| 75 | cmd_prefix = (sys.executable, os.path.join(SCRIPT_PATH, 'gclient.py')) |
| 76 | else: |
| 77 | cmd_prefix = ('gclient',) |
| 78 | return self.run(cmd_prefix + cmd, **kwargs) |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 79 | |
mmoss@chromium.org | 5a44776 | 2015-06-10 20:01:39 +0000 | [diff] [blame] | 80 | def exists(self): |
| 81 | try: |
| 82 | gclient_root = self.run_gclient('root').strip() |
| 83 | return (os.path.exists(os.path.join(gclient_root, '.gclient')) or |
| 84 | os.path.exists(os.path.join(os.getcwd(), self.root))) |
| 85 | except subprocess.CalledProcessError: |
| 86 | pass |
| 87 | return os.path.exists(os.path.join(os.getcwd(), self.root)) |
| 88 | |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 89 | |
| 90 | class GitCheckout(Checkout): |
| 91 | |
dpranke@chromium.org | d88d7f5 | 2013-04-03 21:09:07 +0000 | [diff] [blame] | 92 | def run_git(self, *cmd, **kwargs): |
Dan Jacques | 209a681 | 2017-07-12 11:40:20 -0700 | [diff] [blame] | 93 | print 'Running: git %s' % (' '.join(pipes.quote(x) for x in cmd)) |
Aaron Gable | bd95f41 | 2017-11-29 11:20:26 -0800 | [diff] [blame^] | 94 | if self.options.dry_run: |
| 95 | return '' |
Dan Jacques | 209a681 | 2017-07-12 11:40:20 -0700 | [diff] [blame] | 96 | return git_common.run(*cmd, **kwargs) |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 97 | |
| 98 | |
jochen@chromium.org | d993e78 | 2013-04-11 20:03:13 +0000 | [diff] [blame] | 99 | class GclientGitCheckout(GclientCheckout, GitCheckout): |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 100 | |
digit@chromium.org | 3596d58 | 2013-12-13 17:07:33 +0000 | [diff] [blame] | 101 | def __init__(self, options, spec, root): |
| 102 | super(GclientGitCheckout, self).__init__(options, spec, root) |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 103 | assert 'solutions' in self.spec |
agable@chromium.org | 5bde64e | 2014-11-25 22:15:26 +0000 | [diff] [blame] | 104 | |
| 105 | def _format_spec(self): |
| 106 | def _format_literal(lit): |
| 107 | if isinstance(lit, basestring): |
| 108 | return '"%s"' % lit |
| 109 | if isinstance(lit, list): |
| 110 | return '[%s]' % ', '.join(_format_literal(i) for i in lit) |
| 111 | return '%r' % lit |
| 112 | soln_strings = [] |
| 113 | for soln in self.spec['solutions']: |
| 114 | soln_string= '\n'.join(' "%s": %s,' % (key, _format_literal(value)) |
| 115 | for key, value in soln.iteritems()) |
| 116 | soln_strings.append(' {\n%s\n },' % soln_string) |
| 117 | gclient_spec = 'solutions = [\n%s\n]\n' % '\n'.join(soln_strings) |
Dr Alex Gouaillard | e1dd46f | 2016-11-28 15:00:04 +0800 | [diff] [blame] | 118 | extra_keys = ['target_os', 'target_os_only', 'cache_dir'] |
agable@chromium.org | 5bde64e | 2014-11-25 22:15:26 +0000 | [diff] [blame] | 119 | gclient_spec += ''.join('%s = %s\n' % (key, _format_literal(self.spec[key])) |
| 120 | for key in extra_keys if key in self.spec) |
| 121 | return gclient_spec |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 122 | |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 123 | def init(self): |
| 124 | # Configure and do the gclient checkout. |
agable@chromium.org | 5bde64e | 2014-11-25 22:15:26 +0000 | [diff] [blame] | 125 | self.run_gclient('config', '--spec', self._format_spec()) |
jochen@chromium.org | 048da08 | 2014-05-06 08:32:40 +0000 | [diff] [blame] | 126 | sync_cmd = ['sync'] |
agable@chromium.org | b98f3f2 | 2015-06-15 21:59:09 +0000 | [diff] [blame] | 127 | if self.options.nohooks: |
jochen@chromium.org | 048da08 | 2014-05-06 08:32:40 +0000 | [diff] [blame] | 128 | sync_cmd.append('--nohooks') |
primiano@chromium.org | 5439ea5 | 2014-08-06 17:18:18 +0000 | [diff] [blame] | 129 | if self.options.no_history: |
| 130 | sync_cmd.append('--no-history') |
jochen@chromium.org | 048da08 | 2014-05-06 08:32:40 +0000 | [diff] [blame] | 131 | if self.spec.get('with_branch_heads', False): |
| 132 | sync_cmd.append('--with_branch_heads') |
| 133 | self.run_gclient(*sync_cmd) |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 134 | |
| 135 | # Configure git. |
| 136 | wd = os.path.join(self.base, self.root) |
wtc@chromium.org | 38e9461 | 2014-02-12 22:19:41 +0000 | [diff] [blame] | 137 | if self.options.dry_run: |
agable@chromium.org | 2560ea7 | 2013-04-04 01:22:38 +0000 | [diff] [blame] | 138 | print 'cd %s' % wd |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 139 | self.run_git( |
| 140 | 'submodule', 'foreach', |
| 141 | 'git config -f $toplevel/.git/config submodule.$name.ignore all', |
| 142 | cwd=wd) |
iannucci@chromium.org | f2fb5e7 | 2014-04-03 02:36:44 +0000 | [diff] [blame] | 143 | self.run_git( |
| 144 | 'config', '--add', 'remote.origin.fetch', |
| 145 | '+refs/tags/*:refs/tags/*', cwd=wd) |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 146 | self.run_git('config', 'diff.ignoreSubmodules', 'all', cwd=wd) |
| 147 | |
jochen@chromium.org | d993e78 | 2013-04-11 20:03:13 +0000 | [diff] [blame] | 148 | |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 149 | CHECKOUT_TYPE_MAP = { |
| 150 | 'gclient': GclientCheckout, |
jochen@chromium.org | d993e78 | 2013-04-11 20:03:13 +0000 | [diff] [blame] | 151 | 'gclient_git': GclientGitCheckout, |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 152 | 'git': GitCheckout, |
| 153 | } |
| 154 | |
| 155 | |
digit@chromium.org | 3596d58 | 2013-12-13 17:07:33 +0000 | [diff] [blame] | 156 | def CheckoutFactory(type_name, options, spec, root): |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 157 | """Factory to build Checkout class instances.""" |
| 158 | class_ = CHECKOUT_TYPE_MAP.get(type_name) |
| 159 | if not class_: |
| 160 | raise KeyError('unrecognized checkout type: %s' % type_name) |
digit@chromium.org | 3596d58 | 2013-12-13 17:07:33 +0000 | [diff] [blame] | 161 | return class_(options, spec, root) |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 162 | |
| 163 | |
| 164 | ################################################# |
| 165 | # Utility function and file entry point. |
| 166 | ################################################# |
| 167 | def usage(msg=None): |
| 168 | """Print help and exit.""" |
| 169 | if msg: |
| 170 | print 'Error:', msg |
| 171 | |
iannucci@chromium.org | cc2d3e3 | 2014-08-06 19:47:54 +0000 | [diff] [blame] | 172 | print textwrap.dedent("""\ |
luqui@chromium.org | b371a1c | 2015-12-04 01:42:48 +0000 | [diff] [blame] | 173 | usage: %s [options] <config> [--property=value [--property2=value2 ...]] |
digit@chromium.org | 3596d58 | 2013-12-13 17:07:33 +0000 | [diff] [blame] | 174 | |
iannucci@chromium.org | cc2d3e3 | 2014-08-06 19:47:54 +0000 | [diff] [blame] | 175 | This script can be used to download the Chromium sources. See |
| 176 | http://www.chromium.org/developers/how-tos/get-the-code |
| 177 | for full usage instructions. |
digit@chromium.org | 3596d58 | 2013-12-13 17:07:33 +0000 | [diff] [blame] | 178 | |
iannucci@chromium.org | cc2d3e3 | 2014-08-06 19:47:54 +0000 | [diff] [blame] | 179 | Valid options: |
| 180 | -h, --help, help Print this message. |
| 181 | --nohooks Don't run hooks after checkout. |
iannucci@chromium.org | 78faf8b | 2016-05-09 23:26:37 +0000 | [diff] [blame] | 182 | --force (dangerous) Don't look for existing .gclient file. |
iannucci@chromium.org | cc2d3e3 | 2014-08-06 19:47:54 +0000 | [diff] [blame] | 183 | -n, --dry-run Don't run commands, only print them. |
| 184 | --no-history Perform shallow clones, don't fetch the full git history. |
| 185 | |
luqui@chromium.org | b371a1c | 2015-12-04 01:42:48 +0000 | [diff] [blame] | 186 | Valid fetch configs:""") % os.path.basename(sys.argv[0]) |
thestig@chromium.org | 37103c9 | 2015-09-19 20:54:39 +0000 | [diff] [blame] | 187 | |
luqui@chromium.org | b371a1c | 2015-12-04 01:42:48 +0000 | [diff] [blame] | 188 | configs_dir = os.path.join(SCRIPT_PATH, 'fetch_configs') |
| 189 | configs = [f[:-3] for f in os.listdir(configs_dir) if f.endswith('.py')] |
| 190 | configs.sort() |
| 191 | for fname in configs: |
thestig@chromium.org | 37103c9 | 2015-09-19 20:54:39 +0000 | [diff] [blame] | 192 | print ' ' + fname |
iannucci@chromium.org | cc2d3e3 | 2014-08-06 19:47:54 +0000 | [diff] [blame] | 193 | |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 194 | sys.exit(bool(msg)) |
| 195 | |
| 196 | |
| 197 | def handle_args(argv): |
luqui@chromium.org | b371a1c | 2015-12-04 01:42:48 +0000 | [diff] [blame] | 198 | """Gets the config name from the command line arguments.""" |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 199 | if len(argv) <= 1: |
luqui@chromium.org | b371a1c | 2015-12-04 01:42:48 +0000 | [diff] [blame] | 200 | usage('Must specify a config.') |
dpranke@chromium.org | e3d147d | 2013-04-03 20:31:27 +0000 | [diff] [blame] | 201 | if argv[1] in ('-h', '--help', 'help'): |
| 202 | usage() |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 203 | |
wtc@chromium.org | 38e9461 | 2014-02-12 22:19:41 +0000 | [diff] [blame] | 204 | dry_run = False |
digit@chromium.org | 3596d58 | 2013-12-13 17:07:33 +0000 | [diff] [blame] | 205 | nohooks = False |
primiano@chromium.org | 5439ea5 | 2014-08-06 17:18:18 +0000 | [diff] [blame] | 206 | no_history = False |
iannucci@chromium.org | 78faf8b | 2016-05-09 23:26:37 +0000 | [diff] [blame] | 207 | force = False |
digit@chromium.org | 3596d58 | 2013-12-13 17:07:33 +0000 | [diff] [blame] | 208 | while len(argv) >= 2: |
| 209 | arg = argv[1] |
| 210 | if not arg.startswith('-'): |
| 211 | break |
dpranke@chromium.org | d88d7f5 | 2013-04-03 21:09:07 +0000 | [diff] [blame] | 212 | argv.pop(1) |
digit@chromium.org | 3596d58 | 2013-12-13 17:07:33 +0000 | [diff] [blame] | 213 | if arg in ('-n', '--dry-run'): |
wtc@chromium.org | 38e9461 | 2014-02-12 22:19:41 +0000 | [diff] [blame] | 214 | dry_run = True |
digit@chromium.org | 3596d58 | 2013-12-13 17:07:33 +0000 | [diff] [blame] | 215 | elif arg == '--nohooks': |
| 216 | nohooks = True |
primiano@chromium.org | 5439ea5 | 2014-08-06 17:18:18 +0000 | [diff] [blame] | 217 | elif arg == '--no-history': |
| 218 | no_history = True |
iannucci@chromium.org | 78faf8b | 2016-05-09 23:26:37 +0000 | [diff] [blame] | 219 | elif arg == '--force': |
| 220 | force = True |
digit@chromium.org | 3596d58 | 2013-12-13 17:07:33 +0000 | [diff] [blame] | 221 | else: |
| 222 | usage('Invalid option %s.' % arg) |
dpranke@chromium.org | d88d7f5 | 2013-04-03 21:09:07 +0000 | [diff] [blame] | 223 | |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 224 | def looks_like_arg(arg): |
| 225 | return arg.startswith('--') and arg.count('=') == 1 |
| 226 | |
| 227 | bad_parms = [x for x in argv[2:] if not looks_like_arg(x)] |
| 228 | if bad_parms: |
| 229 | usage('Got bad arguments %s' % bad_parms) |
| 230 | |
luqui@chromium.org | b371a1c | 2015-12-04 01:42:48 +0000 | [diff] [blame] | 231 | config = argv[1] |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 232 | props = argv[2:] |
primiano@chromium.org | 5439ea5 | 2014-08-06 17:18:18 +0000 | [diff] [blame] | 233 | return ( |
iannucci@chromium.org | 78faf8b | 2016-05-09 23:26:37 +0000 | [diff] [blame] | 234 | optparse.Values({ |
| 235 | 'dry_run': dry_run, |
| 236 | 'nohooks': nohooks, |
| 237 | 'no_history': no_history, |
| 238 | 'force': force}), |
luqui@chromium.org | b371a1c | 2015-12-04 01:42:48 +0000 | [diff] [blame] | 239 | config, |
primiano@chromium.org | 5439ea5 | 2014-08-06 17:18:18 +0000 | [diff] [blame] | 240 | props) |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 241 | |
| 242 | |
luqui@chromium.org | b371a1c | 2015-12-04 01:42:48 +0000 | [diff] [blame] | 243 | def run_config_fetch(config, props, aliased=False): |
| 244 | """Invoke a config's fetch method with the passed-through args |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 245 | and return its json output as a python object.""" |
luqui@chromium.org | b371a1c | 2015-12-04 01:42:48 +0000 | [diff] [blame] | 246 | config_path = os.path.abspath( |
| 247 | os.path.join(SCRIPT_PATH, 'fetch_configs', config)) |
| 248 | if not os.path.exists(config_path + '.py'): |
| 249 | print "Could not find a config for %s" % config |
dpranke@chromium.org | 2bf328a | 2013-04-03 21:14:41 +0000 | [diff] [blame] | 250 | sys.exit(1) |
| 251 | |
luqui@chromium.org | b371a1c | 2015-12-04 01:42:48 +0000 | [diff] [blame] | 252 | cmd = [sys.executable, config_path + '.py', 'fetch'] + props |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 253 | result = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0] |
dpranke@chromium.org | 2bf328a | 2013-04-03 21:14:41 +0000 | [diff] [blame] | 254 | |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 255 | spec = json.loads(result) |
| 256 | if 'alias' in spec: |
| 257 | assert not aliased |
luqui@chromium.org | b371a1c | 2015-12-04 01:42:48 +0000 | [diff] [blame] | 258 | return run_config_fetch( |
| 259 | spec['alias']['config'], spec['alias']['props'] + props, aliased=True) |
| 260 | cmd = [sys.executable, config_path + '.py', 'root'] |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 261 | result = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0] |
| 262 | root = json.loads(result) |
| 263 | return spec, root |
| 264 | |
| 265 | |
digit@chromium.org | 3596d58 | 2013-12-13 17:07:33 +0000 | [diff] [blame] | 266 | def run(options, spec, root): |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 267 | """Perform a checkout with the given type and configuration. |
| 268 | |
| 269 | Args: |
digit@chromium.org | 3596d58 | 2013-12-13 17:07:33 +0000 | [diff] [blame] | 270 | options: Options instance. |
luqui@chromium.org | b371a1c | 2015-12-04 01:42:48 +0000 | [diff] [blame] | 271 | spec: Checkout configuration returned by the the config's fetch_spec |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 272 | method (checkout type, repository url, etc.). |
| 273 | root: The directory into which the repo expects to be checkout out. |
| 274 | """ |
| 275 | assert 'type' in spec |
| 276 | checkout_type = spec['type'] |
| 277 | checkout_spec = spec['%s_spec' % checkout_type] |
| 278 | try: |
digit@chromium.org | 3596d58 | 2013-12-13 17:07:33 +0000 | [diff] [blame] | 279 | checkout = CheckoutFactory(checkout_type, options, checkout_spec, root) |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 280 | except KeyError: |
| 281 | return 1 |
iannucci@chromium.org | 78faf8b | 2016-05-09 23:26:37 +0000 | [diff] [blame] | 282 | if not options.force and checkout.exists(): |
mmoss@chromium.org | 5a44776 | 2015-06-10 20:01:39 +0000 | [diff] [blame] | 283 | print 'Your current directory appears to already contain, or be part of, ' |
| 284 | print 'a checkout. "fetch" is used only to get new checkouts. Use ' |
| 285 | print '"gclient sync" to update existing checkouts.' |
dpranke@chromium.org | fd79e0d | 2013-04-12 21:34:32 +0000 | [diff] [blame] | 286 | print |
| 287 | print 'Fetch also does not yet deal with partial checkouts, so if fetch' |
| 288 | print 'failed, delete the checkout and start over (crbug.com/230691).' |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 289 | return 1 |
agable@chromium.org | 2560ea7 | 2013-04-04 01:22:38 +0000 | [diff] [blame] | 290 | return checkout.init() |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 291 | |
| 292 | |
| 293 | def main(): |
luqui@chromium.org | b371a1c | 2015-12-04 01:42:48 +0000 | [diff] [blame] | 294 | options, config, props = handle_args(sys.argv) |
| 295 | spec, root = run_config_fetch(config, props) |
digit@chromium.org | 3596d58 | 2013-12-13 17:07:33 +0000 | [diff] [blame] | 296 | return run(options, spec, root) |
agable@chromium.org | cc02350 | 2013-04-03 20:24:21 +0000 | [diff] [blame] | 297 | |
| 298 | |
| 299 | if __name__ == '__main__': |
sbc@chromium.org | 013731e | 2015-02-26 18:28:43 +0000 | [diff] [blame] | 300 | try: |
| 301 | sys.exit(main()) |
| 302 | except KeyboardInterrupt: |
| 303 | sys.stderr.write('interrupted\n') |
| 304 | sys.exit(1) |