Chromium Code Reviews| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 def init(self): | 56 def init(self): |
| 57 pass | 57 pass |
| 58 | 58 |
| 59 def sync(self): | 59 def sync(self): |
| 60 pass | 60 pass |
| 61 | 61 |
| 62 def run(self, cmd, **kwargs): | 62 def run(self, cmd, **kwargs): |
| 63 print 'Running: %s' % (' '.join(pipes.quote(x) for x in cmd)) | 63 print 'Running: %s' % (' '.join(pipes.quote(x) for x in cmd)) |
| 64 if self.options.dry_run: | 64 if self.options.dry_run: |
| 65 return 0 | 65 return 0 |
| 66 return subprocess.check_call(cmd, **kwargs) | 66 return subprocess.check_output(cmd, **kwargs) |
| 67 | 67 |
| 68 | 68 |
| 69 class GclientCheckout(Checkout): | 69 class GclientCheckout(Checkout): |
| 70 | 70 |
| 71 def run_gclient(self, *cmd, **kwargs): | 71 def run_gclient(self, *cmd, **kwargs): |
| 72 if not spawn.find_executable('gclient'): | 72 if not spawn.find_executable('gclient'): |
| 73 cmd_prefix = (sys.executable, os.path.join(SCRIPT_PATH, 'gclient.py')) | 73 cmd_prefix = (sys.executable, os.path.join(SCRIPT_PATH, 'gclient.py')) |
| 74 else: | 74 else: |
| 75 cmd_prefix = ('gclient',) | 75 cmd_prefix = ('gclient',) |
| 76 return self.run(cmd_prefix + cmd, **kwargs) | 76 return self.run(cmd_prefix + cmd, **kwargs) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 for soln in self.spec['solutions']: | 113 for soln in self.spec['solutions']: |
| 114 soln_string= '\n'.join(' "%s": %s,' % (key, _format_literal(value)) | 114 soln_string= '\n'.join(' "%s": %s,' % (key, _format_literal(value)) |
| 115 for key, value in soln.iteritems()) | 115 for key, value in soln.iteritems()) |
| 116 soln_strings.append(' {\n%s\n },' % soln_string) | 116 soln_strings.append(' {\n%s\n },' % soln_string) |
| 117 gclient_spec = 'solutions = [\n%s\n]\n' % '\n'.join(soln_strings) | 117 gclient_spec = 'solutions = [\n%s\n]\n' % '\n'.join(soln_strings) |
| 118 extra_keys = ['target_os', 'target_os_only'] | 118 extra_keys = ['target_os', 'target_os_only'] |
| 119 gclient_spec += ''.join('%s = %s\n' % (key, _format_literal(self.spec[key])) | 119 gclient_spec += ''.join('%s = %s\n' % (key, _format_literal(self.spec[key])) |
| 120 for key in extra_keys if key in self.spec) | 120 for key in extra_keys if key in self.spec) |
| 121 return gclient_spec | 121 return gclient_spec |
| 122 | 122 |
| 123 def exists(self): | 123 def exists(self): |
|
agable
2015/06/10 17:54:28
Rather than doing this, I would define exists() on
Michael Moss
2015/06/10 18:10:47
Yeah, I wasn't sure how strict we wanted to be, so
agable
2015/06/10 18:22:16
We don't have any GclientSVN-based fetch recipes a
| |
| 124 solution_urls = [s.get('url') for s in self.spec.get('solutions', [])] | |
| 125 try: | |
| 126 current_remote = self.run_git('config', '--get', 'remote.origin.url') | |
| 127 if current_remote.strip() in solution_urls: | |
| 128 return True | |
| 129 except subprocess.CalledProcessError: | |
| 130 pass | |
| 124 return os.path.exists(os.path.join(os.getcwd(), self.root)) | 131 return os.path.exists(os.path.join(os.getcwd(), self.root)) |
| 125 | 132 |
| 126 def init(self): | 133 def init(self): |
| 127 # Configure and do the gclient checkout. | 134 # Configure and do the gclient checkout. |
| 128 self.run_gclient('config', '--spec', self._format_spec()) | 135 self.run_gclient('config', '--spec', self._format_spec()) |
| 129 sync_cmd = ['sync'] | 136 sync_cmd = ['sync'] |
| 130 if self.options.nohooks: | 137 if self.options.nohooks: |
| 131 sync_cmd.append('--nohooks') | 138 sync_cmd.append('--nohooks') |
| 132 if self.options.no_history: | 139 if self.options.no_history: |
| 133 sync_cmd.append('--no-history') | 140 sync_cmd.append('--no-history') |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 308 root: The directory into which the repo expects to be checkout out. | 315 root: The directory into which the repo expects to be checkout out. |
| 309 """ | 316 """ |
| 310 assert 'type' in spec | 317 assert 'type' in spec |
| 311 checkout_type = spec['type'] | 318 checkout_type = spec['type'] |
| 312 checkout_spec = spec['%s_spec' % checkout_type] | 319 checkout_spec = spec['%s_spec' % checkout_type] |
| 313 try: | 320 try: |
| 314 checkout = CheckoutFactory(checkout_type, options, checkout_spec, root) | 321 checkout = CheckoutFactory(checkout_type, options, checkout_spec, root) |
| 315 except KeyError: | 322 except KeyError: |
| 316 return 1 | 323 return 1 |
| 317 if checkout.exists(): | 324 if checkout.exists(): |
| 318 print 'You appear to already have a checkout. "fetch" is used only' | 325 print 'Your current directory appears to already contain, or be part of, ' |
| 319 print 'to get new checkouts. Use "gclient sync" to update the checkout.' | 326 print 'a checkout. "fetch" is used only to get new checkouts. Use ' |
| 327 print '"gclient sync" to update existing checkouts.' | |
| 320 print | 328 print |
| 321 print 'Fetch also does not yet deal with partial checkouts, so if fetch' | 329 print 'Fetch also does not yet deal with partial checkouts, so if fetch' |
| 322 print 'failed, delete the checkout and start over (crbug.com/230691).' | 330 print 'failed, delete the checkout and start over (crbug.com/230691).' |
| 323 return 1 | 331 return 1 |
| 324 return checkout.init() | 332 return checkout.init() |
| 325 | 333 |
| 326 | 334 |
| 327 def main(): | 335 def main(): |
| 328 options, recipe, props = handle_args(sys.argv) | 336 options, recipe, props = handle_args(sys.argv) |
| 329 spec, root = run_recipe_fetch(recipe, props) | 337 spec, root = run_recipe_fetch(recipe, props) |
| 330 return run(options, spec, root) | 338 return run(options, spec, root) |
| 331 | 339 |
| 332 | 340 |
| 333 if __name__ == '__main__': | 341 if __name__ == '__main__': |
| 334 try: | 342 try: |
| 335 sys.exit(main()) | 343 sys.exit(main()) |
| 336 except KeyboardInterrupt: | 344 except KeyboardInterrupt: |
| 337 sys.stderr.write('interrupted\n') | 345 sys.stderr.write('interrupted\n') |
| 338 sys.exit(1) | 346 sys.exit(1) |
| OLD | NEW |