blob: a90b5010bc53b52ad7cf958b3315306a1fdf0f9e [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001#!/usr/bin/env python3
Brad Bishopc342db32019-05-15 21:57:59 -04002#
Patrick Williams92b42cb2022-09-03 06:53:57 -05003# Copyright OpenEmbedded Contributors
4#
Brad Bishopc342db32019-05-15 21:57:59 -04005# SPDX-License-Identifier: GPL-2.0-only
6#
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05007# This script can be used to verify HOMEPAGE values for all recipes in
8# the current configuration.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009# The result is influenced by network environment, since the timeout of connect url is 5 seconds as default.
10
11import sys
12import os
13import subprocess
Patrick Williamsc0f7c042017-02-23 20:41:17 -060014import urllib.request
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015
Patrick Williamsc124f4f2015-09-15 14:41:29 -050016
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050017# Allow importing scripts/lib modules
18scripts_path = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + '/..')
19lib_path = scripts_path + '/lib'
20sys.path = sys.path + [lib_path]
21import scriptpath
22import scriptutils
Patrick Williamsc124f4f2015-09-15 14:41:29 -050023
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050024# Allow importing bitbake modules
25bitbakepath = scriptpath.add_bitbake_lib_path()
26
Patrick Williamsc124f4f2015-09-15 14:41:29 -050027import bb.tinfoil
28
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050029logger = scriptutils.logger_create('verify_homepage')
30
Patrick Williamsc124f4f2015-09-15 14:41:29 -050031def wgetHomepage(pn, homepage):
32 result = subprocess.call('wget ' + '-q -T 5 -t 1 --spider ' + homepage, shell = True)
33 if result:
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080034 logger.warning("%s: failed to verify HOMEPAGE: %s " % (pn, homepage))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050035 return 1
36 else:
37 return 0
38
39def verifyHomepage(bbhandler):
Patrick Williamsc0f7c042017-02-23 20:41:17 -060040 pkg_pn = bbhandler.cooker.recipecaches[''].pkg_pn
Patrick Williamsc124f4f2015-09-15 14:41:29 -050041 pnlist = sorted(pkg_pn)
42 count = 0
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050043 checked = []
Patrick Williamsc124f4f2015-09-15 14:41:29 -050044 for pn in pnlist:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050045 for fn in pkg_pn[pn]:
46 # There's no point checking multiple BBCLASSEXTENDed variants of the same recipe
Patrick Williamsc0f7c042017-02-23 20:41:17 -060047 realfn, _, _ = bb.cache.virtualfn2realfn(fn)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050048 if realfn in checked:
49 continue
Patrick Williamsc0f7c042017-02-23 20:41:17 -060050 data = bbhandler.parse_recipe_file(realfn)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050051 homepage = data.getVar("HOMEPAGE")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050052 if homepage:
53 try:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060054 urllib.request.urlopen(homepage, timeout=5)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050055 except Exception:
56 count = count + wgetHomepage(os.path.basename(realfn), homepage)
57 checked.append(realfn)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050058 return count
59
60if __name__=='__main__':
Patrick Williamsc0f7c042017-02-23 20:41:17 -060061 with bb.tinfoil.Tinfoil() as bbhandler:
62 bbhandler.prepare()
63 logger.info("Start verifying HOMEPAGE:")
64 failcount = verifyHomepage(bbhandler)
65 logger.info("Finished verifying HOMEPAGE.")
66 logger.info("Summary: %s failed" % failcount)