blob: 101995f91d0a53d9dfda8601bebbe7eea178d81e [file] [log] [blame]
Andy Doan8ff38f02012-02-20 16:32:37 -06001#!/usr/bin/python
2
3import re
4import urllib2
5
6def list_links(url, regex=r'<a\s*href=[\'|"](.*?)[\'"].*?>'):
Andy Doan81211902012-03-14 14:37:30 -05007 try:
8 response = urllib2.urlopen(url)
9 msg = response.read()
10 links = re.compile(regex).findall(msg)
11 except urllib2.HTTPError,e:
12 print "ERROR finding links for (%s): %s" % (url, e)
13 links = [] #return empty array
Andy Doan8ff38f02012-02-20 16:32:37 -060014 return links
15
Andy Doan540a4b12012-04-17 11:48:11 -050016def list_hwpack(url):
17 ''' returns tuple of (buildate, url)
18 '''
Andy Doan5f20efb2012-03-29 21:35:16 -050019 urls = list_links(url, r'<a\s*href=[\'|"](hwpack.*?\.tar\.gz)[\'"].*?>')
20 for link in urls:
Andy Doan540a4b12012-04-17 11:48:11 -050021 build_date = re.compile('_(\d+)-').findall(link)
22 return (build_date[0], '%s/%s' % (url,link))
23 return None
Andy Doan8ff38f02012-02-20 16:32:37 -060024
25def latest_hwpacks(url, limit=7):
26 '''returns an array of tuples (build-date, hwpack url) like:
27 [ (20120210, http://foo.bar/hwpack.tar.gz), (20120209, blah.tar.gz) ]
28 '''
29 # only analyze the last few builds
30 links = list_links(url, r'<a\s*href=[\'|"](\d+)\/[\'"].*?>')[:limit]
31 hwpacks = []
32 for link in sorted(links, reverse=True):
Andy Doan540a4b12012-04-17 11:48:11 -050033 build = list_hwpack('%s/%s'% (url, link))
34 if build is not None:
35 hwpacks.append(build)
Andy Doan8ff38f02012-02-20 16:32:37 -060036 return hwpacks
37
Andy Doan5f20efb2012-03-29 21:35:16 -050038def list_rfs(url):
Andy Doan540a4b12012-04-17 11:48:11 -050039 links = list_links(url, r'<a\s*href=[\'|"](linaro-.*?\d+(?!config)\.tar\.gz)[\'"].*?>')
Andy Doan5f20efb2012-03-29 21:35:16 -050040 if len(links) is 1:
41 return "%s/%s" %(url,links[0])
42 return None
43
Andy Doan8ff38f02012-02-20 16:32:37 -060044def latest_rfs(url, limit=7):
45 '''
46 Returns a tuple of (builddate, url)
47 '''
48 # only analyze the last few builds
49 links = list_links(url, r'<a\s*href=[\'|"](\d+)\/[\'"].*?>')[:limit]
Andy Doan1a0233a2012-04-23 11:23:14 -050050 for link in sorted(links, reverse=True, key=int):
Andy Doan540a4b12012-04-17 11:48:11 -050051 build = list_rfs('%s/%s' %(url, link))
52 if build is not None:
53 return (link, build)
Andy Doan8ff38f02012-02-20 16:32:37 -060054
55 return None
56
57if __name__ == '__main__':
58 import sys
59 for arg in sys.argv[1:]:
60 print "HWPACKS for: %s" % arg
61 hwpacks = latest_hwpacks(arg, 4)
62 for hwpack in hwpacks:
63 print " %s: %s" % hwpack
64
65 print "latest nano:"
Andy Doan1a0233a2012-04-23 11:23:14 -050066 print " %s %s" % latest_rfs('http://snapshots.linaro.org/precise/images/nano')