11320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#!/usr/bin/env python 21320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# Copyright (C) 2012 Google Inc. All rights reserved. 31320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# 41320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# Redistribution and use in source and binary forms, with or without 51320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# modification, are permitted provided that the following conditions are 61320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# met: 71320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# 81320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# * Redistributions of source code must retain the above copyright 91320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# notice, this list of conditions and the following disclaimer. 101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# * Redistributions in binary form must reproduce the above 111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# copyright notice, this list of conditions and the following disclaimer 121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# in the documentation and/or other materials provided with the 131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# distribution. 141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# * Neither the name of Google Inc. nor the names of its 151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# contributors may be used to endorse or promote products derived from 161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# this software without specific prior written permission. 171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# 181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# This script exports newly added tests to the W3C Web Performance WG's test 311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# suite. 321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# 331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# You must have checked out the 'webperf' repository from https://dvcs.w3.org/hg/ 341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# 351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# This script will export the LayoutTests/http/tests/w3c/submission directory 361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# to a local 'webperf' repository. 371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# 381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# The main step in exporting the tests is updating all of the URLs to account 391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci# for the differences in directory layout. 401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciimport os 421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciimport shutil 431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciimport sys 441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciif len(sys.argv) != 3: 461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci print 'USAGE: %s path_to_webkit_checkout_root path_to_webperf_checkout_root' % sys.argv[0] 47 sys.exit(1) 48 49source_directory = os.path.join(sys.argv[1], 'LayoutTests', 'http', 'tests', 'w3c', 'webperf') 50destination_directory = os.path.join(sys.argv[2], 'tests') 51 52directories_to_copy = ['resources', 'submission'] 53replacements = [ 54 ('localhost:8000', 'www.w3c-test.org'), # This is the alternate host for cross-server requests. 55 ('127.0.0.1:8000', 'w3c-test.org'), # This is the primary test server. 56 ('w3c/webperf', 'webperf/tests'), # We prepend /w3c to all of our paths. 57 ('/w3c/resources/', '/resources/'), 58 ('\n', '\r\n'), # Convert from *NIX format. 59] 60 61for directory_to_copy in directories_to_copy: 62 destination_subdirectory = os.path.join(destination_directory, directory_to_copy) 63 if not os.path.exists(destination_subdirectory): 64 os.makedirs(destination_subdirectory) 65 for root, dirs, files in os.walk(os.path.join(source_directory, directory_to_copy)): 66 root = os.path.relpath(root, source_directory) 67 for dirname in dirs: 68 destination_subdirectory = os.path.join(destination_directory, root, dirname) 69 if not os.path.exists(destination_subdirectory): 70 os.makedirs(destination_subdirectory) 71 for filename in files: 72 if filename.endswith('-expected.txt'): 73 continue 74 with open(os.path.join(source_directory, root, filename), 'r') as in_file: 75 with open(os.path.join(destination_directory, root, filename), 'w') as out_file: 76 for line in in_file: 77 for to_find, replace_with in replacements: 78 line = line.replace(to_find, replace_with) 79 out_file.write(line) 80 print 'Exported %s' % os.path.join(root, filename) 81