blob: 3d67b36b2b4a2226bf40e04e145bd807a913897b [file] [log] [blame]
Andy Doan8ff38f02012-02-20 16:32:37 -06001#!/usr/bin/python
2
Andy Doan1c6ef8b2012-04-23 12:28:50 -05003import cookielib
4import os
Andy Doan8ff38f02012-02-20 16:32:37 -06005import re
6import urllib2
Fathi Boudra75e299a2012-08-26 19:04:03 +03007import sys
Andy Doan8ff38f02012-02-20 16:32:37 -06008
Andy Doan1c6ef8b2012-04-23 12:28:50 -05009def cookie_setup():
10 cookies = os.getenv('LMC_COOKIES')
11 if cookies:
12 cj = cookielib.LWPCookieJar()
13 opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
14 opener.addheaders.append(('Cookie', cookies))
15 urllib2.install_opener(opener)
16
Andy Doan8ff38f02012-02-20 16:32:37 -060017def list_links(url, regex=r'<a\s*href=[\'|"](.*?)[\'"].*?>'):
Andy Doan81211902012-03-14 14:37:30 -050018 try:
19 response = urllib2.urlopen(url)
20 msg = response.read()
21 links = re.compile(regex).findall(msg)
22 except urllib2.HTTPError,e:
Ricardo Salveti de Araujoba7dacf2012-06-23 01:08:24 -030023 print "ERROR: finding links for (%s): %s" % (url, e)
Andy Doan81211902012-03-14 14:37:30 -050024 links = [] #return empty array
Andy Doan8ff38f02012-02-20 16:32:37 -060025 return links
26
Andy Doan540a4b12012-04-17 11:48:11 -050027def list_hwpack(url):
28 ''' returns tuple of (buildate, url)
29 '''
Andy Doan5f20efb2012-03-29 21:35:16 -050030 urls = list_links(url, r'<a\s*href=[\'|"](hwpack.*?\.tar\.gz)[\'"].*?>')
31 for link in urls:
Andy Doan540a4b12012-04-17 11:48:11 -050032 build_date = re.compile('_(\d+)-').findall(link)
33 return (build_date[0], '%s/%s' % (url,link))
34 return None
Andy Doan8ff38f02012-02-20 16:32:37 -060035
36def latest_hwpacks(url, limit=7):
37 '''returns an array of tuples (build-date, hwpack url) like:
38 [ (20120210, http://foo.bar/hwpack.tar.gz), (20120209, blah.tar.gz) ]
39 '''
40 # only analyze the last few builds
Andy Doan1c6ef8b2012-04-23 12:28:50 -050041 links = list_links(url, r'<a\s*href=[\'|"](\d+)\/[\'"].*?>')
42 links = sorted(links, reverse=True, key=int)[:limit]
Andy Doan8ff38f02012-02-20 16:32:37 -060043 hwpacks = []
Andy Doan1c6ef8b2012-04-23 12:28:50 -050044 for link in links:
Andy Doan540a4b12012-04-17 11:48:11 -050045 build = list_hwpack('%s/%s'% (url, link))
46 if build is not None:
47 hwpacks.append(build)
Andy Doan8ff38f02012-02-20 16:32:37 -060048 return hwpacks
49
Andy Doan5f20efb2012-03-29 21:35:16 -050050def list_rfs(url):
Andy Doan540a4b12012-04-17 11:48:11 -050051 links = list_links(url, r'<a\s*href=[\'|"](linaro-.*?\d+(?!config)\.tar\.gz)[\'"].*?>')
Andy Doan5f20efb2012-03-29 21:35:16 -050052 if len(links) is 1:
53 return "%s/%s" %(url,links[0])
54 return None
55
Andy Doan8ff38f02012-02-20 16:32:37 -060056def latest_rfs(url, limit=7):
57 '''
58 Returns a tuple of (builddate, url)
59 '''
60 # only analyze the last few builds
Andy Doan1c6ef8b2012-04-23 12:28:50 -050061 links = list_links(url, r'<a\s*href=[\'|"](\d+)\/[\'"].*?>')
62 links = sorted(links, reverse=True, key=int)[:limit]
63 for link in links:
Andy Doan540a4b12012-04-17 11:48:11 -050064 build = list_rfs('%s/%s' %(url, link))
65 if build is not None:
66 return (link, build)
Andy Doan8ff38f02012-02-20 16:32:37 -060067
68 return None
69
70if __name__ == '__main__':
Andy Doan1c6ef8b2012-04-23 12:28:50 -050071 cookie_setup()
72
Andy Doan8ff38f02012-02-20 16:32:37 -060073 for arg in sys.argv[1:]:
74 print "HWPACKS for: %s" % arg
75 hwpacks = latest_hwpacks(arg, 4)
76 for hwpack in hwpacks:
77 print " %s: %s" % hwpack
78
79 print "latest nano:"
Andy Doan1a0233a2012-04-23 11:23:14 -050080 print " %s %s" % latest_rfs('http://snapshots.linaro.org/precise/images/nano')