blob: 7bffa78e23875d9028b1f03f69b7161fe9105321 [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001#!/usr/bin/env python3
Brad Bishopc342db32019-05-15 21:57:59 -04002#
3# SPDX-License-Identifier: GPL-2.0-only
4#
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05005# This script can be used to verify HOMEPAGE values for all recipes in
6# the current configuration.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007# The result is influenced by network environment, since the timeout of connect url is 5 seconds as default.
8
9import sys
10import os
11import subprocess
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012import urllib.request
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015# Allow importing scripts/lib modules
16scripts_path = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + '/..')
17lib_path = scripts_path + '/lib'
18sys.path = sys.path + [lib_path]
19import scriptpath
20import scriptutils
Patrick Williamsc124f4f2015-09-15 14:41:29 -050021
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050022# Allow importing bitbake modules
23bitbakepath = scriptpath.add_bitbake_lib_path()
24
Patrick Williamsc124f4f2015-09-15 14:41:29 -050025import bb.tinfoil
26
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050027logger = scriptutils.logger_create('verify_homepage')
28
Patrick Williamsc124f4f2015-09-15 14:41:29 -050029def wgetHomepage(pn, homepage):
30 result = subprocess.call('wget ' + '-q -T 5 -t 1 --spider ' + homepage, shell = True)
31 if result:
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080032 logger.warning("%s: failed to verify HOMEPAGE: %s " % (pn, homepage))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050033 return 1
34 else:
35 return 0
36
37def verifyHomepage(bbhandler):
Patrick Williamsc0f7c042017-02-23 20:41:17 -060038 pkg_pn = bbhandler.cooker.recipecaches[''].pkg_pn
Patrick Williamsc124f4f2015-09-15 14:41:29 -050039 pnlist = sorted(pkg_pn)
40 count = 0
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050041 checked = []
Patrick Williamsc124f4f2015-09-15 14:41:29 -050042 for pn in pnlist:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050043 for fn in pkg_pn[pn]:
44 # There's no point checking multiple BBCLASSEXTENDed variants of the same recipe
Patrick Williamsc0f7c042017-02-23 20:41:17 -060045 realfn, _, _ = bb.cache.virtualfn2realfn(fn)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050046 if realfn in checked:
47 continue
Patrick Williamsc0f7c042017-02-23 20:41:17 -060048 data = bbhandler.parse_recipe_file(realfn)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050049 homepage = data.getVar("HOMEPAGE")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050050 if homepage:
51 try:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060052 urllib.request.urlopen(homepage, timeout=5)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050053 except Exception:
54 count = count + wgetHomepage(os.path.basename(realfn), homepage)
55 checked.append(realfn)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050056 return count
57
58if __name__=='__main__':
Patrick Williamsc0f7c042017-02-23 20:41:17 -060059 with bb.tinfoil.Tinfoil() as bbhandler:
60 bbhandler.prepare()
61 logger.info("Start verifying HOMEPAGE:")
62 failcount = verifyHomepage(bbhandler)
63 logger.info("Finished verifying HOMEPAGE.")
64 logger.info("Summary: %s failed" % failcount)