WebKitTools/BuildSlaveSupport/test-result-archive
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     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
       
    27 
       
    28 sourceRootDirectory = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
       
    29 layoutTestResultsDir = os.path.abspath(os.path.join(sourceRootDirectory, "layout-test-results"))
       
    30 archiveFile = os.path.join(sourceRootDirectory, "layout-test-results.zip")
       
    31 
       
    32 def main():
       
    33     parser = optparse.OptionParser("usage: %prog [options] [action]")
       
    34     parser.add_option("--platform", dest="platform")
       
    35     parser.add_option("--debug", action="store_const", const="debug", dest="configuration")
       
    36     parser.add_option("--release", action="store_const", const="release", dest="configuration")
       
    37 
       
    38     options, (action, ) = parser.parse_args()
       
    39     if not options.platform:
       
    40         parser.error("Platform is required")
       
    41     if not options.configuration:
       
    42         parser.error("Configuration is required")
       
    43     if action not in ('archive'):
       
    44         parser.error("Action is required")
       
    45 
       
    46     return archiveTestResults(options.configuration, options.platform)
       
    47 
       
    48 def archiveTestResults(configuration, platform):
       
    49     assert platform in ('mac', 'win', 'gtk', 'qt', 'chromium')
       
    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', 'gtk', 'qt', 'chromium'):
       
    70         if subprocess.call(["zip", "-r", archiveFile, "."], cwd=layoutTestResultsDir):
       
    71             return 1
       
    72 
       
    73     try:
       
    74         shutil.rmtree(layoutTestResultsDir)
       
    75     except OSError, e:
       
    76 
       
    77         # Python in Cygwin throws a mysterious exception with errno of 90
       
    78         # when removing the layout test result directory after successfully
       
    79         # deleting its contents, claiming "Directory not empty".
       
    80         # We can safely ignore this since it was the directory contents that
       
    81         # we are most interested in deleting.
       
    82         if e.errno != 90:
       
    83             raise
       
    84 
       
    85 if __name__ == '__main__':
       
    86     sys.exit(main())