Skip to content


Subversion checkout URL

You can clone with
Download ZIP
tree: eb066c5e7f
Fetching contributors…

Cannot retrieve contributors at this time

executable file 167 lines (133 sloc) 5.192 kb
#!/usr/bin/env python
# Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
# Gets or updates a DumpRenderTree (a nearly headless build of chrome). This is
# used for running browser tests of client applications.
import os
import sys
import platform
import errno
import tempfile
import shutil
import subprocess
def NormJoin(path1, path2):
return os.path.normpath(os.path.join(path1, path2))
# Change into the dart directory as we want the project to be rooted here.
dart_src = NormJoin(os.path.dirname(sys.argv[0]), os.pardir)
GSUTIL_DIR = 'third_party/gsutil/20110627'
GSUTIL = GSUTIL_DIR + '/gsutil'
DRT_DIR = 'client/tests/drt'
DRT_DARTIUM_PERMANENT_PREFIX = 'gs://dartium-archive/dartium-%(osname)s-inc'
sys.path.append(GSUTIL_DIR + '/boto')
import boto
def execute_command(*cmd):
"""Execute a command in a subprocess."""
pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, error = pipe.communicate()
return pipe.returncode, output
def execute_command_visible(*cmd):
"""Execute a command in a subprocess, but show stdout/stderr."""
result =, stdout=sys.stdout, stderr=sys.stderr,
if result != 0:
raise Exception('Execution of "%s" failed' % ' '.join(cmd))
def gsutil(*cmd):
return execute_command(GSUTIL, *cmd)
def gsutil_visible(*cmd):
execute_command_visible(GSUTIL, *cmd)
def has_boto_config():
"""Returns true if boto config exists."""
config_paths = boto.pyami.config.BotoConfigLocations
if 'AWS_CREDENTIAL_FILE' in os.environ:
for config_path in config_paths:
if os.path.exists(config_path):
return True
return False
def in_runhooks():
'''True if this script was called by "gclient runhooks" or "gclient sync"'''
return 'runhooks' in sys.argv
def ensure_config():
# If ~/.boto doesn't exist, tell the user to run "gsutil config"
if not has_boto_config():
print >>sys.stderr, '''
* WARNING: Can't download DumpRenderTree! This is required to test client apps.
* You need to do a one-time configuration step to access Google Storage.
* Please run this command and follow the instructions:
* %s config
* NOTE: When prompted you can leave "project-id" blank. Just hit enter.
''' % GSUTIL
def main():
system = platform.system()
if system == 'Darwin':
osname = 'mac'
elif system == 'Linux':
osname = 'lucid64'
print >>sys.stderr, ('WARNING: platform "%s" does not support'
'DumpRenderTree for tests') % system
return 0
# Query for the lastest version
pattern = DRT_DARTIUM_LATEST_PATTERN % { 'osname' : osname }
result, out = gsutil('ls', pattern)
if result == 0:
latest = out.split()[-1]
# use permanent link instead, just in case the latest zip entry gets deleted
# while we are downloading it.
latest = (DRT_DARTIUM_PERMANENT_PREFIX % { 'osname' : osname }
+ latest[latest.rindex('/'):])
else: # e.g. no access
pattern = DRT_CHROMIUM_LATEST_PATTERN % { 'osname' : osname }
result, out = gsutil('ls', pattern)
if result == 0:
latest = out.split()[-1]
print "Couldn't download DumpRenderTree: %s\n%s" % (pattern, out)
if not os.path.exists(VERSION):
print "Tests using arch=chromium will not work. Please try again later."
return 0
# Check if we need to update the file
if os.path.exists(VERSION):
v = open(VERSION, 'r').read()
if v == latest:
if not in_runhooks():
print 'DumpRenderTree is up to date.\nVersion: ' + latest
return 0 # up to date
if os.path.exists(DRT_DIR):
print 'Removing old DumpRenderTree tree %s' % DRT_DIR
# download the zip file to a temporary path, and unzip to the target location
temp_dir = tempfile.mkdtemp()
temp_zip = temp_dir + '/'
# It's nice to show download progress
gsutil_visible('cp', latest, temp_zip)
result, out = execute_command('unzip', temp_zip, '-d', temp_dir)
if result != 0:
raise Exception('Execution of "unzip %s -d %s" failed: %s' %
(temp_zip, temp_dir, str(out)))
unzipped_dir = temp_dir + '/' + os.path.basename(latest)[:-4] # remove .zip
shutil.move(unzipped_dir, DRT_DIR)
# create the version stamp
v = open(VERSION, 'w')
print 'Successfully downloaded to %s' % DRT_DIR
return 0
if __name__ == '__main__':
Jump to Line
Something went wrong with that request. Please try again.