Chromium Code Reviews| 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 | |
| 17 | 18 |
| 18 def NormJoin(path1, path2): | 19 def NormJoin(path1, path2): |
| 19 return os.path.normpath(os.path.join(path1, path2)) | 20 return os.path.normpath(os.path.join(path1, path2)) |
| 20 | 21 |
| 21 # Change into the dart directory as we want the project to be rooted here. | 22 # Change into the dart directory as we want the project to be rooted here. |
| 22 dart_src = NormJoin(os.path.dirname(sys.argv[0]), os.pardir) | 23 dart_src = NormJoin(os.path.dirname(sys.argv[0]), os.pardir) |
| 23 os.chdir(dart_src) | 24 os.chdir(dart_src) |
| 24 | 25 |
| 25 GSUTIL_DIR = 'third_party/gsutil' | 26 GSUTIL_DIR = os.path.join('third_party', 'gsutil') |
| 26 GSUTIL = GSUTIL_DIR + '/gsutil' | 27 GSUTIL = GSUTIL_DIR + '/gsutil' |
| 27 | 28 |
| 28 DRT_DIR = 'client/tests/drt' | 29 DRT_DIR = os.path.join('client', 'tests', 'drt') |
| 29 DRT_VERSION = DRT_DIR + '/LAST_VERSION' | 30 DRT_VERSION = os.path.join(DRT_DIR, 'LAST_VERSION') |
| 30 DRT_LATEST_PATTERN = ( | 31 DRT_LATEST_PATTERN = ( |
| 31 'gs://dartium-archive/latest/drt-%(osname)s-inc-*.zip') | 32 'gs://dartium-archive/latest/drt-%(osname)s-inc-*.zip') |
| 32 DRT_PERMANENT_PREFIX = 'gs://dartium-archive/drt-%(osname)s-inc' | 33 DRT_PERMANENT_PREFIX = 'gs://dartium-archive/drt-%(osname)s-inc' |
| 33 | 34 |
| 34 DARTIUM_DIR = 'client/tests/dartium' | 35 DARTIUM_DIR = os.path.join('client', 'tests', 'dartium') |
| 35 DARTIUM_VERSION = DARTIUM_DIR + '/LAST_VERSION' | 36 DARTIUM_VERSION = os.path.join(DARTIUM_DIR, 'LAST_VERSION') |
| 36 DARTIUM_LATEST_PATTERN = ( | 37 DARTIUM_LATEST_PATTERN = ( |
| 37 'gs://dartium-archive/latest/dartium-%(osname)s-inc-*.zip') | 38 'gs://dartium-archive/latest/dartium-%(osname)s-inc-*.zip') |
| 38 DARTIUM_PERMANENT_PREFIX = 'gs://dartium-archive/dartium-%(osname)s-inc' | 39 DARTIUM_PERMANENT_PREFIX = 'gs://dartium-archive/dartium-%(osname)s-inc' |
| 39 | 40 |
| 40 sys.path.append(GSUTIL_DIR + '/boto') | 41 sys.path.append(os.path.join(GSUTIL_DIR, 'boto')) |
| 41 import boto | 42 import boto |
| 42 | 43 |
| 43 | 44 |
| 44 def execute_command(*cmd): | 45 def execute_command(*cmd): |
| 45 """Execute a command in a subprocess.""" | 46 """Execute a command in a subprocess.""" |
| 46 pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | 47 pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 47 output, error = pipe.communicate() | 48 output, error = pipe.communicate() |
| 48 return pipe.returncode, output | 49 return pipe.returncode, output |
| 49 | 50 |
| 50 | 51 |
| 51 def execute_command_visible(*cmd): | 52 def execute_command_visible(*cmd): |
| 52 """Execute a command in a subprocess, but show stdout/stderr.""" | 53 """Execute a command in a subprocess, but show stdout/stderr.""" |
| 53 result = subprocess.call(cmd, stdout=sys.stdout, stderr=sys.stderr, | 54 result = subprocess.call(cmd, stdout=sys.stdout, stderr=sys.stderr, |
| 54 stdin=sys.stdin) | 55 stdin=sys.stdin) |
| 55 if result != 0: | 56 if result != 0: |
| 56 raise Exception('Execution of "%s" failed' % ' '.join(cmd)) | 57 raise Exception('Execution of "%s" failed' % ' '.join(cmd)) |
| 57 | 58 |
| 58 | 59 |
| 59 def gsutil(*cmd): | 60 def gsutil(*cmd): |
| 60 return execute_command(GSUTIL, *cmd) | 61 return execute_command('python', GSUTIL, *cmd) |
| 61 | 62 |
| 62 | 63 |
| 63 def gsutil_visible(*cmd): | 64 def gsutil_visible(*cmd): |
| 64 execute_command_visible(GSUTIL, *cmd) | 65 execute_command_visible('python', GSUTIL, *cmd) |
| 65 | 66 |
| 66 | 67 |
| 67 def has_boto_config(): | 68 def has_boto_config(): |
| 68 """Returns true if boto config exists.""" | 69 """Returns true if boto config exists.""" |
| 69 | 70 |
| 70 config_paths = boto.pyami.config.BotoConfigLocations | 71 config_paths = boto.pyami.config.BotoConfigLocations |
| 71 if 'AWS_CREDENTIAL_FILE' in os.environ: | 72 if 'AWS_CREDENTIAL_FILE' in os.environ: |
| 72 config_paths.append(os.environ['AWS_CREDENTIAL_FILE']) | 73 config_paths.append(os.environ['AWS_CREDENTIAL_FILE']) |
| 73 for config_path in config_paths: | 74 for config_path in config_paths: |
| 74 if os.path.exists(config_path): | 75 if os.path.exists(config_path): |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 105 directory: target directory (recreated) to install binary | 106 directory: target directory (recreated) to install binary |
| 106 version_file: name of file with the current version stamp | 107 version_file: name of file with the current version stamp |
| 107 latest_pattern: the google store url pattern pointing to the latest binary | 108 latest_pattern: the google store url pattern pointing to the latest binary |
| 108 permanent_prefix: stable google store folder used to download versions | 109 permanent_prefix: stable google store folder used to download versions |
| 109 """ | 110 """ |
| 110 system = platform.system() | 111 system = platform.system() |
| 111 if system == 'Darwin': | 112 if system == 'Darwin': |
| 112 osname = 'mac' | 113 osname = 'mac' |
| 113 elif system == 'Linux': | 114 elif system == 'Linux': |
| 114 osname = 'lucid64' | 115 osname = 'lucid64' |
| 116 elif system == 'Windows': | |
| 117 osname = 'win' | |
| 115 else: | 118 else: |
| 116 print >>sys.stderr, ('WARNING: platform "%s" does not support' | 119 print >>sys.stderr, ('WARNING: platform "%s" does not support' |
| 117 '%s for tests') % (system, name) | 120 '%s for tests') % (system, name) |
| 118 return 0 | 121 return 0 |
| 119 | 122 |
| 120 ensure_config() | 123 ensure_config() |
| 121 | 124 |
| 122 # Query for the lastest version | 125 # Query for the lastest version |
| 123 pattern = latest_pattern % { 'osname' : osname } | 126 pattern = latest_pattern % { 'osname' : osname } |
| 124 result, out = gsutil('ls', pattern) | 127 result, out = gsutil('ls', pattern) |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 142 print name + ' is up to date.\nVersion: ' + latest | 145 print name + ' is up to date.\nVersion: ' + latest |
| 143 return 0 # up to date | 146 return 0 # up to date |
| 144 | 147 |
| 145 if os.path.exists(directory): | 148 if os.path.exists(directory): |
| 146 print 'Removing old %s tree %s' % (name, directory) | 149 print 'Removing old %s tree %s' % (name, directory) |
| 147 shutil.rmtree(directory) | 150 shutil.rmtree(directory) |
| 148 | 151 |
| 149 # download the zip file to a temporary path, and unzip to the target location | 152 # download the zip file to a temporary path, and unzip to the target location |
| 150 temp_dir = tempfile.mkdtemp() | 153 temp_dir = tempfile.mkdtemp() |
| 151 try: | 154 try: |
| 152 temp_zip = temp_dir + '/drt.zip' | 155 temp_zip = os.path.join(temp_dir, 'drt.zip') |
| 156 temp_zip_url = 'file://' + temp_zip | |
| 153 # It's nice to show download progress | 157 # It's nice to show download progress |
| 154 gsutil_visible('cp', latest, temp_zip) | 158 gsutil_visible('cp', latest, temp_zip_url) |
| 155 | 159 |
| 156 result, out = execute_command('unzip', temp_zip, '-d', temp_dir) | 160 if platform.system() != 'Windows': |
| 157 if result != 0: | 161 # The Python zip utility does not preserve executable permissions, but |
|
Siggi Cherem (dart-lang)
2012/04/25 23:41:00
why did this check go away?
Emily Fortuna
2012/04/26 15:51:49
Ooops, I took it out when I was debugging and forg
| |
| 158 raise Exception('Execution of "unzip %s -d %s" failed: %s' % | 162 # this does not seem to be a problem for Windows, which does not have a |
| 159 (temp_zip, temp_dir, str(out))) | 163 # built in zip utility. :-/ |
|
Emily Fortuna
2012/04/25 23:26:13
This branch is the same from the original.
| |
| 160 unzipped_dir = temp_dir + '/' + os.path.basename(latest)[:-4] # remove .zip | 164 result, out = execute_command('unzip', temp_zip, '-d', temp_dir) |
| 165 unzipped_dir = temp_dir + '/' + os.path.basename(latest)[:-4] #Remove .zip | |
| 166 else: | |
|
Emily Fortuna
2012/04/25 23:26:13
This branch is what I added for Windows. :-/ Every
| |
| 167 z = zipfile.ZipFile(temp_zip) | |
| 168 z.extractall(temp_dir) | |
| 169 # -4 = remove .zip for dir name | |
| 170 unzipped_dir = os.path.join(temp_dir, os.path.basename(latest)[:-4]) | |
| 171 z.close() | |
| 161 shutil.move(unzipped_dir, directory) | 172 shutil.move(unzipped_dir, directory) |
| 162 finally: | 173 finally: |
| 163 shutil.rmtree(temp_dir) | 174 shutil.rmtree(temp_dir) |
| 164 | 175 |
| 165 # create the version stamp | 176 # create the version stamp |
| 166 v = open(version_file, 'w') | 177 v = open(version_file, 'w') |
| 167 v.write(latest) | 178 v.write(latest) |
| 168 v.close() | 179 v.close() |
| 169 | 180 |
| 170 print 'Successfully downloaded to %s' % directory | 181 print 'Successfully downloaded to %s' % directory |
| 171 return 0 | 182 return 0 |
| 172 | 183 |
| 173 | 184 |
| 174 def main(): | 185 def main(): |
| 175 parser = optparse.OptionParser() | 186 parser = optparse.OptionParser() |
| 176 parser.add_option('--dartium', dest='dartium', | 187 parser.add_option('--dartium', dest='dartium', |
| 177 help='Get latest Dartium', action='store_true', | 188 help='Get latest Dartium', action='store_true', |
| 178 default=False) | 189 default=False) |
| 179 args, _ = parser.parse_args() | 190 args, _ = parser.parse_args() |
| 180 | 191 |
| 181 if args.dartium: | 192 if args.dartium: |
| 182 get_latest('Dartium', DARTIUM_DIR, DARTIUM_VERSION, | 193 get_latest('Dartium', DARTIUM_DIR, DARTIUM_VERSION, |
| 183 DARTIUM_LATEST_PATTERN, DARTIUM_PERMANENT_PREFIX) | 194 DARTIUM_LATEST_PATTERN, DARTIUM_PERMANENT_PREFIX) |
| 184 else: | 195 else: |
| 185 get_latest('DumpRenderTree', DRT_DIR, DRT_VERSION, | 196 get_latest('DumpRenderTree', DRT_DIR, DRT_VERSION, |
| 186 DRT_LATEST_PATTERN, DRT_PERMANENT_PREFIX) | 197 DRT_LATEST_PATTERN, DRT_PERMANENT_PREFIX) |
| 187 | 198 |
| 188 if __name__ == '__main__': | 199 if __name__ == '__main__': |
| 189 sys.exit(main()) | 200 sys.exit(main()) |
| OLD | NEW |