OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Functions specific to build slaves, shared by several buildbot scripts. | 5 """Functions specific to build slaves, shared by several buildbot scripts. |
6 """ | 6 """ |
7 | 7 |
8 import datetime | 8 import datetime |
9 import glob | 9 import glob |
10 import os | 10 import os |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 ): | 368 ): |
369 return name | 369 return name |
370 | 370 |
371 # Add provider prefix | 371 # Add provider prefix |
372 if not provider_prefix: | 372 if not provider_prefix: |
373 provider_prefix = 'x-goog-meta' | 373 provider_prefix = 'x-goog-meta' |
374 return '%s-%s' % (provider_prefix, name) | 374 return '%s-%s' % (provider_prefix, name) |
375 | 375 |
376 | 376 |
377 def GSUtilCopy(source, dest, mimetype=None, gs_acl=None, cache_control=None, | 377 def GSUtilCopy(source, dest, mimetype=None, gs_acl=None, cache_control=None, |
378 metadata=None): | 378 metadata=None, override_gsutil=None): |
379 """Copy a file to Google Storage. | 379 """Copy a file to Google Storage. |
380 | 380 |
381 Runs the following command: | 381 Runs the following command: |
382 gsutil -h Content-Type:<mimetype> \ | 382 gsutil -h Content-Type:<mimetype> \ |
383 -h Cache-Control:<cache_control> \ | 383 -h Cache-Control:<cache_control> \ |
384 cp -a <gs_acl> file://<filename> <gs_base>/<subdir>/<filename w/o path> | 384 cp -a <gs_acl> file://<filename> <gs_base>/<subdir>/<filename w/o path> |
385 | 385 |
386 Args: | 386 Args: |
387 source: the source URI | 387 source: the source URI |
388 dest: the destination URI | 388 dest: the destination URI |
389 mimetype: optional value to add as a Content-Type header | 389 mimetype: optional value to add as a Content-Type header |
390 gs_acl: optional value to add as a canned-acl | 390 gs_acl: optional value to add as a canned-acl |
391 cache_control: optional value to set Cache-Control header | 391 cache_control: optional value to set Cache-Control header |
392 metadata: (dict) A dictionary of string key/value metadata entries to set | 392 metadata: (dict) A dictionary of string key/value metadata entries to set |
393 (see `gsutil cp' '-h' option) | 393 (see `gsutil cp' '-h' option) |
| 394 override_gsutil (list): optional argv to run gsutil |
394 Returns: | 395 Returns: |
395 The status code returned from running the generated gsutil command. | 396 The status code returned from running the generated gsutil command. |
396 """ | 397 """ |
397 | 398 |
398 if not source.startswith('gs://') and not source.startswith('file://'): | 399 if not source.startswith('gs://') and not source.startswith('file://'): |
399 source = 'file://' + source | 400 source = 'file://' + source |
400 if not dest.startswith('gs://') and not dest.startswith('file://'): | 401 if not dest.startswith('gs://') and not dest.startswith('file://'): |
401 dest = 'file://' + dest | 402 dest = 'file://' + dest |
| 403 # The setup also sets up some env variables - for now always run that. |
402 gsutil = GSUtilSetup() | 404 gsutil = GSUtilSetup() |
403 # Run the gsutil command. gsutil internally calls command_wrapper, which | 405 # Run the gsutil command. gsutil internally calls command_wrapper, which |
404 # will try to run the command 10 times if it fails. | 406 # will try to run the command 10 times if it fails. |
405 command = [gsutil] | 407 command = override_gsutil or [gsutil] |
406 | 408 |
407 if not metadata: | 409 if not metadata: |
408 metadata = {} | 410 metadata = {} |
409 if mimetype: | 411 if mimetype: |
410 metadata['Content-Type'] = mimetype | 412 metadata['Content-Type'] = mimetype |
411 if cache_control: | 413 if cache_control: |
412 metadata['Cache-Control'] = cache_control | 414 metadata['Cache-Control'] = cache_control |
413 for k, v in sorted(metadata.iteritems(), key=lambda (k, _): k): | 415 for k, v in sorted(metadata.iteritems(), key=lambda (k, _): k): |
414 field = GSUtilGetMetadataField(k) | 416 field = GSUtilGetMetadataField(k) |
415 param = (field) if v is None else ('%s:%s' % (field, v)) | 417 param = (field) if v is None else ('%s:%s' % (field, v)) |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 '--filesync', | 728 '--filesync', |
727 '--recurse-paths', | 729 '--recurse-paths', |
728 '--symlinks', | 730 '--symlinks', |
729 local_archive, | 731 local_archive, |
730 ] | 732 ] |
731 zip_cmd.extend(targets) | 733 zip_cmd.extend(targets) |
732 | 734 |
733 chromium_utils.RunCommand(zip_cmd) | 735 chromium_utils.RunCommand(zip_cmd) |
734 GSUtilCopy(local_archive, 'gs://%s/%s' % (bucket, archive)) | 736 GSUtilCopy(local_archive, 'gs://%s/%s' % (bucket, archive)) |
735 return 'https://storage.cloud.google.com/%s/%s' % (bucket, archive) | 737 return 'https://storage.cloud.google.com/%s/%s' % (bucket, archive) |
OLD | NEW |