| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 else: | 94 else: |
| 95 svn_path = 'svn' | 95 svn_path = 'svn' |
| 96 return self.run((svn_path,) + cmd, **kwargs) | 96 return self.run((svn_path,) + cmd, **kwargs) |
| 97 | 97 |
| 98 | 98 |
| 99 class GclientGitCheckout(GclientCheckout, GitCheckout): | 99 class GclientGitCheckout(GclientCheckout, GitCheckout): |
| 100 | 100 |
| 101 def __init__(self, options, spec, root): | 101 def __init__(self, options, spec, root): |
| 102 super(GclientGitCheckout, self).__init__(options, spec, root) | 102 super(GclientGitCheckout, self).__init__(options, spec, root) |
| 103 assert 'solutions' in self.spec | 103 assert 'solutions' in self.spec |
| 104 keys = ['solutions', 'target_os', 'target_os_only'] | 104 |
| 105 gclient_spec = '\n'.join('%s = %s' % (key, self.spec[key]) | 105 def _format_spec(self): |
| 106 for key in keys if key in self.spec) | 106 def _format_literal(lit): |
| 107 self.spec['gclient_spec'] = gclient_spec | 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) |
| 118 extra_keys = ['target_os', 'target_os_only'] |
| 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 |
| 108 | 122 |
| 109 def exists(self): | 123 def exists(self): |
| 110 return os.path.exists(os.path.join(os.getcwd(), self.root)) | 124 return os.path.exists(os.path.join(os.getcwd(), self.root)) |
| 111 | 125 |
| 112 def init(self): | 126 def init(self): |
| 113 # Configure and do the gclient checkout. | 127 # Configure and do the gclient checkout. |
| 114 self.run_gclient('config', '--spec', self.spec['gclient_spec']) | 128 self.run_gclient('config', '--spec', self._format_spec()) |
| 115 sync_cmd = ['sync'] | 129 sync_cmd = ['sync'] |
| 116 if self.options.nohooks: | 130 if self.options.nohooks: |
| 117 sync_cmd.append('--nohooks') | 131 sync_cmd.append('--nohooks') |
| 118 if self.options.no_history: | 132 if self.options.no_history: |
| 119 sync_cmd.append('--no-history') | 133 sync_cmd.append('--no-history') |
| 120 if self.spec.get('with_branch_heads', False): | 134 if self.spec.get('with_branch_heads', False): |
| 121 sync_cmd.append('--with_branch_heads') | 135 sync_cmd.append('--with_branch_heads') |
| 122 self.run_gclient(*sync_cmd) | 136 self.run_gclient(*sync_cmd) |
| 123 | 137 |
| 124 # Configure git. | 138 # Configure git. |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 | 325 |
| 312 | 326 |
| 313 def main(): | 327 def main(): |
| 314 options, recipe, props = handle_args(sys.argv) | 328 options, recipe, props = handle_args(sys.argv) |
| 315 spec, root = run_recipe_fetch(recipe, props) | 329 spec, root = run_recipe_fetch(recipe, props) |
| 316 return run(options, spec, root) | 330 return run(options, spec, root) |
| 317 | 331 |
| 318 | 332 |
| 319 if __name__ == '__main__': | 333 if __name__ == '__main__': |
| 320 sys.exit(main()) | 334 sys.exit(main()) |
| OLD | NEW |