You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

89 lines
2.7 KiB

  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-2017 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. from html.parser import HTMLParser
  24. from . import utils
  25. from .urlutils import open_url
  26. from reportbug.exceptions import (
  27. NoNetwork,
  28. )
  29. BUILDD_URL = 'https://buildd.debian.org/build.php?arch=%s&pkg=%s'
  30. # Check for successful in a 'td' block
  31. class BuilddParser(HTMLParser):
  32. def __init__(self):
  33. HTMLParser.__init__(self)
  34. self.versions = {}
  35. self.savedata = None
  36. self.found_succeeded = False
  37. # --- Formatter interface, taking care of 'savedata' mode;
  38. # shouldn't need to be overridden
  39. def handle_data(self, data):
  40. if self.savedata is not None:
  41. self.savedata = self.savedata + data
  42. # --- Hooks to save data; shouldn't need to be overridden
  43. def save_bgn(self):
  44. self.savedata = ''
  45. def save_end(self, mode=0):
  46. data = self.savedata
  47. self.savedata = None
  48. if not mode and data is not None:
  49. data = ' '.join(data.split())
  50. return data
  51. def handle_starttag(self, tag, attrs):
  52. if tag == 'td':
  53. self.save_bgn()
  54. def handle_endtag(self, tag):
  55. if tag == 'td':
  56. data = self.save_end()
  57. if data and 'successful' in data.lower():
  58. self.found_succeeded = True
  59. def check_built(src_package, timeout, arch=None, http_proxy=None):
  60. """Return True if built in the past, False otherwise (even error)"""
  61. if not arch:
  62. arch = utils.get_arch()
  63. try:
  64. page = open_url(BUILDD_URL % (arch, src_package), http_proxy, timeout)
  65. except NoNetwork:
  66. return False
  67. if not page:
  68. return False
  69. parser = BuilddParser()
  70. parser.feed(page)
  71. return parser.found_succeeded