verify-homepage.py 2.1 KB

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