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