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