gardeningserver.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # Copyright (C) 2011 Google Inc. All rights reserved.
  2. #
  3. # Redistribution and use in source and binary forms, with or without
  4. # modification, are permitted provided that the following conditions are
  5. # met:
  6. #
  7. # 1. Redistributions of source code must retain the above copyright
  8. # notice, this list of conditions and the following disclaimer.
  9. # 2. Redistributions in binary form must reproduce the above copyright
  10. # notice, this list of conditions and the following disclaimer in the
  11. # documentation and/or other materials provided with the distribution.
  12. #
  13. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  14. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  15. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  16. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  17. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  18. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  19. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  21. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. import BaseHTTPServer
  25. import SocketServer
  26. import logging
  27. import json
  28. import os
  29. import sys
  30. import urllib
  31. from webkitpy.common.memoized import memoized
  32. from webkitpy.tool.servers.reflectionhandler import ReflectionHandler
  33. from webkitpy.port import builders
  34. _log = logging.getLogger(__name__)
  35. class GardeningHTTPServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer):
  36. def __init__(self, httpd_port, config):
  37. server_name = ''
  38. self.tool = config['tool']
  39. self.options = config['options']
  40. BaseHTTPServer.HTTPServer.__init__(self, (server_name, httpd_port), GardeningHTTPRequestHandler)
  41. def url(self, args=None):
  42. # We can't use urllib.encode() here because that encodes spaces as plus signs and the buildbots don't decode those properly.
  43. arg_string = ('?' + '&'.join("%s=%s" % (key, urllib.quote(value)) for (key, value) in args.items())) if args else ''
  44. return 'http://localhost:8127/garden-o-matic.html' + arg_string
  45. class GardeningHTTPRequestHandler(ReflectionHandler):
  46. STATIC_FILE_NAMES = frozenset()
  47. STATIC_FILE_EXTENSIONS = ('.js', '.css', '.html', '.gif', '.png', '.ico')
  48. STATIC_FILE_DIRECTORY = os.path.join(
  49. os.path.dirname(__file__),
  50. '..',
  51. '..',
  52. '..',
  53. '..',
  54. 'BuildSlaveSupport',
  55. 'build.webkit.org-config',
  56. 'public_html',
  57. 'TestFailures')
  58. allow_cross_origin_requests = True
  59. debug_output = ''
  60. def ping(self):
  61. self._serve_text('pong')
  62. def _run_webkit_patch(self, command, input_string):
  63. PIPE = self.server.tool.executive.PIPE
  64. process = self.server.tool.executive.popen([self.server.tool.path()] + command, cwd=self.server.tool.scm().checkout_root, stdin=PIPE, stdout=PIPE, stderr=PIPE)
  65. process.stdin.write(input_string)
  66. output, error = process.communicate()
  67. return (process.returncode, output, error)
  68. def rebaselineall(self):
  69. command = ['rebaseline-json']
  70. if self.server.options.move_overwritten_baselines:
  71. command.append('--move-overwritten-baselines')
  72. if self.server.options.results_directory:
  73. command.extend(['--results-directory', self.server.options.results_directory])
  74. if not self.server.options.optimize:
  75. command.append('--no-optimize')
  76. if self.server.options.verbose:
  77. command.append('--verbose')
  78. json_input = self.read_entity_body()
  79. _log.debug("calling %s, input='%s'", command, json_input)
  80. return_code, output, error = self._run_webkit_patch(command, json_input)
  81. print >> sys.stderr, error
  82. if return_code:
  83. _log.error("rebaseline-json failed: %d, output='%s'" % (return_code, output))
  84. else:
  85. _log.debug("rebaseline-json succeeded")
  86. # FIXME: propagate error and/or log messages back to the UI.
  87. self._serve_text('success')
  88. def localresult(self):
  89. path = self.query['path'][0]
  90. filesystem = self.server.tool.filesystem
  91. # Ensure that we're only serving files from inside the results directory.
  92. if not filesystem.isabs(path) and self.server.options.results_directory:
  93. fullpath = filesystem.abspath(filesystem.join(self.server.options.results_directory, path))
  94. if fullpath.startswith(filesystem.abspath(self.server.options.results_directory)):
  95. self._serve_file(fullpath, headers_only=(self.command == 'HEAD'))
  96. return
  97. self.send_response(403)