blob: 7bffa78e23875d9028b1f03f69b7161fe9105321 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#!/usr/bin/env python3
2#
3# SPDX-License-Identifier: GPL-2.0-only
4#
5# This script can be used to verify HOMEPAGE values for all recipes in
6# the current configuration.
7# 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
12import urllib.request
13
14
15# 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
21
22# Allow importing bitbake modules
23bitbakepath = scriptpath.add_bitbake_lib_path()
24
25import bb.tinfoil
26
27logger = scriptutils.logger_create('verify_homepage')
28
29def wgetHomepage(pn, homepage):
30 result = subprocess.call('wget ' + '-q -T 5 -t 1 --spider ' + homepage, shell = True)
31 if result:
32 logger.warning("%s: failed to verify HOMEPAGE: %s " % (pn, homepage))
33 return 1
34 else:
35 return 0
36
37def verifyHomepage(bbhandler):
38 pkg_pn = bbhandler.cooker.recipecaches[''].pkg_pn
39 pnlist = sorted(pkg_pn)
40 count = 0
41 checked = []
42 for pn in pnlist:
43 for fn in pkg_pn[pn]:
44 # There's no point checking multiple BBCLASSEXTENDed variants of the same recipe
45 realfn, _, _ = bb.cache.virtualfn2realfn(fn)
46 if realfn in checked:
47 continue
48 data = bbhandler.parse_recipe_file(realfn)
49 homepage = data.getVar("HOMEPAGE")
50 if homepage:
51 try:
52 urllib.request.urlopen(homepage, timeout=5)
53 except Exception:
54 count = count + wgetHomepage(os.path.basename(realfn), homepage)
55 checked.append(realfn)
56 return count
57
58if __name__=='__main__':
59 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)