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