blob: 76f1749cfa0666c8b6bdc0d43552b30a12a5244a [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001#!/usr/bin/env python3
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05003# This script can be used to verify HOMEPAGE values for all recipes in
4# the current configuration.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05005# The result is influenced by network environment, since the timeout of connect url is 5 seconds as default.
6
7import sys
8import os
9import subprocess
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010import urllib.request
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050013# Allow importing scripts/lib modules
14scripts_path = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + '/..')
15lib_path = scripts_path + '/lib'
16sys.path = sys.path + [lib_path]
17import scriptpath
18import scriptutils
Patrick Williamsc124f4f2015-09-15 14:41:29 -050019
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050020# Allow importing bitbake modules
21bitbakepath = scriptpath.add_bitbake_lib_path()
22
Patrick Williamsc124f4f2015-09-15 14:41:29 -050023import bb.tinfoil
24
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050025logger = scriptutils.logger_create('verify_homepage')
26
Patrick Williamsc124f4f2015-09-15 14:41:29 -050027def wgetHomepage(pn, homepage):
28 result = subprocess.call('wget ' + '-q -T 5 -t 1 --spider ' + homepage, shell = True)
29 if result:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050030 logger.warn("%s: failed to verify HOMEPAGE: %s " % (pn, homepage))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050031 return 1
32 else:
33 return 0
34
35def verifyHomepage(bbhandler):
Patrick Williamsc0f7c042017-02-23 20:41:17 -060036 pkg_pn = bbhandler.cooker.recipecaches[''].pkg_pn
Patrick Williamsc124f4f2015-09-15 14:41:29 -050037 pnlist = sorted(pkg_pn)
38 count = 0
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050039 checked = []
Patrick Williamsc124f4f2015-09-15 14:41:29 -050040 for pn in pnlist:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050041 for fn in pkg_pn[pn]:
42 # There's no point checking multiple BBCLASSEXTENDed variants of the same recipe
Patrick Williamsc0f7c042017-02-23 20:41:17 -060043 realfn, _, _ = bb.cache.virtualfn2realfn(fn)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050044 if realfn in checked:
45 continue
Patrick Williamsc0f7c042017-02-23 20:41:17 -060046 data = bbhandler.parse_recipe_file(realfn)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050047 homepage = data.getVar("HOMEPAGE")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050048 if homepage:
49 try:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060050 urllib.request.urlopen(homepage, timeout=5)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050051 except Exception:
52 count = count + wgetHomepage(os.path.basename(realfn), homepage)
53 checked.append(realfn)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050054 return count
55
56if __name__=='__main__':
Patrick Williamsc0f7c042017-02-23 20:41:17 -060057 with bb.tinfoil.Tinfoil() as bbhandler:
58 bbhandler.prepare()
59 logger.info("Start verifying HOMEPAGE:")
60 failcount = verifyHomepage(bbhandler)
61 logger.info("Finished verifying HOMEPAGE.")
62 logger.info("Summary: %s failed" % failcount)