Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(447)

Side by Side Diff: gsutil.py

Issue 828463003: Fix gsutil execution on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | win_toolchain/toolchain2013.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 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 """Run a pinned gsutil.""" 6 """Run a pinned gsutil."""
7 7
8 8
9 import argparse 9 import argparse
10 import base64 10 import base64
(...skipping 10 matching lines...) Expand all
21 GSUTIL_URL = 'https://storage.googleapis.com/pub/' 21 GSUTIL_URL = 'https://storage.googleapis.com/pub/'
22 API_URL = 'https://www.googleapis.com/storage/v1/b/pub/o/' 22 API_URL = 'https://www.googleapis.com/storage/v1/b/pub/o/'
23 23
24 THIS_DIR = os.path.dirname(os.path.abspath(__file__)) 24 THIS_DIR = os.path.dirname(os.path.abspath(__file__))
25 DEFAULT_BIN_DIR = os.path.join(THIS_DIR, 'external_bin', 'gsutil') 25 DEFAULT_BIN_DIR = os.path.join(THIS_DIR, 'external_bin', 'gsutil')
26 DEFAULT_FALLBACK_GSUTIL = os.path.join( 26 DEFAULT_FALLBACK_GSUTIL = os.path.join(
27 THIS_DIR, 'third_party', 'gsutil', 'gsutil') 27 THIS_DIR, 'third_party', 'gsutil', 'gsutil')
28 28
29 29
30 class SubprocessError(Exception): 30 class SubprocessError(Exception):
31 pass 31 def __init__(self, message=None, code=0):
32 super(SubprocessError, self).__init__(message)
33 self.code = code
32 34
33 35
34 class InvalidGsutilError(Exception): 36 class InvalidGsutilError(Exception):
35 pass 37 pass
36 38
37 39
38 def call(args, verbose=True, **kwargs): 40 def call(args, verbose=True, **kwargs):
39 kwargs['stdout'] = subprocess.PIPE 41 kwargs['stdout'] = subprocess.PIPE
40 kwargs['stderr'] = subprocess.STDOUT 42 kwargs['stderr'] = subprocess.STDOUT
41 proc = subprocess.Popen(args, **kwargs) 43 proc = subprocess.Popen(args, **kwargs)
42 out = [] 44 out = []
43 for line in proc.stdout: 45 for line in proc.stdout:
44 out.append(line) 46 out.append(line)
45 if verbose: 47 if verbose:
46 sys.stdout.write(line) 48 sys.stdout.write(line)
47 code = proc.wait() 49 code = proc.wait()
48 if code: 50 if code:
49 raise SubprocessError('%s failed with %s' % (args, code)) 51 raise SubprocessError('%s failed with %s' % (args, code), code)
50 return ''.join(out) 52 return ''.join(out)
51 53
52 54
53 def download_gsutil(version, target_dir): 55 def download_gsutil(version, target_dir):
54 """Downloads gsutil into the target_dir.""" 56 """Downloads gsutil into the target_dir."""
55 filename = 'gsutil_%s.zip' % version 57 filename = 'gsutil_%s.zip' % version
56 target_filename = os.path.join(target_dir, filename) 58 target_filename = os.path.join(target_dir, filename)
57 59
58 # Check if the target exists already. 60 # Check if the target exists already.
59 if os.path.exists(target_filename): 61 if os.path.exists(target_filename):
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 120
119 return gsutil_bin 121 return gsutil_bin
120 122
121 123
122 def run_gsutil(force_version, fallback, target, args): 124 def run_gsutil(force_version, fallback, target, args):
123 if force_version: 125 if force_version:
124 gsutil_bin = ensure_gsutil(force_version, target) 126 gsutil_bin = ensure_gsutil(force_version, target)
125 else: 127 else:
126 gsutil_bin = fallback 128 gsutil_bin = fallback
127 cmd = [sys.executable, gsutil_bin] + args 129 cmd = [sys.executable, gsutil_bin] + args
128 os.execv(cmd[0], cmd) 130 try:
131 call(cmd)
132 except SubprocessError as e:
133 return e.code
134 return 0
129 135
130 136
131 def parse_args(): 137 def parse_args():
132 parser = argparse.ArgumentParser() 138 parser = argparse.ArgumentParser()
133 parser.add_argument('--force-version') 139 parser.add_argument('--force-version')
134 parser.add_argument('--fallback', default=DEFAULT_FALLBACK_GSUTIL) 140 parser.add_argument('--fallback', default=DEFAULT_FALLBACK_GSUTIL)
135 parser.add_argument('--target', default=DEFAULT_BIN_DIR) 141 parser.add_argument('--target', default=DEFAULT_BIN_DIR)
136 parser.add_argument('args', nargs=argparse.REMAINDER) 142 parser.add_argument('args', nargs=argparse.REMAINDER)
137 143
138 args, extras = parser.parse_known_args() 144 args, extras = parser.parse_known_args()
139 if args.args and args.args[0] == '--': 145 if args.args and args.args[0] == '--':
140 args.args.pop(0) 146 args.args.pop(0)
141 if extras: 147 if extras:
142 args.args = extras + args.args 148 args.args = extras + args.args
143 return args.force_version, args.fallback, args.target, args.args 149 return args.force_version, args.fallback, args.target, args.args
144 150
145 151
146 def main(): 152 def main():
147 force_version, fallback, target, args = parse_args() 153 force_version, fallback, target, args = parse_args()
148 run_gsutil(force_version, fallback, target, args) 154 return run_gsutil(force_version, fallback, target, args)
149 155
150 if __name__ == '__main__': 156 if __name__ == '__main__':
151 sys.exit(main()) 157 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | win_toolchain/toolchain2013.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698