Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 """Download files from Google Storage based on SHA1 sums.""" | 6 """Download files from Google Storage based on SHA1 sums.""" |
| 7 | 7 |
| 8 | 8 |
| 9 import hashlib | 9 import hashlib |
| 10 import optparse | 10 import optparse |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 def __init__(self, path, boto_path, timeout=None, version='4.7'): | 57 def __init__(self, path, boto_path, timeout=None, version='4.7'): |
| 58 if not os.path.exists(path): | 58 if not os.path.exists(path): |
| 59 raise FileNotFoundError('GSUtil not found in %s' % path) | 59 raise FileNotFoundError('GSUtil not found in %s' % path) |
| 60 self.path = path | 60 self.path = path |
| 61 self.timeout = timeout | 61 self.timeout = timeout |
| 62 self.boto_path = boto_path | 62 self.boto_path = boto_path |
| 63 self.version = version | 63 self.version = version |
| 64 | 64 |
| 65 def get_sub_env(self): | 65 def get_sub_env(self): |
| 66 env = os.environ.copy() | 66 env = os.environ.copy() |
| 67 if self.boto_path == os.devnull: | 67 if self.boto_path: |
| 68 env['AWS_CREDENTIAL_FILE'] = '' | |
| 69 env['BOTO_CONFIG'] = '' | |
| 70 elif self.boto_path: | |
| 71 env['AWS_CREDENTIAL_FILE'] = self.boto_path | 68 env['AWS_CREDENTIAL_FILE'] = self.boto_path |
| 72 env['BOTO_CONFIG'] = self.boto_path | 69 env['BOTO_CONFIG'] = self.boto_path |
| 73 else: | |
| 74 custompath = env.get('AWS_CREDENTIAL_FILE', '~/.boto') + '.depot_tools' | |
| 75 custompath = os.path.expanduser(custompath) | |
| 76 if os.path.exists(custompath): | |
| 77 env['AWS_CREDENTIAL_FILE'] = custompath | |
| 78 | 70 |
| 79 return env | 71 return env |
| 80 | 72 |
| 81 def call(self, *args): | 73 def call(self, *args): |
| 82 cmd = [sys.executable, self.path, '--force-version', self.version] | 74 cmd = [sys.executable, self.path, '--force-version', self.version] |
| 83 cmd.extend(args) | 75 cmd.extend(args) |
| 84 return subprocess2.call(cmd, env=self.get_sub_env(), timeout=self.timeout) | 76 if sys.platform.startswith('win'): |
| 77 return subprocess2.call(cmd, env=self.get_sub_env(), timeout=self.timeout) | |
| 78 else: | |
| 79 os.execv(sys.executable, cmd) | |
|
Vadim Sh.
2015/06/17 19:24:04
why? Are you sure 'call' is not used multiple time
hinoka
2015/06/17 19:49:20
I thought it would've been cleaner, but on second
| |
| 85 | 80 |
| 86 def check_call(self, *args): | 81 def check_call(self, *args): |
| 87 cmd = [sys.executable, self.path, '--force-version', self.version] | 82 cmd = [sys.executable, self.path, '--force-version', self.version] |
| 88 cmd.extend(args) | 83 cmd.extend(args) |
| 89 ((out, err), code) = subprocess2.communicate( | 84 ((out, err), code) = subprocess2.communicate( |
| 90 cmd, | 85 cmd, |
| 91 stdout=subprocess2.PIPE, | 86 stdout=subprocess2.PIPE, |
| 92 stderr=subprocess2.PIPE, | 87 stderr=subprocess2.PIPE, |
| 93 env=self.get_sub_env(), | 88 env=self.get_sub_env(), |
| 94 timeout=self.timeout) | 89 timeout=self.timeout) |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 396 # Make sure gsutil exists where we expect it to. | 391 # Make sure gsutil exists where we expect it to. |
| 397 if os.path.exists(GSUTIL_DEFAULT_PATH): | 392 if os.path.exists(GSUTIL_DEFAULT_PATH): |
| 398 gsutil = Gsutil(GSUTIL_DEFAULT_PATH, | 393 gsutil = Gsutil(GSUTIL_DEFAULT_PATH, |
| 399 boto_path=options.boto) | 394 boto_path=options.boto) |
| 400 else: | 395 else: |
| 401 parser.error('gsutil not found in %s, bad depot_tools checkout?' % | 396 parser.error('gsutil not found in %s, bad depot_tools checkout?' % |
| 402 GSUTIL_DEFAULT_PATH) | 397 GSUTIL_DEFAULT_PATH) |
| 403 | 398 |
| 404 # Passing in -g/--config will run our copy of GSUtil, then quit. | 399 # Passing in -g/--config will run our copy of GSUtil, then quit. |
| 405 if options.config: | 400 if options.config: |
| 406 return gsutil.call('config', '-r', '-o', | 401 print '===Note from depot_tools===' |
| 407 os.path.expanduser('~/.boto.depot_tools')) | 402 print 'If you do not have a project ID, enter "0" when asked for one.' |
| 403 print '===End note from depot_tools===' | |
| 404 print | |
| 405 return gsutil.call('config') | |
| 408 | 406 |
| 409 if not args: | 407 if not args: |
| 410 parser.error('Missing target.') | 408 parser.error('Missing target.') |
| 411 if len(args) > 1: | 409 if len(args) > 1: |
| 412 parser.error('Too many targets.') | 410 parser.error('Too many targets.') |
| 413 if not options.bucket: | 411 if not options.bucket: |
| 414 parser.error('Missing bucket. Specify bucket with --bucket.') | 412 parser.error('Missing bucket. Specify bucket with --bucket.') |
| 415 if options.sha1_file and options.directory: | 413 if options.sha1_file and options.directory: |
| 416 parser.error('Both --directory and --sha1_file are specified, ' | 414 parser.error('Both --directory and --sha1_file are specified, ' |
| 417 'can only specify one.') | 415 'can only specify one.') |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 451 base_url = 'gs://%s' % options.bucket | 449 base_url = 'gs://%s' % options.bucket |
| 452 | 450 |
| 453 return download_from_google_storage( | 451 return download_from_google_storage( |
| 454 input_filename, base_url, gsutil, options.num_threads, options.directory, | 452 input_filename, base_url, gsutil, options.num_threads, options.directory, |
| 455 options.recursive, options.force, options.output, options.ignore_errors, | 453 options.recursive, options.force, options.output, options.ignore_errors, |
| 456 options.sha1_file, options.verbose, options.auto_platform) | 454 options.sha1_file, options.verbose, options.auto_platform) |
| 457 | 455 |
| 458 | 456 |
| 459 if __name__ == '__main__': | 457 if __name__ == '__main__': |
| 460 sys.exit(main(sys.argv)) | 458 sys.exit(main(sys.argv)) |
| OLD | NEW |