verify-homepage.py 2.0 KB

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