blob: 7c2633ca329a65f2e5b7a355b088efea0daa6ff8 [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',
44 'lt-snowball': 'snowball_sd',
45 'lt-vexpress-a9': 'vexpress-a9',
46 'efikamx': 'efikamx',
Andy Doan15aa23b2012-02-02 16:40:58 -060047}
48# a mapping of binary image to its image_file size
49BINARIES = {
Andy Doan4202d882012-03-29 21:36:09 -050050 # daily oneiric snapshots
Andy Doan15aa23b2012-02-02 16:40:58 -060051 'linaro-o-nano': '512M',
52 'linaro-o-alip': '2G',
53 'linaro-o-ubuntu-desktop': '3G',
Andy Doan4202d882012-03-29 21:36:09 -050054 # release images
55 'nano': '512M',
56 'alip': '2G',
57 'ubuntu-desktop': '3G',
58 'linarotv-xbmc': '3G',
Andy Doan15aa23b2012-02-02 16:40:58 -060059}
60
Andy Doanc6500af2012-03-15 14:44:39 -050061PREINST_SCRIPTS = {
62 'lt-snowball': 'ste-preinstall.sh',
63}
64
Andy Doan15aa23b2012-02-02 16:40:58 -060065def today():
66 d = datetime.date.today()
67 return "%d%02d%02d" % (d.year, d.month, d.day)
68
Andy Doan8ff38f02012-02-20 16:32:37 -060069def hwpack_available(date, hwpack, platform):
70 url = 'http://snapshots.linaro.org/%s/%s-%s' % (platform, hwpack, platform)
71 hwpacks = crawler.latest_hwpacks(url)
72 for hwpack in hwpacks:
73 if hwpack[0] == date:
74 return hwpack[1]
75
Andy Doan15aa23b2012-02-02 16:40:58 -060076 return False
77
78def compress_image(imgfile):
79 print "compressing %s" % imgfile
80 args = ('bzip2', imgfile)
81 cmd_runner.run(args).wait()
Andy Doan23ce4e12012-03-21 12:46:21 -050082 return '%s.bz2' % imgfile
83
84def zsync_image(imgfile):
85 print "making zsync file for %s" % imgfile
86 args = ('zsyncmake', '-o', '%s.zsync'%imgfile, imgfile)
87 cmd_runner.run(args).wait()
Andy Doan15aa23b2012-02-02 16:40:58 -060088
Andy Doanb00dbc02012-03-15 16:23:06 -050089def build_image(lmc, imgfile, hwpack, hwpack_file, binary, binary_file):
Andy Doan15aa23b2012-02-02 16:40:58 -060090 print "building image: %s" % imgfile
91 dev = HWPACKS[hwpack]
92 size = BINARIES[binary]
93
Andy Doan4fa16dc2012-02-09 17:47:45 -080094 print 'running l-m-c: %s' % lmc
Andy Doanc6500af2012-03-15 14:44:39 -050095 args = [lmc,
Andy Doan15aa23b2012-02-02 16:40:58 -060096 '--dev', dev,
97 '--image_file', imgfile,
98 '--image_size', size,
99 '--hwpack-force-yes',
100 '--hwpack', hwpack_file,
101 '--binary', binary_file,
Andy Doanc6500af2012-03-15 14:44:39 -0500102 ]
103
104 if PREINST_SCRIPTS.has_key(hwpack):
105 sdir = os.path.abspath(os.path.dirname(__file__))
106 script = "%s/%s" % (sdir, PREINST_SCRIPTS[hwpack])
107 print "using presintall script: %s" % script
108 args.append('--preinstall-script')
109 args.append(script)
110
Andy Doan15aa23b2012-02-02 16:40:58 -0600111 cmd_runner.run(args, as_root=True).wait()
Andy Doan23ce4e12012-03-21 12:46:21 -0500112 bz2file = compress_image(imgfile)
113 zsync_image(bz2file)
Andy Doan15aa23b2012-02-02 16:40:58 -0600114
Andy Doan184cd3b2012-03-29 22:20:02 -0500115class SnapshotCrawler:
116 def __init__(self, date, platform, hwpacks, binaries):
117 self.date = date
118 self.platform = platform
119 self.hwpacks = hwpacks
120 self.binaries = binaries
Andy Doane449bce2012-03-21 15:22:31 -0500121
Andy Doan184cd3b2012-03-29 22:20:02 -0500122 def get_binaries(self):
123 '''return a hash table of binary->url'''
124 binaryf = {}
125 for binary in self.binaries:
126 url = 'http://snapshots.linaro.org/%s/%s' % (self.platform, binary)
127 (date, url) = crawler.latest_rfs(url)
Andy Doan4202d882012-03-29 21:36:09 -0500128 binaryf[binary] = url
Andy Doan4202d882012-03-29 21:36:09 -0500129
Andy Doan184cd3b2012-03-29 22:20:02 -0500130 return binaryf
Andy Doana3977372012-03-29 12:22:44 -0500131
Andy Doan184cd3b2012-03-29 22:20:02 -0500132 def get_hwpack_url(self, hwpack):
133 hwpackname = "%s-%s" % (hwpack, self.platform)
134 return hwpack_available(self.date, hwpack, self.platform)
Andy Doan4202d882012-03-29 21:36:09 -0500135
Andy Doan184cd3b2012-03-29 22:20:02 -0500136 def get_image_name(self, odir, hwpack, hwpack_url, binary):
137
138 #covert a url like:
139 # http://snapshots.linaro.org/oneiric/lt-origen-oneiric/20120321/1/images/hwpack/hwpack_linaro-lt-origen_20120321-1_armel_supported.tar.gz
140 # to:
141 # oneiric/lt-origen-oneiric/20120321/1/images/<file>.img
142 path = urlparse.urlparse(hwpack_url).path
143 path = os.path.dirname(path)
144 path = os.path.split(path)[0]
145
146 path = '%s/%s' % (odir, path)
147 if not os.path.exists(path):
148 os.makedirs(path)
149 return "%s/%s-%s_%s.img" %(path,hwpack,self.platform,binary)
150
151class ReleaseCrawler:
152 def __init__(self, cycle, platform, hwpacks, binaries):
153 self.cycle = cycle
154 self.platform = platform
155 self.hwpacks = hwpacks
156 self.binaries = binaries
157
158 #inialize our list of hwpacks
159 url = 'http://releases.linaro.org/%s/ubuntu/%s-hwpacks' % (cycle,platform)
160 self.hwpack_urls = crawler.list_hwpacks(url)
161
162 def get_hwpack_url(self, hwpack):
163 pat = re.compile('hwpack_linaro-%s_' % hwpack)
164 for url in self.hwpack_urls:
165 if pat.search(url):
166 return url
167 return None
168
169 def get_binaries(self):
170 '''return a hash table of binary->url'''
171 binaryf = {}
172 for binary in self.binaries:
173 url = 'http://releases.linaro.org/%s/ubuntu/%s-images/%s' % (
174 self.cycle, self.platform, binary)
175 url = crawler.list_rfs(url)
176 if url is not None:
177 binaryf[binary] = url
178 return binaryf
179
180 def get_image_name(self, odir, hwpack, hwpack_url, binary):
181 path = '%s/%s/%s/%s' % (odir, self.cycle, self.platform, binary)
182 if not os.path.exists(path):
183 os.makedirs(path)
184 return "%s/%s-%s.img" %(path,hwpack,binary)
Andy Doan4202d882012-03-29 21:36:09 -0500185
Andy Doan15aa23b2012-02-02 16:40:58 -0600186def main():
187 day = today()
188 hwpacks = HWPACKS.keys()
189 binaries = BINARIES.keys()
190
191 p = argparse.ArgumentParser(description=
Andy Doana3977372012-03-29 12:22:44 -0500192 'Builds a matrix of builds from the latest build on '
193 'snapshots.linaro.org or release images on releases.linaro.org')
Andy Doan15aa23b2012-02-02 16:40:58 -0600194
Andy Doan94bfe312012-02-09 17:57:29 -0800195 p.add_argument('-o', dest='out_dir', default='./out',
Andy Doan15aa23b2012-02-02 16:40:58 -0600196 help='The out directory for downloaded and built files, default=./')
197 p.add_argument('-d', dest='date', default=day,
198 help='The date, default=%s' % day)
199 p.add_argument('-w', dest='hwpacks', action='append',
200 help='The hwpacks to generate for, default=%s' %
201 ', '.join(hwpacks))
202 p.add_argument('-b', dest='binaries', action='append',
203 help='The binaries to generate for, default=%s' %
204 ', '.join(binaries))
205 p.add_argument('-p', dest='platform', default='oneiric',
206 help='The platform, default=oneiric')
Andy Doan4202d882012-03-29 21:36:09 -0500207 p.add_argument('-r', dest='release', action='store_true', default=False,
208 help='If this is for release images. NOTE: the "date" arg'
209 'will then become the cycle ie -d 12.03')
Andy Doan15aa23b2012-02-02 16:40:58 -0600210
211 args = p.parse_args()
Andy Doana3977372012-03-29 12:22:44 -0500212
Andy Doan15aa23b2012-02-02 16:40:58 -0600213 if args.hwpacks:
214 hwpacks = args.hwpacks
215 if args.binaries:
216 binaries = args.binaries
217
218 dm = fetch_image.DownloadManager(args.out_dir)
Andy Doan15aa23b2012-02-02 16:40:58 -0600219
Andy Doan4202d882012-03-29 21:36:09 -0500220 if args.release:
Andy Doan184cd3b2012-03-29 22:20:02 -0500221 site = ReleaseCrawler(args.date, args.platform, hwpacks, binaries)
Andy Doan4202d882012-03-29 21:36:09 -0500222 else:
Andy Doan184cd3b2012-03-29 22:20:02 -0500223 site = SnapshotCrawler(args.date, args.platform, hwpacks, binaries)
224
225 binaryf = site.get_binaries()
Andy Doan15aa23b2012-02-02 16:40:58 -0600226
Andy Doanb00dbc02012-03-15 16:23:06 -0500227 lmc = '%s/linaro-image-tools/linaro-media-create' % args.out_dir
Andy Doan184cd3b2012-03-29 22:20:02 -0500228 odir = '%s/pre-built' % args.out_dir
Andy Doanb00dbc02012-03-15 16:23:06 -0500229
Andy Doan15aa23b2012-02-02 16:40:58 -0600230 for hwpack in hwpacks:
Andy Doan184cd3b2012-03-29 22:20:02 -0500231 url = site.get_hwpack_url(hwpack)
Andy Doanb00dbc02012-03-15 16:23:06 -0500232
Andy Doan2cfe5e62012-02-09 17:41:45 -0800233 if url is not None and url is not False:
Andy Doan15aa23b2012-02-02 16:40:58 -0600234 hwpf = dm.download(url, None)
235 for binary in binaries:
Andy Doan184cd3b2012-03-29 22:20:02 -0500236 imgfile = site.get_image_name(odir,hwpack,url,binary)
Andy Doan81211902012-03-14 14:37:30 -0500237 rfsf = dm.download(binaryf[binary], None)
Andy Doanb00dbc02012-03-15 16:23:06 -0500238 build_image(lmc, imgfile, hwpack, hwpf, binary, rfsf)
Andy Doan15aa23b2012-02-02 16:40:58 -0600239 else:
Andy Doan8ff38f02012-02-20 16:32:37 -0600240 print '%s hwpack not available for %s' % (args.date,hwpack)
Andy Doan15aa23b2012-02-02 16:40:58 -0600241
242if __name__ == '__main__':
243 main()
244