blob: 5d7fe8982942632444182677af19a4492fe76a87 [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
Fathi Boudra26f990b2012-08-27 19:00:01 +030017def list_links(url, regex=r'<a\s*href=[\'"].*[\'"]>(.*)/?</a>'):
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 '''
Fathi Boudra26f990b2012-08-27 19:00:01 +030030 urls = list_links(url, r'<a\s*href=[\'|"].*[\'"]>(hwpack.*?\.tar\.gz)</a>')
Andy Doan5f20efb2012-03-29 21:35:16 -050031 for link in urls:
Ricardo Salveti de Araujo688f24f2012-10-17 02:40:36 -030032 try:
33 build_date = re.compile('_(\d+)-').findall(link)
34 return (build_date[0], '%s/%s' % (url,link))
35 except:
36 return None
Andy Doan540a4b12012-04-17 11:48:11 -050037 return None
Andy Doan8ff38f02012-02-20 16:32:37 -060038
39def latest_hwpacks(url, limit=7):
40 '''returns an array of tuples (build-date, hwpack url) like:
41 [ (20120210, http://foo.bar/hwpack.tar.gz), (20120209, blah.tar.gz) ]
42 '''
43 # only analyze the last few builds
Fathi Boudra26f990b2012-08-27 19:00:01 +030044 links = list_links(url, r'<a\s*href=[\'|"].*[\'"]>(\d+)/?</a>')
Andy Doan1c6ef8b2012-04-23 12:28:50 -050045 links = sorted(links, reverse=True, key=int)[:limit]
Andy Doan8ff38f02012-02-20 16:32:37 -060046 hwpacks = []
Andy Doan1c6ef8b2012-04-23 12:28:50 -050047 for link in links:
Andy Doan540a4b12012-04-17 11:48:11 -050048 build = list_hwpack('%s/%s'% (url, link))
49 if build is not None:
50 hwpacks.append(build)
Andy Doan8ff38f02012-02-20 16:32:37 -060051 return hwpacks
52
Andy Doan5f20efb2012-03-29 21:35:16 -050053def list_rfs(url):
Ricardo Salveti de Araujofc9dde72012-10-18 04:24:59 -030054 links = list_links(url,
55 r'<a\s*href=[\'|"].*[\'"]>(.*\-\d+\.(?!config)(?:rootfs\.)?tar\.gz)</a>')
Andy Doan5f20efb2012-03-29 21:35:16 -050056 if len(links) is 1:
57 return "%s/%s" %(url,links[0])
58 return None
59
Andy Doan8ff38f02012-02-20 16:32:37 -060060def latest_rfs(url, limit=7):
61 '''
62 Returns a tuple of (builddate, url)
63 '''
64 # only analyze the last few builds
Fathi Boudra26f990b2012-08-27 19:00:01 +030065 links = list_links(url, r'<a\s*href=[\'"].*[\'"]>(\d+)/?</a>')
Andy Doan1c6ef8b2012-04-23 12:28:50 -050066 links = sorted(links, reverse=True, key=int)[:limit]
67 for link in links:
Andy Doan540a4b12012-04-17 11:48:11 -050068 build = list_rfs('%s/%s' %(url, link))
69 if build is not None:
70 return (link, build)
Andy Doan8ff38f02012-02-20 16:32:37 -060071
72 return None
73
74if __name__ == '__main__':
Andy Doan1c6ef8b2012-04-23 12:28:50 -050075 cookie_setup()
76
Andy Doan8ff38f02012-02-20 16:32:37 -060077 for arg in sys.argv[1:]:
78 print "HWPACKS for: %s" % arg
79 hwpacks = latest_hwpacks(arg, 4)
80 for hwpack in hwpacks:
81 print " %s: %s" % hwpack
82
83 print "latest nano:"
Fathi Boudra684e5e42012-11-30 04:19:33 +010084 print " %s %s" % latest_rfs('http://snapshots.linaro.org/quantal/images/nano')