blob: db84b4ca374a26b16a504536a99497eb22007f02 [file] [log] [blame]
Andy Doan15aa23b2012-02-02 16:40:58 -06001#!/usr/bin/env python
2# Copyright (C) 2012 Linaro
3#
4# Author: Andy Doan <andy.doan@linaro.org>
5#
6# This file is part of Linaro Daily Prebuilt Images.
7#
8# Linaro Daily Prebuilt Images is free software; you can redistribute it and/or
9# modify it under the terms of the GNU General Public License
10# as published by the Free Software Foundation; either version 2
11# of the License, or (at your option) any later version.
12#
13# Linaro Daily Prebuilt Images is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with Linaro Image Tools; if not, write to the Free Software
20# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21# USA.
22
Andy Doanfccf4842012-03-08 10:42:19 -060023from linaro_fetch_image import fetch_image
Andy Doan15aa23b2012-02-02 16:40:58 -060024from linaro_image_tools import cmd_runner
25
Andy Doan8ff38f02012-02-20 16:32:37 -060026import crawler
27
Andy Doan15aa23b2012-02-02 16:40:58 -060028import argparse
29import bz2
30import datetime
Andy Doanc6500af2012-03-15 14:44:39 -050031import os
Andy Doan15aa23b2012-02-02 16:40:58 -060032import re
Andy Doane449bce2012-03-21 15:22:31 -050033import urlparse
Andy Doan4202d882012-03-29 21:36:09 -050034import sys
Andy Doan15aa23b2012-02-02 16:40:58 -060035
36# a mapping of hwpack name to l-m-c name
37HWPACKS = {
Andy Doanabd46772012-02-15 18:38:01 -060038 'omap3': 'beagle',
Andy Doan108b8e62012-02-15 14:35:01 -060039 'overo': 'overo',
Andy Doanabd46772012-02-15 18:38:01 -060040 'lt-panda': 'panda',
41 'lt-mx5':'mx53loco',
42 'lt-mx6': 'mx6qsabrelite',
43 'lt-origen': 'origen',
Andy Doan540a4b12012-04-17 11:48:11 -050044 'leb-origen': 'origen',
Andy Doanabd46772012-02-15 18:38:01 -060045 'lt-snowball': 'snowball_sd',
46 'lt-vexpress-a9': 'vexpress-a9',
47 'efikamx': 'efikamx',
Andy Doan15aa23b2012-02-02 16:40:58 -060048}
49# a mapping of binary image to its image_file size
50BINARIES = {
Andy Doan4202d882012-03-29 21:36:09 -050051 # release images
52 'nano': '512M',
53 'alip': '2G',
54 'ubuntu-desktop': '3G',
55 'linarotv-xbmc': '3G',
Andy Doan15aa23b2012-02-02 16:40:58 -060056}
57
Andy Doanc6500af2012-03-15 14:44:39 -050058PREINST_SCRIPTS = {
59 'lt-snowball': 'ste-preinstall.sh',
60}
61
Andy Doan15aa23b2012-02-02 16:40:58 -060062def today():
63 d = datetime.date.today()
64 return "%d%02d%02d" % (d.year, d.month, d.day)
65
Andy Doan8ff38f02012-02-20 16:32:37 -060066def hwpack_available(date, hwpack, platform):
Andy Doan540a4b12012-04-17 11:48:11 -050067 url = 'http://snapshots.linaro.org/%s/hwpacks/%s' % (platform, hwpack)
Andy Doan8ff38f02012-02-20 16:32:37 -060068 hwpacks = crawler.latest_hwpacks(url)
69 for hwpack in hwpacks:
70 if hwpack[0] == date:
71 return hwpack[1]
72
Andy Doan15aa23b2012-02-02 16:40:58 -060073 return False
74
75def compress_image(imgfile):
76 print "compressing %s" % imgfile
77 args = ('bzip2', imgfile)
78 cmd_runner.run(args).wait()
Andy Doan23ce4e12012-03-21 12:46:21 -050079 return '%s.bz2' % imgfile
80
81def zsync_image(imgfile):
82 print "making zsync file for %s" % imgfile
83 args = ('zsyncmake', '-o', '%s.zsync'%imgfile, imgfile)
84 cmd_runner.run(args).wait()
Andy Doan15aa23b2012-02-02 16:40:58 -060085
Andy Doanb00dbc02012-03-15 16:23:06 -050086def build_image(lmc, imgfile, hwpack, hwpack_file, binary, binary_file):
Andy Doan15aa23b2012-02-02 16:40:58 -060087 print "building image: %s" % imgfile
88 dev = HWPACKS[hwpack]
89 size = BINARIES[binary]
90
Andy Doan4fa16dc2012-02-09 17:47:45 -080091 print 'running l-m-c: %s' % lmc
Andy Doanc6500af2012-03-15 14:44:39 -050092 args = [lmc,
Andy Doan15aa23b2012-02-02 16:40:58 -060093 '--dev', dev,
94 '--image_file', imgfile,
95 '--image_size', size,
96 '--hwpack-force-yes',
97 '--hwpack', hwpack_file,
98 '--binary', binary_file,
Andy Doanc6500af2012-03-15 14:44:39 -050099 ]
100
101 if PREINST_SCRIPTS.has_key(hwpack):
102 sdir = os.path.abspath(os.path.dirname(__file__))
103 script = "%s/%s" % (sdir, PREINST_SCRIPTS[hwpack])
104 print "using presintall script: %s" % script
105 args.append('--preinstall-script')
106 args.append(script)
107
Andy Doan15aa23b2012-02-02 16:40:58 -0600108 cmd_runner.run(args, as_root=True).wait()
Andy Doan23ce4e12012-03-21 12:46:21 -0500109 bz2file = compress_image(imgfile)
110 zsync_image(bz2file)
Andy Doan15aa23b2012-02-02 16:40:58 -0600111
Andy Doan184cd3b2012-03-29 22:20:02 -0500112class SnapshotCrawler:
113 def __init__(self, date, platform, hwpacks, binaries):
114 self.date = date
115 self.platform = platform
116 self.hwpacks = hwpacks
117 self.binaries = binaries
Andy Doane449bce2012-03-21 15:22:31 -0500118
Andy Doan184cd3b2012-03-29 22:20:02 -0500119 def get_binaries(self):
120 '''return a hash table of binary->url'''
121 binaryf = {}
122 for binary in self.binaries:
Andy Doan540a4b12012-04-17 11:48:11 -0500123 url = 'http://snapshots.linaro.org/%s/images/%s' % (self.platform, binary)
Andy Doan184cd3b2012-03-29 22:20:02 -0500124 (date, url) = crawler.latest_rfs(url)
Andy Doan4202d882012-03-29 21:36:09 -0500125 binaryf[binary] = url
Andy Doan4202d882012-03-29 21:36:09 -0500126
Andy Doan184cd3b2012-03-29 22:20:02 -0500127 return binaryf
Andy Doana3977372012-03-29 12:22:44 -0500128
Andy Doan184cd3b2012-03-29 22:20:02 -0500129 def get_hwpack_url(self, hwpack):
130 hwpackname = "%s-%s" % (hwpack, self.platform)
131 return hwpack_available(self.date, hwpack, self.platform)
Andy Doan4202d882012-03-29 21:36:09 -0500132
Andy Doan184cd3b2012-03-29 22:20:02 -0500133 def get_image_name(self, odir, hwpack, hwpack_url, binary):
134
135 #covert a url like:
Andy Doan540a4b12012-04-17 11:48:11 -0500136 # http://snapshots.linaro.org/precise/hwpacks/lt-panda/87/hwpack_linaro-lt-panda_20120417-87_armhf_supported.tar.gz
Andy Doan184cd3b2012-03-29 22:20:02 -0500137 # to:
Andy Doan540a4b12012-04-17 11:48:11 -0500138 # precise/hwpacks/lt-panda/87/<file>.img
Andy Doan184cd3b2012-03-29 22:20:02 -0500139 path = urlparse.urlparse(hwpack_url).path
140 path = os.path.dirname(path)
Andy Doan540a4b12012-04-17 11:48:11 -0500141 path = path[1:] #strip off the first "/"
Andy Doan184cd3b2012-03-29 22:20:02 -0500142
143 path = '%s/%s' % (odir, path)
144 if not os.path.exists(path):
145 os.makedirs(path)
146 return "%s/%s-%s_%s.img" %(path,hwpack,self.platform,binary)
147
Andy Doan540a4b12012-04-17 11:48:11 -0500148# XXX: this is now broken for precise. need to wait for release images to see
149# what changes are needed
Andy Doan184cd3b2012-03-29 22:20:02 -0500150class ReleaseCrawler:
151 def __init__(self, cycle, platform, hwpacks, binaries):
152 self.cycle = cycle
153 self.platform = platform
154 self.hwpacks = hwpacks
155 self.binaries = binaries
156
157 #inialize our list of hwpacks
158 url = 'http://releases.linaro.org/%s/ubuntu/%s-hwpacks' % (cycle,platform)
159 self.hwpack_urls = crawler.list_hwpacks(url)
160
161 def get_hwpack_url(self, hwpack):
162 pat = re.compile('hwpack_linaro-%s_' % hwpack)
163 for url in self.hwpack_urls:
164 if pat.search(url):
165 return url
166 return None
167
168 def get_binaries(self):
169 '''return a hash table of binary->url'''
170 binaryf = {}
171 for binary in self.binaries:
172 url = 'http://releases.linaro.org/%s/ubuntu/%s-images/%s' % (
173 self.cycle, self.platform, binary)
174 url = crawler.list_rfs(url)
175 if url is not None:
176 binaryf[binary] = url
177 return binaryf
178
179 def get_image_name(self, odir, hwpack, hwpack_url, binary):
180 path = '%s/%s/%s/%s' % (odir, self.cycle, self.platform, binary)
181 if not os.path.exists(path):
182 os.makedirs(path)
183 return "%s/%s-%s.img" %(path,hwpack,binary)
Andy Doan4202d882012-03-29 21:36:09 -0500184
Andy Doan15aa23b2012-02-02 16:40:58 -0600185def main():
186 day = today()
187 hwpacks = HWPACKS.keys()
188 binaries = BINARIES.keys()
189
190 p = argparse.ArgumentParser(description=
Andy Doana3977372012-03-29 12:22:44 -0500191 'Builds a matrix of builds from the latest build on '
192 'snapshots.linaro.org or release images on releases.linaro.org')
Andy Doan15aa23b2012-02-02 16:40:58 -0600193
Andy Doan94bfe312012-02-09 17:57:29 -0800194 p.add_argument('-o', dest='out_dir', default='./out',
Andy Doan15aa23b2012-02-02 16:40:58 -0600195 help='The out directory for downloaded and built files, default=./')
196 p.add_argument('-d', dest='date', default=day,
197 help='The date, default=%s' % day)
198 p.add_argument('-w', dest='hwpacks', action='append',
199 help='The hwpacks to generate for, default=%s' %
200 ', '.join(hwpacks))
201 p.add_argument('-b', dest='binaries', action='append',
202 help='The binaries to generate for, default=%s' %
203 ', '.join(binaries))
Andy Doan540a4b12012-04-17 11:48:11 -0500204 p.add_argument('-p', dest='platform', default='precise',
205 help='The platform, default=precise')
Andy Doan4202d882012-03-29 21:36:09 -0500206 p.add_argument('-r', dest='release', action='store_true', default=False,
207 help='If this is for release images. NOTE: the "date" arg'
208 'will then become the cycle ie -d 12.03')
Andy Doan15aa23b2012-02-02 16:40:58 -0600209
210 args = p.parse_args()
Andy Doana3977372012-03-29 12:22:44 -0500211
Andy Doan15aa23b2012-02-02 16:40:58 -0600212 if args.hwpacks:
213 hwpacks = args.hwpacks
214 if args.binaries:
215 binaries = args.binaries
216
217 dm = fetch_image.DownloadManager(args.out_dir)
Andy Doan15aa23b2012-02-02 16:40:58 -0600218
Andy Doan4202d882012-03-29 21:36:09 -0500219 if args.release:
Andy Doan184cd3b2012-03-29 22:20:02 -0500220 site = ReleaseCrawler(args.date, args.platform, hwpacks, binaries)
Andy Doan4202d882012-03-29 21:36:09 -0500221 else:
Andy Doan184cd3b2012-03-29 22:20:02 -0500222 site = SnapshotCrawler(args.date, args.platform, hwpacks, binaries)
223
224 binaryf = site.get_binaries()
Andy Doan15aa23b2012-02-02 16:40:58 -0600225
Andy Doanb00dbc02012-03-15 16:23:06 -0500226 lmc = '%s/linaro-image-tools/linaro-media-create' % args.out_dir
Andy Doan184cd3b2012-03-29 22:20:02 -0500227 odir = '%s/pre-built' % args.out_dir
Andy Doanb00dbc02012-03-15 16:23:06 -0500228
Andy Doan15aa23b2012-02-02 16:40:58 -0600229 for hwpack in hwpacks:
Andy Doan184cd3b2012-03-29 22:20:02 -0500230 url = site.get_hwpack_url(hwpack)
Andy Doanb00dbc02012-03-15 16:23:06 -0500231
Andy Doan2cfe5e62012-02-09 17:41:45 -0800232 if url is not None and url is not False:
Andy Doan15aa23b2012-02-02 16:40:58 -0600233 hwpf = dm.download(url, None)
234 for binary in binaries:
Andy Doan184cd3b2012-03-29 22:20:02 -0500235 imgfile = site.get_image_name(odir,hwpack,url,binary)
Andy Doan81211902012-03-14 14:37:30 -0500236 rfsf = dm.download(binaryf[binary], None)
Andy Doanb00dbc02012-03-15 16:23:06 -0500237 build_image(lmc, imgfile, hwpack, hwpf, binary, rfsf)
Andy Doan15aa23b2012-02-02 16:40:58 -0600238 else:
Andy Doan8ff38f02012-02-20 16:32:37 -0600239 print '%s hwpack not available for %s' % (args.date,hwpack)
Andy Doan15aa23b2012-02-02 16:40:58 -0600240
241if __name__ == '__main__':
242 main()
243