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 os | 22 import os |
23 import subprocess | 23 import subprocess |
24 import sys | 24 import sys |
25 import pipes | 25 import pipes |
26 | 26 |
27 from distutils import spawn | |
28 | |
27 | 29 |
28 SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__)) | 30 SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__)) |
29 | 31 |
30 | 32 |
31 ################################################# | 33 ################################################# |
32 # Checkout class definitions. | 34 # Checkout class definitions. |
33 ################################################# | 35 ################################################# |
34 class Checkout(object): | 36 class Checkout(object): |
35 """Base class for implementing different types of checkouts. | 37 """Base class for implementing different types of checkouts. |
36 | 38 |
(...skipping 12 matching lines...) Expand all Loading... | |
49 | 51 |
50 def exists(self): | 52 def exists(self): |
51 pass | 53 pass |
52 | 54 |
53 def init(self): | 55 def init(self): |
54 pass | 56 pass |
55 | 57 |
56 def sync(self): | 58 def sync(self): |
57 pass | 59 pass |
58 | 60 |
61 def run(self, tool, cmd_prefix, *cmd, **kwargs): | |
62 print 'Running: %s %s' % (tool, | |
szager1
2013/04/12 03:47:07
Just curious, why print a symbolic name for the co
Dirk Pranke
2013/04/12 03:56:43
Heh. I actually want to be able to cut and paste,
| |
63 ' '.join(pipes.quote(x) for x in cmd)) | |
64 if self.dryrun: | |
65 return 0 | |
66 return subprocess.check_call(cmd_prefix + cmd, **kwargs) | |
67 | |
59 | 68 |
60 class GclientCheckout(Checkout): | 69 class GclientCheckout(Checkout): |
61 | 70 |
62 def run_gclient(self, *cmd, **kwargs): | 71 def run_gclient(self, *cmd, **kwargs): |
63 print 'Running: gclient %s' % ' '.join(pipes.quote(x) for x in cmd) | 72 return self.run('gclient', |
64 if not self.dryrun: | 73 (sys.executable, os.path.join(SCRIPT_PATH, 'gclient.py')), |
65 return subprocess.check_call( | 74 *cmd, **kwargs) |
66 (sys.executable, os.path.join(SCRIPT_PATH, 'gclient.py')) + cmd, | |
67 **kwargs) | |
68 | 75 |
69 | 76 |
70 class GitCheckout(Checkout): | 77 class GitCheckout(Checkout): |
71 | 78 |
72 def run_git(self, *cmd, **kwargs): | 79 def run_git(self, *cmd, **kwargs): |
73 print 'Running: git %s' % ' '.join(pipes.quote(x) for x in cmd) | 80 if sys.platform == 'win32' and not spawn.find_executable('git'): |
szager1
2013/04/12 03:47:07
Optional, but better organization:
class GitCheck
Dirk Pranke
2013/04/12 03:56:43
I'm not really a fan of class-level statement cont
| |
74 if not self.dryrun: | 81 git_path = os.path.join(SCRIPT_PATH, 'git-1.8.0_bin', 'bin', 'git.exe') |
75 return subprocess.check_call(('git',) + cmd, **kwargs) | 82 else: |
83 git_path = 'git' | |
84 return self.run('git', (git_path,), *cmd, **kwargs) | |
76 | 85 |
77 | 86 |
78 class SvnCheckout(Checkout): | 87 class SvnCheckout(Checkout): |
79 | 88 |
80 def run_svn(self, *cmd, **kwargs): | 89 def run_svn(self, *cmd, **kwargs): |
81 print 'Running: svn %s' % ' '.join(pipes.quote(x) for x in cmd) | 90 if sys.platform == 'win32' and not spawn.find_executable('svn'): |
szager1
2013/04/12 03:47:07
Same comment.
Dirk Pranke
2013/04/12 03:56:43
same reply :)
| |
82 if not self.dryrun: | 91 svn_path = os.path.join(SCRIPT_PATH, 'svn_bin', 'svn.exe') |
83 return subprocess.check_call(('svn',) + cmd, **kwargs) | 92 else: |
93 svn_path = 'svn' | |
94 return self.run('svn', (svn_path,), *cmd, **kwargs) | |
84 | 95 |
85 | 96 |
86 class GclientGitCheckout(GclientCheckout, GitCheckout): | 97 class GclientGitCheckout(GclientCheckout, GitCheckout): |
87 | 98 |
88 def __init__(self, dryrun, spec, root): | 99 def __init__(self, dryrun, spec, root): |
89 super(GclientGitCheckout, self).__init__(dryrun, spec, root) | 100 super(GclientGitCheckout, self).__init__(dryrun, spec, root) |
90 assert 'solutions' in self.spec | 101 assert 'solutions' in self.spec |
91 keys = ['solutions', 'target_os', 'target_os_only'] | 102 keys = ['solutions', 'target_os', 'target_os_only'] |
92 gclient_spec = '\n'.join('%s = %s' % (key, self.spec[key]) | 103 gclient_spec = '\n'.join('%s = %s' % (key, self.spec[key]) |
93 for key in self.spec if key in keys) | 104 for key in self.spec if key in keys) |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 | 265 |
255 | 266 |
256 def main(): | 267 def main(): |
257 dryrun, recipe, props = handle_args(sys.argv) | 268 dryrun, recipe, props = handle_args(sys.argv) |
258 spec, root = run_recipe_fetch(recipe, props) | 269 spec, root = run_recipe_fetch(recipe, props) |
259 return run(dryrun, spec, root) | 270 return run(dryrun, spec, root) |
260 | 271 |
261 | 272 |
262 if __name__ == '__main__': | 273 if __name__ == '__main__': |
263 sys.exit(main()) | 274 sys.exit(main()) |
OLD | NEW |