blob: a16da69d5cf7992d57c18c03d30b44b32054c51a [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 Doan15aa23b2012-02-02 16:40:58 -060034
35# a mapping of hwpack name to l-m-c name
36HWPACKS = {
Andy Doanabd46772012-02-15 18:38:01 -060037 'omap3': 'beagle',
Andy Doan108b8e62012-02-15 14:35:01 -060038 'overo': 'overo',
Andy Doanabd46772012-02-15 18:38:01 -060039 'lt-panda': 'panda',
40 'lt-mx5':'mx53loco',
41 'lt-mx6': 'mx6qsabrelite',
42 'lt-origen': 'origen',
43 'lt-snowball': 'snowball_sd',
44 'lt-vexpress-a9': 'vexpress-a9',
45 'efikamx': 'efikamx',
Andy Doan15aa23b2012-02-02 16:40:58 -060046}
47# a mapping of binary image to its image_file size
48BINARIES = {
49 'linaro-o-nano': '512M',
50 'linaro-o-alip': '2G',
51 'linaro-o-ubuntu-desktop': '3G',
52}
53
Andy Doanc6500af2012-03-15 14:44:39 -050054PREINST_SCRIPTS = {
55 'lt-snowball': 'ste-preinstall.sh',
56}
57
Andy Doan15aa23b2012-02-02 16:40:58 -060058def today():
59 d = datetime.date.today()
60 return "%d%02d%02d" % (d.year, d.month, d.day)
61
Andy Doan8ff38f02012-02-20 16:32:37 -060062def hwpack_available(date, hwpack, platform):
63 url = 'http://snapshots.linaro.org/%s/%s-%s' % (platform, hwpack, platform)
64 hwpacks = crawler.latest_hwpacks(url)
65 for hwpack in hwpacks:
66 if hwpack[0] == date:
67 return hwpack[1]
68
Andy Doan15aa23b2012-02-02 16:40:58 -060069 return False
70
71def compress_image(imgfile):
72 print "compressing %s" % imgfile
73 args = ('bzip2', imgfile)
74 cmd_runner.run(args).wait()
Andy Doan23ce4e12012-03-21 12:46:21 -050075 return '%s.bz2' % imgfile
76
77def zsync_image(imgfile):
78 print "making zsync file for %s" % imgfile
79 args = ('zsyncmake', '-o', '%s.zsync'%imgfile, imgfile)
80 cmd_runner.run(args).wait()
Andy Doan15aa23b2012-02-02 16:40:58 -060081
Andy Doanb00dbc02012-03-15 16:23:06 -050082def build_image(lmc, imgfile, hwpack, hwpack_file, binary, binary_file):
Andy Doan15aa23b2012-02-02 16:40:58 -060083 print "building image: %s" % imgfile
84 dev = HWPACKS[hwpack]
85 size = BINARIES[binary]
86
Andy Doan4fa16dc2012-02-09 17:47:45 -080087 print 'running l-m-c: %s' % lmc
Andy Doanc6500af2012-03-15 14:44:39 -050088 args = [lmc,
Andy Doan15aa23b2012-02-02 16:40:58 -060089 '--dev', dev,
90 '--image_file', imgfile,
91 '--image_size', size,
92 '--hwpack-force-yes',
93 '--hwpack', hwpack_file,
94 '--binary', binary_file,
Andy Doanc6500af2012-03-15 14:44:39 -050095 ]
96
97 if PREINST_SCRIPTS.has_key(hwpack):
98 sdir = os.path.abspath(os.path.dirname(__file__))
99 script = "%s/%s" % (sdir, PREINST_SCRIPTS[hwpack])
100 print "using presintall script: %s" % script
101 args.append('--preinstall-script')
102 args.append(script)
103
Andy Doan15aa23b2012-02-02 16:40:58 -0600104 cmd_runner.run(args, as_root=True).wait()
Andy Doan23ce4e12012-03-21 12:46:21 -0500105 bz2file = compress_image(imgfile)
106 zsync_image(bz2file)
Andy Doan15aa23b2012-02-02 16:40:58 -0600107
Andy Doane449bce2012-03-21 15:22:31 -0500108def get_image_dir(outdir, url):
109 '''covert a url like:
110 http://snapshots.linaro.org/oneiric/lt-origen-oneiric/20120321/1/images/hwpack/hwpack_linaro-lt-origen_20120321-1_armel_supported.tar.gz
111 to:
112 oneiric/lt-origen-oneiric/20120321/1/images
113 '''
114 path = urlparse.urlparse(url).path
115 path = os.path.dirname(path)
116 path = os.path.split(path)[0]
117
118 path = '%s/%s' % (outdir, path)
119 if not os.path.exists(path):
120 os.makedirs(path)
121 return path
122
Andy Doana3977372012-03-29 12:22:44 -0500123def get_snapshot_binaries(binaries, platform):
124 binaryf = {}
125 for binary in binaries:
126 url = 'http://snapshots.linaro.org/%s/%s' % (platform, binary)
127 (date, url) = crawler.latest_rfs(url)
128 binaryf[binary] = url
129
130 return binaryf
131
132def get_snapshot_hwpack(date, hwpack, platform):
133 ''' returns the url to the hwpack on snapshots.l.o if it exists'''
134 hwpackname = "%s-%s" % (hwpack, platform)
135 return hwpack_available(date, hwpack, platform)
136
Andy Doan15aa23b2012-02-02 16:40:58 -0600137def main():
138 day = today()
139 hwpacks = HWPACKS.keys()
140 binaries = BINARIES.keys()
141
142 p = argparse.ArgumentParser(description=
Andy Doana3977372012-03-29 12:22:44 -0500143 'Builds a matrix of builds from the latest build on '
144 'snapshots.linaro.org or release images on releases.linaro.org')
Andy Doan15aa23b2012-02-02 16:40:58 -0600145
Andy Doan94bfe312012-02-09 17:57:29 -0800146 p.add_argument('-o', dest='out_dir', default='./out',
Andy Doan15aa23b2012-02-02 16:40:58 -0600147 help='The out directory for downloaded and built files, default=./')
148 p.add_argument('-d', dest='date', default=day,
149 help='The date, default=%s' % day)
150 p.add_argument('-w', dest='hwpacks', action='append',
151 help='The hwpacks to generate for, default=%s' %
152 ', '.join(hwpacks))
153 p.add_argument('-b', dest='binaries', action='append',
154 help='The binaries to generate for, default=%s' %
155 ', '.join(binaries))
156 p.add_argument('-p', dest='platform', default='oneiric',
157 help='The platform, default=oneiric')
158
159 args = p.parse_args()
Andy Doana3977372012-03-29 12:22:44 -0500160
Andy Doan15aa23b2012-02-02 16:40:58 -0600161 if args.hwpacks:
162 hwpacks = args.hwpacks
163 if args.binaries:
164 binaries = args.binaries
165
166 dm = fetch_image.DownloadManager(args.out_dir)
Andy Doan15aa23b2012-02-02 16:40:58 -0600167
Andy Doana3977372012-03-29 12:22:44 -0500168 binaryf = get_snapshot_binaries(binaries, args.platform)
Andy Doan15aa23b2012-02-02 16:40:58 -0600169
Andy Doanb00dbc02012-03-15 16:23:06 -0500170 lmc = '%s/linaro-image-tools/linaro-media-create' % args.out_dir
Andy Doane449bce2012-03-21 15:22:31 -0500171 odir_root = '%s/pre-built' % args.out_dir
Andy Doanb00dbc02012-03-15 16:23:06 -0500172
Andy Doan15aa23b2012-02-02 16:40:58 -0600173 for hwpack in hwpacks:
Andy Doana3977372012-03-29 12:22:44 -0500174 url = get_snapshot_hwpack(args.date, hwpack, args.platform)
Andy Doanb00dbc02012-03-15 16:23:06 -0500175
Andy Doan2cfe5e62012-02-09 17:41:45 -0800176 if url is not None and url is not False:
Andy Doane449bce2012-03-21 15:22:31 -0500177 odir = get_image_dir(odir_root, url)
178
Andy Doan15aa23b2012-02-02 16:40:58 -0600179 hwpf = dm.download(url, None)
180 for binary in binaries:
Andy Doanb00dbc02012-03-15 16:23:06 -0500181 imgfile = "%s/%s-%s_%s.img" %(odir,hwpack,args.platform,binary)
Andy Doan81211902012-03-14 14:37:30 -0500182 rfsf = dm.download(binaryf[binary], None)
Andy Doanb00dbc02012-03-15 16:23:06 -0500183 build_image(lmc, imgfile, hwpack, hwpf, binary, rfsf)
Andy Doan15aa23b2012-02-02 16:40:58 -0600184 else:
Andy Doan8ff38f02012-02-20 16:32:37 -0600185 print '%s hwpack not available for %s' % (args.date,hwpack)
Andy Doan15aa23b2012-02-02 16:40:58 -0600186
187if __name__ == '__main__':
188 main()
189