Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 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 |
| 10 | import urllib2 |
| 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: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 30 | logger.warn("%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): |
| 36 | pkg_pn = bbhandler.cooker.recipecache.pkg_pn |
| 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 |
| 43 | realfn, _ = bb.cache.Cache.virtualfn2realfn(fn) |
| 44 | if realfn in checked: |
| 45 | continue |
| 46 | data = bb.cache.Cache.loadDataFull(realfn, bbhandler.cooker.collection.get_file_appends(realfn), bbhandler.config_data) |
| 47 | homepage = data.getVar("HOMEPAGE", True) |
| 48 | if homepage: |
| 49 | try: |
| 50 | urllib2.urlopen(homepage, timeout=5) |
| 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 | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 57 | bbhandler = bb.tinfoil.Tinfoil() |
| 58 | bbhandler.prepare() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 59 | logger.info("Start verifying HOMEPAGE:") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 60 | failcount = verifyHomepage(bbhandler) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 61 | logger.info("Finished verifying HOMEPAGE.") |
| 62 | logger.info("Summary: %s failed" % failcount) |