Chromium Code Reviews| Index: fetch.py |
| diff --git a/fetch.py b/fetch.py |
| index 80dcce9a2f13a0e7aeefaf8871298a7737154af3..496e23f5e98f16fecafdddf70a69aa86bc283178 100755 |
| --- a/fetch.py |
| +++ b/fetch.py |
| @@ -24,6 +24,8 @@ import subprocess |
| import sys |
| import pipes |
| +from distutils import spawn |
| + |
| SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__)) |
| @@ -46,6 +48,8 @@ class Checkout(object): |
| self.dryrun = dryrun |
| self.spec = spec |
| self.root = root |
| + self._script_paths = {} |
| + self._binary_paths = {} |
| def exists(self): |
| pass |
| @@ -56,31 +60,57 @@ class Checkout(object): |
| def sync(self): |
| pass |
| + @staticmethod |
| + def _find_executable(binary_name): |
| + exe_name = binary_name + '.exe' if sys.platform == 'win32' else binary_name |
| + path = spawn.find_executable(exe_name) |
| + if path: |
| + return path |
| + return spawn.find_executable(os.path.join(SCRIPT_PATH, binary_name + '_bin', |
|
agable
2013/04/11 18:21:09
Isn't git installed to depot_tools\git-1.8.0_bin\
|
| + exe_name)) |
| + |
| + def run_script(self, script, *args, **kwargs): |
| + path = self._script_paths.get(script) |
| + if not path: |
| + path = os.path.join(SCRIPT_PATH, script + '.py') |
| + if not os.path.exists(path): |
| + print "Error: could not find '%s.py' in depot_tools" % script |
| + return 1 |
| + self._script_paths[script] = path |
| + print 'Running: %s %s' % (script, |
| + ' '.join(pipes.quote(arg) for arg in args)) |
| + if self.dryrun: |
| + return 0 |
| + return subprocess.check_call((sys.executable, path) + args, **kwargs) |
| + |
| + def run_binary(self, binary_name, *args, **kwargs): |
| + path = self._binary_paths.get(binary_name) |
| + if not path: |
| + path = self._find_executable(binary_name) |
| + if not path: |
| + print "Error: could not find '%s' in PATH" % binary_name |
| + return 1 |
| + self._binary_paths[binary_name] = path |
| + print 'Running: %s %s' % (binary_name, |
| + ' '.join(pipes.quote(arg) for arg in args)) |
| + if self.dryrun: |
| + return 0 |
| + return subprocess.check_call((path,) + args, **kwargs) |
| -class GclientCheckout(Checkout): |
| - def run_gclient(self, *cmd, **kwargs): |
| - print 'Running: gclient %s' % ' '.join(pipes.quote(x) for x in cmd) |
| - if not self.dryrun: |
| - return subprocess.check_call( |
| - (sys.executable, os.path.join(SCRIPT_PATH, 'gclient.py')) + cmd, |
| - **kwargs) |
| +class GclientCheckout(Checkout): |
| + def run_gclient(self, *args, **kwargs): |
| + return self.run_script('gclient', *args, **kwargs) |
| class GitCheckout(Checkout): |
| - |
| - def run_git(self, *cmd, **kwargs): |
| - print 'Running: git %s' % ' '.join(pipes.quote(x) for x in cmd) |
| - if not self.dryrun: |
| - return subprocess.check_call(('git',) + cmd, **kwargs) |
| + def run_git(self, *args, **kwargs): |
| + return self.run_binary('git', *args, **kwargs) |
| class SvnCheckout(Checkout): |
| - |
| - def run_svn(self, *cmd, **kwargs): |
| - print 'Running: svn %s' % ' '.join(pipes.quote(x) for x in cmd) |
| - if not self.dryrun: |
| - return subprocess.check_call(('svn',) + cmd, **kwargs) |
| + def run_svn(self, *args, **kwargs): |
| + return self.run_binary('svn', *args, **kwargs) |
| class GclientGitSvnCheckout(GclientCheckout, GitCheckout, SvnCheckout): |