blob: 86cc82bca385b0d8a628c315ac5622dc3625d093 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#!/usr/bin/env python
2
3# This script is used for verify HOMEPAGE.
4# The result is influenced by network environment, since the timeout of connect url is 5 seconds as default.
5
6import sys
7import os
8import subprocess
9import urllib2
10
11def search_bitbakepath():
12 bitbakepath = ""
13
14 # Search path to bitbake lib dir in order to load bb modules
15 if os.path.exists(os.path.join(os.path.dirname(sys.argv[0]), '../../bitbake/lib/bb')):
16 bitbakepath = os.path.join(os.path.dirname(sys.argv[0]), '../../bitbake/lib')
17 bitbakepath = os.path.abspath(bitbakepath)
18 else:
19 # Look for bitbake/bin dir in PATH
20 for pth in os.environ['PATH'].split(':'):
21 if os.path.exists(os.path.join(pth, '../lib/bb')):
22 bitbakepath = os.path.abspath(os.path.join(pth, '../lib'))
23 break
24 if not bitbakepath:
25 sys.stderr.write("Unable to find bitbake by searching parent directory of this script or PATH\n")
26 sys.exit(1)
27 return bitbakepath
28
29# For importing the following modules
30sys.path.insert(0, search_bitbakepath())
31import bb.tinfoil
32
33def wgetHomepage(pn, homepage):
34 result = subprocess.call('wget ' + '-q -T 5 -t 1 --spider ' + homepage, shell = True)
35 if result:
36 bb.warn("Failed to verify HOMEPAGE (%s) of %s" % (homepage, pn))
37 return 1
38 else:
39 return 0
40
41def verifyHomepage(bbhandler):
42 pkg_pn = bbhandler.cooker.recipecache.pkg_pn
43 pnlist = sorted(pkg_pn)
44 count = 0
45 for pn in pnlist:
46 fn = pkg_pn[pn].pop()
47 data = bb.cache.Cache.loadDataFull(fn, bbhandler.cooker.collection.get_file_appends(fn), bbhandler.config_data)
48 homepage = data.getVar("HOMEPAGE")
49 if homepage:
50 try:
51 urllib2.urlopen(homepage, timeout=5)
52 except Exception:
53 count = count + wgetHomepage(pn, homepage)
54 return count
55
56if __name__=='__main__':
57 failcount = 0
58 bbhandler = bb.tinfoil.Tinfoil()
59 bbhandler.prepare()
60 print "Start to verify HOMEPAGE:"
61 failcount = verifyHomepage(bbhandler)
62 print "finish to verify HOMEPAGE."
63 print "Summary: %s failed" % failcount