| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 3 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 4 # for details. All rights reserved. Use of this source code is governed by a | 4 # for details. All rights reserved. Use of this source code is governed by a |
| 5 # BSD-style license that can be found in the LICENSE file. | 5 # BSD-style license that can be found in the LICENSE file. |
| 6 | 6 |
| 7 # Gets or updates a DumpRenderTree (a nearly headless build of chrome). This is | 7 # Gets or updates a DumpRenderTree (a nearly headless build of chrome). This is |
| 8 # used for running browser tests of client applications. | 8 # used for running browser tests of client applications. |
| 9 | 9 |
| 10 import optparse | 10 import optparse |
| 11 import os | 11 import os |
| 12 import platform | 12 import platform |
| 13 import shutil | 13 import shutil |
| 14 import subprocess | 14 import subprocess |
| 15 import sys | 15 import sys |
| 16 import tempfile | 16 import tempfile |
| 17 import zipfile | |
| 18 | 17 |
| 19 def NormJoin(path1, path2): | 18 def NormJoin(path1, path2): |
| 20 return os.path.normpath(os.path.join(path1, path2)) | 19 return os.path.normpath(os.path.join(path1, path2)) |
| 21 | 20 |
| 22 # Change into the dart directory as we want the project to be rooted here. | 21 # Change into the dart directory as we want the project to be rooted here. |
| 23 dart_src = NormJoin(os.path.dirname(sys.argv[0]), os.pardir) | 22 dart_src = NormJoin(os.path.dirname(sys.argv[0]), os.pardir) |
| 24 os.chdir(dart_src) | 23 os.chdir(dart_src) |
| 25 | 24 |
| 26 GSUTIL_DIR = os.path.join('third_party', 'gsutil') | 25 GSUTIL_DIR = 'third_party/gsutil' |
| 27 GSUTIL = GSUTIL_DIR + '/gsutil' | 26 GSUTIL = GSUTIL_DIR + '/gsutil' |
| 28 | 27 |
| 29 DRT_DIR = os.path.join('client', 'tests', 'drt') | 28 DRT_DIR = 'client/tests/drt' |
| 30 DRT_VERSION = os.path.join(DRT_DIR, 'LAST_VERSION') | 29 DRT_VERSION = DRT_DIR + '/LAST_VERSION' |
| 31 DRT_LATEST_PATTERN = ( | 30 DRT_LATEST_PATTERN = ( |
| 32 'gs://dartium-archive/latest/drt-%(osname)s-inc-*.zip') | 31 'gs://dartium-archive/latest/drt-%(osname)s-inc-*.zip') |
| 33 DRT_PERMANENT_PREFIX = 'gs://dartium-archive/drt-%(osname)s-inc' | 32 DRT_PERMANENT_PREFIX = 'gs://dartium-archive/drt-%(osname)s-inc' |
| 34 | 33 |
| 35 DARTIUM_DIR = os.path.join('client', 'tests', 'dartium') | 34 DARTIUM_DIR = 'client/tests/dartium' |
| 36 DARTIUM_VERSION = os.path.join(DARTIUM_DIR, 'LAST_VERSION') | 35 DARTIUM_VERSION = DARTIUM_DIR + '/LAST_VERSION' |
| 37 DARTIUM_LATEST_PATTERN = ( | 36 DARTIUM_LATEST_PATTERN = ( |
| 38 'gs://dartium-archive/latest/dartium-%(osname)s-inc-*.zip') | 37 'gs://dartium-archive/latest/dartium-%(osname)s-inc-*.zip') |
| 39 DARTIUM_PERMANENT_PREFIX = 'gs://dartium-archive/dartium-%(osname)s-inc' | 38 DARTIUM_PERMANENT_PREFIX = 'gs://dartium-archive/dartium-%(osname)s-inc' |
| 40 | 39 |
| 41 sys.path.append(os.path.join(GSUTIL_DIR, 'boto')) | 40 sys.path.append(GSUTIL_DIR + '/boto') |
| 42 import boto | 41 import boto |
| 43 | 42 |
| 44 | 43 |
| 45 def execute_command(*cmd): | 44 def execute_command(*cmd): |
| 46 """Execute a command in a subprocess.""" | 45 """Execute a command in a subprocess.""" |
| 47 pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | 46 pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 48 output, error = pipe.communicate() | 47 output, error = pipe.communicate() |
| 49 return pipe.returncode, output | 48 return pipe.returncode, output |
| 50 | 49 |
| 51 | 50 |
| 52 def execute_command_visible(*cmd): | 51 def execute_command_visible(*cmd): |
| 53 """Execute a command in a subprocess, but show stdout/stderr.""" | 52 """Execute a command in a subprocess, but show stdout/stderr.""" |
| 54 result = subprocess.call(cmd, stdout=sys.stdout, stderr=sys.stderr, | 53 result = subprocess.call(cmd, stdout=sys.stdout, stderr=sys.stderr, |
| 55 stdin=sys.stdin) | 54 stdin=sys.stdin) |
| 56 if result != 0: | 55 if result != 0: |
| 57 raise Exception('Execution of "%s" failed' % ' '.join(cmd)) | 56 raise Exception('Execution of "%s" failed' % ' '.join(cmd)) |
| 58 | 57 |
| 59 | 58 |
| 60 def gsutil(*cmd): | 59 def gsutil(*cmd): |
| 61 return execute_command('python', GSUTIL, *cmd) | 60 return execute_command(GSUTIL, *cmd) |
| 62 | 61 |
| 63 | 62 |
| 64 def gsutil_visible(*cmd): | 63 def gsutil_visible(*cmd): |
| 65 execute_command_visible('python', GSUTIL, *cmd) | 64 execute_command_visible(GSUTIL, *cmd) |
| 66 | 65 |
| 67 | 66 |
| 68 def has_boto_config(): | 67 def has_boto_config(): |
| 69 """Returns true if boto config exists.""" | 68 """Returns true if boto config exists.""" |
| 70 | 69 |
| 71 config_paths = boto.pyami.config.BotoConfigLocations | 70 config_paths = boto.pyami.config.BotoConfigLocations |
| 72 if 'AWS_CREDENTIAL_FILE' in os.environ: | 71 if 'AWS_CREDENTIAL_FILE' in os.environ: |
| 73 config_paths.append(os.environ['AWS_CREDENTIAL_FILE']) | 72 config_paths.append(os.environ['AWS_CREDENTIAL_FILE']) |
| 74 for config_path in config_paths: | 73 for config_path in config_paths: |
| 75 if os.path.exists(config_path): | 74 if os.path.exists(config_path): |
| (...skipping 30 matching lines...) Expand all Loading... |
| 106 directory: target directory (recreated) to install binary | 105 directory: target directory (recreated) to install binary |
| 107 version_file: name of file with the current version stamp | 106 version_file: name of file with the current version stamp |
| 108 latest_pattern: the google store url pattern pointing to the latest binary | 107 latest_pattern: the google store url pattern pointing to the latest binary |
| 109 permanent_prefix: stable google store folder used to download versions | 108 permanent_prefix: stable google store folder used to download versions |
| 110 """ | 109 """ |
| 111 system = platform.system() | 110 system = platform.system() |
| 112 if system == 'Darwin': | 111 if system == 'Darwin': |
| 113 osname = 'mac' | 112 osname = 'mac' |
| 114 elif system == 'Linux': | 113 elif system == 'Linux': |
| 115 osname = 'lucid64' | 114 osname = 'lucid64' |
| 116 elif system == 'Windows': | |
| 117 osname = 'win' | |
| 118 else: | 115 else: |
| 119 print >>sys.stderr, ('WARNING: platform "%s" does not support' | 116 print >>sys.stderr, ('WARNING: platform "%s" does not support' |
| 120 '%s for tests') % (system, name) | 117 '%s for tests') % (system, name) |
| 121 return 0 | 118 return 0 |
| 122 | 119 |
| 123 ensure_config() | 120 ensure_config() |
| 124 | 121 |
| 125 # Query for the lastest version | 122 # Query for the lastest version |
| 126 pattern = latest_pattern % { 'osname' : osname } | 123 pattern = latest_pattern % { 'osname' : osname } |
| 127 result, out = gsutil('ls', pattern) | 124 result, out = gsutil('ls', pattern) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 145 print name + ' is up to date.\nVersion: ' + latest | 142 print name + ' is up to date.\nVersion: ' + latest |
| 146 return 0 # up to date | 143 return 0 # up to date |
| 147 | 144 |
| 148 if os.path.exists(directory): | 145 if os.path.exists(directory): |
| 149 print 'Removing old %s tree %s' % (name, directory) | 146 print 'Removing old %s tree %s' % (name, directory) |
| 150 shutil.rmtree(directory) | 147 shutil.rmtree(directory) |
| 151 | 148 |
| 152 # download the zip file to a temporary path, and unzip to the target location | 149 # download the zip file to a temporary path, and unzip to the target location |
| 153 temp_dir = tempfile.mkdtemp() | 150 temp_dir = tempfile.mkdtemp() |
| 154 try: | 151 try: |
| 155 temp_zip = os.path.join(temp_dir, 'drt.zip') | 152 temp_zip = temp_dir + '/drt.zip' |
| 156 temp_zip_url = 'file://' + temp_zip | |
| 157 # It's nice to show download progress | 153 # It's nice to show download progress |
| 158 gsutil_visible('cp', latest, temp_zip_url) | 154 gsutil_visible('cp', latest, temp_zip) |
| 159 | 155 |
| 160 z = zipfile.ZipFile(temp_zip) | 156 result, out = execute_command('unzip', temp_zip, '-d', temp_dir) |
| 161 z.extractall(temp_dir) | 157 if result != 0: |
| 162 # remove .zip for dir name | 158 raise Exception('Execution of "unzip %s -d %s" failed: %s' % |
| 163 unzipped_dir = os.path.join(temp_dir, os.path.basename(latest)[:-4]) | 159 (temp_zip, temp_dir, str(out))) |
| 164 z.close() | 160 unzipped_dir = temp_dir + '/' + os.path.basename(latest)[:-4] # remove .zip |
| 165 shutil.move(unzipped_dir, directory) | 161 shutil.move(unzipped_dir, directory) |
| 166 finally: | 162 finally: |
| 167 shutil.rmtree(temp_dir) | 163 shutil.rmtree(temp_dir) |
| 168 | 164 |
| 169 # create the version stamp | 165 # create the version stamp |
| 170 v = open(version_file, 'w') | 166 v = open(version_file, 'w') |
| 171 v.write(latest) | 167 v.write(latest) |
| 172 v.close() | 168 v.close() |
| 173 | 169 |
| 174 print 'Successfully downloaded to %s' % directory | 170 print 'Successfully downloaded to %s' % directory |
| 175 return 0 | 171 return 0 |
| 176 | 172 |
| 177 | 173 |
| 178 def main(): | 174 def main(): |
| 179 parser = optparse.OptionParser() | 175 parser = optparse.OptionParser() |
| 180 parser.add_option('--dartium', dest='dartium', | 176 parser.add_option('--dartium', dest='dartium', |
| 181 help='Get latest Dartium', action='store_true', | 177 help='Get latest Dartium', action='store_true', |
| 182 default=False) | 178 default=False) |
| 183 args, _ = parser.parse_args() | 179 args, _ = parser.parse_args() |
| 184 | 180 |
| 185 if args.dartium: | 181 if args.dartium: |
| 186 get_latest('Dartium', DARTIUM_DIR, DARTIUM_VERSION, | 182 get_latest('Dartium', DARTIUM_DIR, DARTIUM_VERSION, |
| 187 DARTIUM_LATEST_PATTERN, DARTIUM_PERMANENT_PREFIX) | 183 DARTIUM_LATEST_PATTERN, DARTIUM_PERMANENT_PREFIX) |
| 188 else: | 184 else: |
| 189 get_latest('DumpRenderTree', DRT_DIR, DRT_VERSION, | 185 get_latest('DumpRenderTree', DRT_DIR, DRT_VERSION, |
| 190 DRT_LATEST_PATTERN, DRT_PERMANENT_PREFIX) | 186 DRT_LATEST_PATTERN, DRT_PERMANENT_PREFIX) |
| 191 | 187 |
| 192 if __name__ == '__main__': | 188 if __name__ == '__main__': |
| 193 sys.exit(main()) | 189 sys.exit(main()) |
| OLD | NEW |