blob: 265ff65d3cf53d1debf66b6484163d7eaa3073a3 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#!/usr/bin/env python
2
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
10import urllib2
11
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):
36 pkg_pn = bbhandler.cooker.recipecache.pkg_pn
37 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
43 realfn, _ = bb.cache.Cache.virtualfn2realfn(fn)
44 if realfn in checked:
45 continue
46 data = bb.cache.Cache.loadDataFull(realfn, bbhandler.cooker.collection.get_file_appends(realfn), bbhandler.config_data)
47 homepage = data.getVar("HOMEPAGE", True)
48 if homepage:
49 try:
50 urllib2.urlopen(homepage, timeout=5)
51 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 Williamsc124f4f2015-09-15 14:41:29 -050057 bbhandler = bb.tinfoil.Tinfoil()
58 bbhandler.prepare()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050059 logger.info("Start verifying HOMEPAGE:")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050060 failcount = verifyHomepage(bbhandler)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050061 logger.info("Finished verifying HOMEPAGE.")
62 logger.info("Summary: %s failed" % failcount)