3 # Copyright (C) 2009 Apple Inc. All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
16 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
19 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 import optparse, os, shutil, subprocess, sys, zipfile
28 sourceRootDirectory = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
29 archiveFile = os.path.join(sourceRootDirectory, "layout-test-results.zip")
32 parser = optparse.OptionParser("usage: %prog [options] [action]")
33 parser.add_option("--platform", dest="platform")
34 parser.add_option("--debug", action="store_const", const="debug", dest="configuration")
35 parser.add_option("--release", action="store_const", const="release", dest="configuration")
37 options, (action, ) = parser.parse_args()
38 if not options.platform:
39 parser.error("Platform is required")
40 if not options.configuration:
41 parser.error("Configuration is required")
42 if action not in ('archive'):
43 parser.error("Action is required")
45 layoutTestResultsDir = os.path.abspath(os.path.join(sourceRootDirectory, "layout-test-results"))
46 return archiveTestResults(options.configuration, options.platform, layoutTestResultsDir)
48 def archiveTestResults(configuration, platform, layoutTestResultsDir):
49 assert platform in ('mac', 'win', 'wincairo', 'gtk', 'qt', 'chromium', 'efl')
52 os.unlink(archiveFile)
58 # Ensure that layoutTestResultsDir exists since we cannot archive a directory that does not exist
59 os.makedirs(layoutTestResultsDir)
64 open(os.path.join(layoutTestResultsDir, '.placeholder'), 'w').close()
67 if subprocess.call(["ditto", "-c", "-k", "--sequesterRsrc", layoutTestResultsDir, archiveFile]):
69 elif platform in ('win', 'wincairo', 'gtk', 'qt', 'efl'):
70 if subprocess.call(["zip", "-r", archiveFile, "."], cwd=layoutTestResultsDir):
72 elif platform == 'chromium':
74 os.chdir(layoutTestResultsDir)
75 zipFilesRecursively(archiveFile, ["."])
79 shutil.rmtree(layoutTestResultsDir)
82 # Python in Cygwin throws a mysterious exception with errno of 90
83 # when removing the layout test result directory after successfully
84 # deleting its contents, claiming "Directory not empty".
85 # We can safely ignore this since it was the directory contents that
86 # we are most interested in deleting.
87 # Python in Cygwin will also sometimes throw errno 2 if a process is
88 # holding a file open. There's no point in failing to create the
89 # archive just because some other process is behaving badly. See
90 # <http://webkit.org/b/55581>.
91 if e.errno != 90 and e.errno != 2:
94 def zipFilesRecursively(archiveFile, files):
95 """Make a zip archive.
98 archiveFile: The resultant zip archive file name.
99 files: A list of files to be archived. If a list item is a directory,
100 files in the directory are archived recursively."""
101 zipper = zipfile.ZipFile(archiveFile, 'w', zipfile.ZIP_DEFLATED)
103 if os.path.isdir(file):
104 for dirPath, dirNames, fileNames in os.walk(file):
105 for fileName in fileNames:
106 relativePath = os.path.join(dirPath, fileName)
107 print "Adding", relativePath
108 zipper.write(relativePath)
113 print "Created zip archive: ", archiveFile
115 if __name__ == '__main__':