| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 2 # Copyright (c) 2010 The Chromium OS 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 import datetime | 6 import datetime |
| 7 import multiprocessing | 7 import multiprocessing |
| 8 import optparse | 8 import optparse |
| 9 import os | 9 import os |
| 10 import re | 10 import re |
| 11 import sys | 11 import sys |
| 12 import tempfile | 12 import tempfile |
| 13 import time | 13 import time |
| 14 import urlparse | |
| 15 | 14 |
| 16 from chromite.lib import cros_build_lib | 15 from chromite.lib import cros_build_lib |
| 17 from chromite.lib.binpkg import (GrabLocalPackageIndex, GrabRemotePackageIndex, | 16 from chromite.lib.binpkg import (GrabLocalPackageIndex, GrabRemotePackageIndex, |
| 18 PackageIndex) | 17 PackageIndex) |
| 19 """ | 18 """ |
| 20 This script is used to upload host prebuilts as well as board BINHOSTS. | 19 This script is used to upload host prebuilts as well as board BINHOSTS. |
| 21 | 20 |
| 22 If the URL starts with 'gs://', we upload using gsutil to Google Storage. | 21 If the URL starts with 'gs://', we upload using gsutil to Google Storage. |
| 23 Otherwise, rsync is used. | 22 Otherwise, rsync is used. |
| 24 | 23 |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 pkgs: The packages to upload. | 309 pkgs: The packages to upload. |
| 311 | 310 |
| 312 Returns: | 311 Returns: |
| 313 Returns a dictionary of local_path/remote_path pairs | 312 Returns a dictionary of local_path/remote_path pairs |
| 314 """ | 313 """ |
| 315 upload_files = {} | 314 upload_files = {} |
| 316 for pkg in pkgs: | 315 for pkg in pkgs: |
| 317 suffix = pkg['CPV'] + '.tbz2' | 316 suffix = pkg['CPV'] + '.tbz2' |
| 318 local_path = os.path.join(base_local_path, suffix) | 317 local_path = os.path.join(base_local_path, suffix) |
| 319 assert os.path.exists(local_path) | 318 assert os.path.exists(local_path) |
| 320 remote_path = urlparse.urljoin(base_remote_path, suffix) | 319 remote_path = '%s/%s' % (base_remote_path.rstrip('/'), suffix) |
| 321 upload_files[local_path] = remote_path | 320 upload_files[local_path] = remote_path |
| 322 | 321 |
| 323 return upload_files | 322 return upload_files |
| 324 | 323 |
| 325 | 324 |
| 326 def DetermineMakeConfFile(target): | 325 def DetermineMakeConfFile(target): |
| 327 """Determine the make.conf file that needs to be updated for prebuilts. | 326 """Determine the make.conf file that needs to be updated for prebuilts. |
| 328 | 327 |
| 329 Args: | 328 Args: |
| 330 target: String representation of the board. This includes host and board | 329 target: String representation of the board. This includes host and board |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 binhost_conf = os.path.join(build_path, _BINHOST_CONF_DIR, 'host', | 407 binhost_conf = os.path.join(build_path, _BINHOST_CONF_DIR, 'host', |
| 409 '%s.conf' % _HOST_TARGET) | 408 '%s.conf' % _HOST_TARGET) |
| 410 else: | 409 else: |
| 411 board_path = os.path.join(build_path, _BOARD_PATH % {'board': board}) | 410 board_path = os.path.join(build_path, _BOARD_PATH % {'board': board}) |
| 412 package_path = os.path.join(board_path, 'packages') | 411 package_path = os.path.join(board_path, 'packages') |
| 413 package_string = board | 412 package_string = board |
| 414 url_suffix = _REL_BOARD_PATH % {'board': board, 'version': version} | 413 url_suffix = _REL_BOARD_PATH % {'board': board, 'version': version} |
| 415 git_file = os.path.join(build_path, DetermineMakeConfFile(board)) | 414 git_file = os.path.join(build_path, DetermineMakeConfFile(board)) |
| 416 binhost_conf = os.path.join(build_path, _BINHOST_CONF_DIR, 'target', | 415 binhost_conf = os.path.join(build_path, _BINHOST_CONF_DIR, 'target', |
| 417 '%s.conf' % board) | 416 '%s.conf' % board) |
| 418 remote_location = urlparse.urljoin(upload_location, url_suffix) | 417 remote_location = '%s/%s' % (upload_location.rstrip('/'), url_suffix) |
| 419 | 418 |
| 420 # Process Packages file, removing duplicates and filtered packages. | 419 # Process Packages file, removing duplicates and filtered packages. |
| 421 pkg_index = GrabLocalPackageIndex(package_path) | 420 pkg_index = GrabLocalPackageIndex(package_path) |
| 422 pkg_index.SetUploadLocation(binhost_base_url, url_suffix) | 421 pkg_index.SetUploadLocation(binhost_base_url, url_suffix) |
| 423 pkg_index.RemoveFilteredPackages(lambda pkg: ShouldFilterPackage(pkg)) | 422 pkg_index.RemoveFilteredPackages(lambda pkg: ShouldFilterPackage(pkg)) |
| 424 uploads = pkg_index.ResolveDuplicateUploads(pkg_indexes) | 423 uploads = pkg_index.ResolveDuplicateUploads(pkg_indexes) |
| 425 | 424 |
| 426 # Write Packages file. | 425 # Write Packages file. |
| 427 tmp_packages_file = pkg_index.WriteToNamedTemporaryFile() | 426 tmp_packages_file = pkg_index.WriteToNamedTemporaryFile() |
| 428 | 427 |
| 429 if upload_location.startswith('gs://'): | 428 if upload_location.startswith('gs://'): |
| 430 # Build list of files to upload. | 429 # Build list of files to upload. |
| 431 upload_files = GenerateUploadDict(package_path, remote_location, uploads) | 430 upload_files = GenerateUploadDict(package_path, remote_location, uploads) |
| 432 remote_file = urlparse.urljoin(remote_location, 'Packages') | 431 remote_file = '%s/Packages' % remote_location.rstrip('/') |
| 433 upload_files[tmp_packages_file.name] = remote_file | 432 upload_files[tmp_packages_file.name] = remote_file |
| 434 | 433 |
| 435 print 'Uploading %s' % package_string | 434 print 'Uploading %s' % package_string |
| 436 failed_uploads = RemoteUpload(upload_files) | 435 failed_uploads = RemoteUpload(upload_files) |
| 437 if len(failed_uploads) > 1 or (None not in failed_uploads): | 436 if len(failed_uploads) > 1 or (None not in failed_uploads): |
| 438 error_msg = ['%s -> %s\n' % args for args in failed_uploads] | 437 error_msg = ['%s -> %s\n' % args for args in failed_uploads] |
| 439 raise UploadFailed('Error uploading:\n%s' % error_msg) | 438 raise UploadFailed('Error uploading:\n%s' % error_msg) |
| 440 else: | 439 else: |
| 441 pkgs = ' '.join(p['CPV'] + '.tbz2' for p in uploads) | 440 pkgs = ' '.join(p['CPV'] + '.tbz2' for p in uploads) |
| 442 ssh_server, remote_path = remote_location.split(':', 1) | 441 ssh_server, remote_path = remote_location.split(':', 1) |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 if options.board: | 532 if options.board: |
| 534 UploadPrebuilt(options.build_path, options.upload, version, | 533 UploadPrebuilt(options.build_path, options.upload, version, |
| 535 options.binhost_base_url, board=options.board, | 534 options.binhost_base_url, board=options.board, |
| 536 git_sync=options.git_sync, key=options.key, | 535 git_sync=options.git_sync, key=options.key, |
| 537 pkg_indexes=pkg_indexes, | 536 pkg_indexes=pkg_indexes, |
| 538 sync_binhost_conf=options.sync_binhost_conf) | 537 sync_binhost_conf=options.sync_binhost_conf) |
| 539 | 538 |
| 540 | 539 |
| 541 if __name__ == '__main__': | 540 if __name__ == '__main__': |
| 542 main() | 541 main() |
| OLD | NEW |