Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 2 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 3 | # Copyright OpenEmbedded Contributors |
| 4 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 5 | # SPDX-License-Identifier: GPL-2.0-only |
| 6 | # |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 7 | # This script can be used to verify HOMEPAGE values for all recipes in |
| 8 | # the current configuration. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9 | # The result is influenced by network environment, since the timeout of connect url is 5 seconds as default. |
| 10 | |
| 11 | import sys |
| 12 | import os |
| 13 | import subprocess |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 14 | import urllib.request |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 15 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 16 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 17 | # Allow importing scripts/lib modules |
| 18 | scripts_path = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + '/..') |
| 19 | lib_path = scripts_path + '/lib' |
| 20 | sys.path = sys.path + [lib_path] |
| 21 | import scriptpath |
| 22 | import scriptutils |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 23 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 24 | # Allow importing bitbake modules |
| 25 | bitbakepath = scriptpath.add_bitbake_lib_path() |
| 26 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 27 | import bb.tinfoil |
| 28 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 29 | logger = scriptutils.logger_create('verify_homepage') |
| 30 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 31 | def wgetHomepage(pn, homepage): |
| 32 | result = subprocess.call('wget ' + '-q -T 5 -t 1 --spider ' + homepage, shell = True) |
| 33 | if result: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 34 | logger.warning("%s: failed to verify HOMEPAGE: %s " % (pn, homepage)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 35 | return 1 |
| 36 | else: |
| 37 | return 0 |
| 38 | |
| 39 | def verifyHomepage(bbhandler): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 40 | pkg_pn = bbhandler.cooker.recipecaches[''].pkg_pn |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 41 | pnlist = sorted(pkg_pn) |
| 42 | count = 0 |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 43 | checked = [] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 44 | for pn in pnlist: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 45 | for fn in pkg_pn[pn]: |
| 46 | # There's no point checking multiple BBCLASSEXTENDed variants of the same recipe |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 47 | realfn, _, _ = bb.cache.virtualfn2realfn(fn) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 48 | if realfn in checked: |
| 49 | continue |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 50 | data = bbhandler.parse_recipe_file(realfn) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 51 | homepage = data.getVar("HOMEPAGE") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 52 | if homepage: |
| 53 | try: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 54 | urllib.request.urlopen(homepage, timeout=5) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 55 | except Exception: |
| 56 | count = count + wgetHomepage(os.path.basename(realfn), homepage) |
| 57 | checked.append(realfn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 58 | return count |
| 59 | |
| 60 | if __name__=='__main__': |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 61 | 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) |