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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 Under cygwin, this will always return "win32" like the native Python.""" | 47 Under cygwin, this will always return "win32" like the native Python.""" |
| 48 if sys.platform == 'cygwin': | 48 if sys.platform == 'cygwin': |
| 49 return 'win32' | 49 return 'win32' |
| 50 return sys.platform | 50 return sys.platform |
| 51 | 51 |
| 52 | 52 |
| 53 # Common utilities | 53 # Common utilities |
| 54 class Gsutil(object): | 54 class Gsutil(object): |
| 55 """Call gsutil with some predefined settings. This is a convenience object, | 55 """Call gsutil with some predefined settings. This is a convenience object, |
| 56 and is also immutable.""" | 56 and is also immutable.""" |
| 57 def __init__(self, path, boto_path, timeout=None, version='4.7'): | 57 def __init__(self, path, boto_path=None, timeout=None, version='4.7'): |
|
hinoka
2015/06/17 19:49:20
I think i'll deprecate boto_path as a flag at some
| |
| 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 == os.devnull: |
| 68 env['AWS_CREDENTIAL_FILE'] = '' | 68 env['AWS_CREDENTIAL_FILE'] = '' |
| 69 env['BOTO_CONFIG'] = '' | 69 env['BOTO_CONFIG'] = '' |
| 70 elif self.boto_path: | 70 elif self.boto_path: |
| 71 env['AWS_CREDENTIAL_FILE'] = self.boto_path | 71 env['AWS_CREDENTIAL_FILE'] = self.boto_path |
| 72 env['BOTO_CONFIG'] = self.boto_path | 72 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 | 73 |
| 79 return env | 74 return env |
| 80 | 75 |
| 81 def call(self, *args): | 76 def call(self, *args): |
| 82 cmd = [sys.executable, self.path, '--force-version', self.version] | 77 cmd = [sys.executable, self.path, '--force-version', self.version] |
| 83 cmd.extend(args) | 78 cmd.extend(args) |
| 84 return subprocess2.call(cmd, env=self.get_sub_env(), timeout=self.timeout) | 79 return subprocess2.call(cmd, env=self.get_sub_env(), timeout=self.timeout) |
| 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] |
| (...skipping 308 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 |