Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/python | |
| 2 | |
| 3 # Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
|
ricow1
2014/05/22 12:40:19
use dart copyright notice?
Bill Hesse
2014/05/22 12:59:37
Done.
| |
| 4 # Use of this source code is governed by a BSD-style license that can be | |
| 5 # found in the LICENSE file. | |
| 6 | |
| 7 """Download archived multivm or dartium builds. | |
| 8 | |
| 9 Usage: download_multivm.py revision build_directory target_directory | |
| 10 """ | |
| 11 | |
| 12 import os | |
| 13 import platform | |
| 14 import shutil | |
| 15 import subprocess | |
| 16 import sys | |
| 17 | |
| 18 BUILDER_NAME = 'BUILDBOT_BUILDERNAME' | |
| 19 | |
| 20 if platform.system() == 'Windows': | |
| 21 GSUTIL = 'e:\\b\\build\\scripts\\slave\\gsutil.bat' | |
| 22 else: | |
| 23 GSUTIL = '/b/build/scripts/slave/gsutil' | |
| 24 | |
| 25 GS_SITE = 'gs://' | |
| 26 GS_BUCKET = 'dartium-archive' | |
| 27 # We are in [checkout dir]/src/dart/tools/dartium in a dartium/multivm checkout | |
| 28 SRC_DIR = os.path.dirname( | |
| 29 os.path.dirname( | |
| 30 os.path.dirname( | |
| 31 os.path.dirname(__file__)))) | |
| 32 | |
| 33 def DownloadArchive(bucket, revision, build_dir, target_dir): | |
| 34 dartium_bucket = bucket.replace('multivm', 'multivm-dartium') | |
| 35 dartium_archive = dartium_bucket + '-' + revision + '.zip' | |
| 36 | |
| 37 source = '/'.join([GS_SITE + GS_BUCKET, dartium_bucket, dartium_archive]) | |
| 38 zip_file = '/'.join([build_dir, dartium_archive]) | |
| 39 | |
| 40 if not os.path.exists(GSUTIL): | |
| 41 print('download_multivm.py must be run in a dartium or multivm checkout' | |
| 42 ' on a buildbot slave. Could not find gsutil at %s' % GSUTIL) | |
| 43 cmd = [GSUTIL, 'cp', source, zip_file] | |
| 44 (status, output) = ExecuteCommand(cmd) | |
| 45 if status: | |
| 46 print output | |
| 47 return status | |
| 48 unzip_result_dir = zip_file.replace('.zip', '') | |
| 49 if os.path.exists(unzip_result_dir): | |
| 50 shutil.rmtree(unzip_result_dir) | |
| 51 | |
| 52 if platform.system() == 'Windows': | |
| 53 executable = os.path.join(SRC_DIR, 'third_party', 'lzma_sdk', | |
| 54 'Executable', '7za.exe') | |
| 55 cmd = [executable, 'x', '-aoa', '-o%s' % build_dir, zip_file] | |
| 56 else: | |
| 57 cmd = ['unzip', zip_file, '-d', build_dir] | |
| 58 (status, output) = ExecuteCommand(cmd) | |
| 59 if status: | |
| 60 print output | |
| 61 return status | |
| 62 os.remove(zip_file) | |
| 63 if os.path.exists(target_dir): | |
| 64 shutil.rmtree(target_dir) | |
| 65 shutil.move(zip_file.replace('.zip', ''), target_dir) | |
| 66 return 0 | |
| 67 | |
| 68 | |
| 69 def ExecuteCommand(cmd): | |
| 70 """Execute a command in a subprocess. | |
| 71 """ | |
| 72 print 'Executing: ' + ' '.join(cmd) | |
|
ricow1
2014/05/22 12:40:19
I suggest that we just use
subprocess.check_output
Bill Hesse
2014/05/22 12:59:37
Done.
| |
| 73 try: | |
| 74 pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
| 75 (output, error) = pipe.communicate() | |
| 76 if pipe.returncode != 0: | |
| 77 print 'Execution failed: ' + str(error) | |
| 78 return (pipe.returncode, output) | |
| 79 except: | |
| 80 import traceback | |
| 81 print 'Execution raised exception:', traceback.format_exc() | |
| 82 return (-1, '') | |
| 83 | |
| 84 def main(): | |
| 85 revision = sys.argv[1] | |
| 86 build_dir = sys.argv[2] | |
| 87 target_dir = sys.argv[3] | |
| 88 bucket = os.environ[BUILDER_NAME].replace('linux', 'lucid64') | |
| 89 return DownloadArchive(bucket, revision, build_dir, target_dir) | |
| 90 | |
| 91 if __name__ == '__main__': | |
| 92 sys.exit(main()) | |
| OLD | NEW |