[CherryPick] input element with placeholder text and width set to 100% on focus cause...
[framework/web/webkit-efl.git] / Tools / BuildSlaveSupport / test-result-archive
1 #!/usr/bin/python
2
3 # Copyright (C) 2009 Apple Inc.  All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
7 # are met:
8 #
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. 
14 #
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.
25
26 import optparse, os, shutil, subprocess, sys, zipfile
27
28 sourceRootDirectory = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
29 archiveFile = os.path.join(sourceRootDirectory, "layout-test-results.zip")
30
31 def main():
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")
36
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")
44
45     layoutTestResultsDir = os.path.abspath(os.path.join(sourceRootDirectory, "layout-test-results"))
46     return archiveTestResults(options.configuration, options.platform, layoutTestResultsDir)
47
48 def archiveTestResults(configuration, platform, layoutTestResultsDir):
49     assert platform in ('mac', 'win', 'wincairo', 'gtk', 'qt', 'chromium', 'efl')
50
51     try:
52         os.unlink(archiveFile)
53     except OSError, e:
54         if e.errno != 2:
55             raise
56
57     try:
58         # Ensure that layoutTestResultsDir exists since we cannot archive a directory that does not exist
59         os.makedirs(layoutTestResultsDir)
60     except OSError, e:
61         if e.errno != 17:
62             raise
63
64     open(os.path.join(layoutTestResultsDir, '.placeholder'), 'w').close()
65
66     if platform == 'mac':
67         if subprocess.call(["ditto", "-c", "-k", "--sequesterRsrc", layoutTestResultsDir, archiveFile]):
68             return 1
69     elif platform in ('win', 'wincairo', 'gtk', 'qt', 'efl'):
70         if subprocess.call(["zip", "-r", archiveFile, "."], cwd=layoutTestResultsDir):
71             return 1
72     elif platform == 'chromium':
73         cwd = os.getcwd()
74         os.chdir(layoutTestResultsDir)
75         zipFilesRecursively(archiveFile, ["."])
76         os.chdir(cwd)
77
78     try:
79         shutil.rmtree(layoutTestResultsDir)
80     except OSError, e:
81
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:
92             raise
93
94 def zipFilesRecursively(archiveFile, files):
95     """Make a zip archive.
96
97     Args:
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)
102     for file in files:
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)
109         else:
110             print "Adding", file
111             zipper.write(file)
112     zipper.close()
113     print "Created zip archive: ", archiveFile
114
115 if __name__ == '__main__':
116     sys.exit(main())