/external/webkit/WebKitTools/Scripts/webkitpy/statusserver.py

https://github.com/DooMLoRD/Xperia-2011-Official-Kernel-Sources · Python · 96 lines · 50 code · 15 blank · 31 comment · 9 complexity · 0be812379b9bc8e77c33b31369383565 MD5 · raw file

  1. # Copyright (C) 2009 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. # * Redistributions of source code must retain the above copyright
  8. # notice, this list of conditions and the following disclaimer.
  9. # * Redistributions in binary form must reproduce the above
  10. # copyright notice, this list of conditions and the following disclaimer
  11. # in the documentation and/or other materials provided with the
  12. # distribution.
  13. # * Neither the name of Google Inc. nor the names of its
  14. # contributors may be used to endorse or promote products derived from
  15. # this software without specific prior written permission.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  23. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. from webkitpy.networktransaction import NetworkTransaction
  29. from webkitpy.webkit_logging import log
  30. from mechanize import Browser
  31. # WebKit includes a built copy of BeautifulSoup in Scripts/webkitpy
  32. # so this import should always succeed.
  33. from .BeautifulSoup import BeautifulSoup
  34. import urllib2
  35. class StatusServer:
  36. default_host = "webkit-commit-queue.appspot.com"
  37. def __init__(self, host=default_host):
  38. self.set_host(host)
  39. self.browser = Browser()
  40. def set_host(self, host):
  41. self.host = host
  42. self.url = "http://%s" % self.host
  43. def results_url_for_status(self, status_id):
  44. return "%s/results/%s" % (self.url, status_id)
  45. def _add_patch(self, patch):
  46. if not patch:
  47. return
  48. if patch.bug_id():
  49. self.browser["bug_id"] = str(patch.bug_id())
  50. if patch.id():
  51. self.browser["patch_id"] = str(patch.id())
  52. def _add_results_file(self, results_file):
  53. if not results_file:
  54. return
  55. self.browser.add_file(results_file, "text/plain", "results.txt", 'results_file')
  56. def _post_to_server(self, queue_name, status, patch, results_file):
  57. if results_file:
  58. # We might need to re-wind the file if we've already tried to post it.
  59. results_file.seek(0)
  60. update_status_url = "%s/update-status" % self.url
  61. self.browser.open(update_status_url)
  62. self.browser.select_form(name="update_status")
  63. self.browser['queue_name'] = queue_name
  64. self._add_patch(patch)
  65. self.browser['status'] = status
  66. self._add_results_file(results_file)
  67. return self.browser.submit().read() # This is the id of the newly created status object.
  68. def update_status(self, queue_name, status, patch=None, results_file=None):
  69. # During unit testing, host is None
  70. if not self.host:
  71. return
  72. log(status)
  73. return NetworkTransaction().run(lambda: self._post_to_server(queue_name, status, patch, results_file))
  74. def patch_status(self, queue_name, patch_id):
  75. update_status_url = "%s/patch-status/%s/%s" % (self.url, queue_name, patch_id)
  76. try:
  77. return urllib2.urlopen(update_status_url).read()
  78. except urllib2.HTTPError, e:
  79. if e.code == 404:
  80. return None
  81. raise e