checkbuildd.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #
  2. # checkbuildd.py - Check buildd.debian.org for successful past builds
  3. #
  4. # Written by Chris Lawrence <lawrencc@debian.org>
  5. # (C) 2002-08 Chris Lawrence
  6. # Copyright (C) 2008-2016 Sandro Tosi <morph@debian.org>
  7. #
  8. # This program is freely distributable per the following license:
  9. #
  10. # Permission to use, copy, modify, and distribute this software and its
  11. # documentation for any purpose and without fee is hereby granted,
  12. # provided that the above copyright notice appears in all copies and that
  13. # both that copyright notice and this permission notice appear in
  14. # supporting documentation.
  15. #
  16. # I DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL I
  18. # BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
  19. # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20. # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  21. # ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  22. # SOFTWARE.
  23. import sgmllib
  24. import commands
  25. import utils
  26. from urlutils import open_url
  27. from reportbug.exceptions import (
  28. NoNetwork,
  29. )
  30. BUILDD_URL = 'https://buildd.debian.org/build.php?arch=%s&pkg=%s'
  31. # Check for successful in a 'td' block
  32. class BuilddParser(sgmllib.SGMLParser):
  33. def __init__(self):
  34. sgmllib.SGMLParser.__init__(self)
  35. self.versions = {}
  36. self.savedata = None
  37. self.found_succeeded = False
  38. # --- Formatter interface, taking care of 'savedata' mode;
  39. # shouldn't need to be overridden
  40. def handle_data(self, data):
  41. if self.savedata is not None:
  42. self.savedata = self.savedata + data
  43. # --- Hooks to save data; shouldn't need to be overridden
  44. def save_bgn(self):
  45. self.savedata = ''
  46. def save_end(self, mode=0):
  47. data = self.savedata
  48. self.savedata = None
  49. if not mode and data is not None:
  50. data = ' '.join(data.split())
  51. return data
  52. def start_td(self, attrs):
  53. self.save_bgn()
  54. def end_td(self):
  55. data = self.save_end()
  56. if data and 'successful' in data.lower():
  57. self.found_succeeded = True
  58. def check_built(src_package, timeout, arch=None, http_proxy=None):
  59. """Return True if built in the past, False otherwise (even error)"""
  60. if not arch:
  61. arch = utils.get_arch()
  62. try:
  63. page = open_url(BUILDD_URL % (arch, src_package), http_proxy, timeout)
  64. except NoNetwork:
  65. return False
  66. if not page:
  67. return False
  68. parser = BuilddParser()
  69. parser.feed(page.read())
  70. parser.close()
  71. page.close()
  72. return parser.found_succeeded