verify-homepage.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env python3
  2. #
  3. # SPDX-License-Identifier: GPL-2.0-only
  4. #
  5. # This script can be used to verify HOMEPAGE values for all recipes in
  6. # the current configuration.
  7. # The result is influenced by network environment, since the timeout of connect url is 5 seconds as default.
  8. import sys
  9. import os
  10. import subprocess
  11. import urllib.request
  12. # Allow importing scripts/lib modules
  13. scripts_path = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + '/..')
  14. lib_path = scripts_path + '/lib'
  15. sys.path = sys.path + [lib_path]
  16. import scriptpath
  17. import scriptutils
  18. # Allow importing bitbake modules
  19. bitbakepath = scriptpath.add_bitbake_lib_path()
  20. import bb.tinfoil
  21. logger = scriptutils.logger_create('verify_homepage')
  22. def wgetHomepage(pn, homepage):
  23. result = subprocess.call('wget ' + '-q -T 5 -t 1 --spider ' + homepage, shell = True)
  24. if result:
  25. logger.warning("%s: failed to verify HOMEPAGE: %s " % (pn, homepage))
  26. return 1
  27. else:
  28. return 0
  29. def verifyHomepage(bbhandler):
  30. pkg_pn = bbhandler.cooker.recipecaches[''].pkg_pn
  31. pnlist = sorted(pkg_pn)
  32. count = 0
  33. checked = []
  34. for pn in pnlist:
  35. for fn in pkg_pn[pn]:
  36. # There's no point checking multiple BBCLASSEXTENDed variants of the same recipe
  37. realfn, _, _ = bb.cache.virtualfn2realfn(fn)
  38. if realfn in checked:
  39. continue
  40. data = bbhandler.parse_recipe_file(realfn)
  41. homepage = data.getVar("HOMEPAGE")
  42. if homepage:
  43. try:
  44. urllib.request.urlopen(homepage, timeout=5)
  45. except Exception:
  46. count = count + wgetHomepage(os.path.basename(realfn), homepage)
  47. checked.append(realfn)
  48. return count
  49. if __name__=='__main__':
  50. with bb.tinfoil.Tinfoil() as bbhandler:
  51. bbhandler.prepare()
  52. logger.info("Start verifying HOMEPAGE:")
  53. failcount = verifyHomepage(bbhandler)
  54. logger.info("Finished verifying HOMEPAGE.")
  55. logger.info("Summary: %s failed" % failcount)