blob: 30dcfe37208bd0c1610eda80cbf1217da0e47c51 [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
33
34# a mapping of hwpack name to l-m-c name
35HWPACKS = {
Andy Doanabd46772012-02-15 18:38:01 -060036 'omap3': 'beagle',
Andy Doan108b8e62012-02-15 14:35:01 -060037 'overo': 'overo',
Andy Doanabd46772012-02-15 18:38:01 -060038 'lt-panda': 'panda',
39 'lt-mx5':'mx53loco',
40 'lt-mx6': 'mx6qsabrelite',
41 'lt-origen': 'origen',
42 'lt-snowball': 'snowball_sd',
43 'lt-vexpress-a9': 'vexpress-a9',
44 'efikamx': 'efikamx',
Andy Doan15aa23b2012-02-02 16:40:58 -060045}
46# a mapping of binary image to its image_file size
47BINARIES = {
48 'linaro-o-nano': '512M',
49 'linaro-o-alip': '2G',
50 'linaro-o-ubuntu-desktop': '3G',
51}
52
Andy Doanc6500af2012-03-15 14:44:39 -050053PREINST_SCRIPTS = {
54 'lt-snowball': 'ste-preinstall.sh',
55}
56
Andy Doan15aa23b2012-02-02 16:40:58 -060057def today():
58 d = datetime.date.today()
59 return "%d%02d%02d" % (d.year, d.month, d.day)
60
Andy Doan8ff38f02012-02-20 16:32:37 -060061def hwpack_available(date, hwpack, platform):
62 url = 'http://snapshots.linaro.org/%s/%s-%s' % (platform, hwpack, platform)
63 hwpacks = crawler.latest_hwpacks(url)
64 for hwpack in hwpacks:
65 if hwpack[0] == date:
66 return hwpack[1]
67
Andy Doan15aa23b2012-02-02 16:40:58 -060068 return False
69
70def compress_image(imgfile):
71 print "compressing %s" % imgfile
72 args = ('bzip2', imgfile)
73 cmd_runner.run(args).wait()
Andy Doan23ce4e12012-03-21 12:46:21 -050074 return '%s.bz2' % imgfile
75
76def zsync_image(imgfile):
77 print "making zsync file for %s" % imgfile
78 args = ('zsyncmake', '-o', '%s.zsync'%imgfile, imgfile)
79 cmd_runner.run(args).wait()
Andy Doan15aa23b2012-02-02 16:40:58 -060080
Andy Doanb00dbc02012-03-15 16:23:06 -050081def build_image(lmc, imgfile, hwpack, hwpack_file, binary, binary_file):
Andy Doan15aa23b2012-02-02 16:40:58 -060082 print "building image: %s" % imgfile
83 dev = HWPACKS[hwpack]
84 size = BINARIES[binary]
85
Andy Doan4fa16dc2012-02-09 17:47:45 -080086 print 'running l-m-c: %s' % lmc
Andy Doanc6500af2012-03-15 14:44:39 -050087 args = [lmc,
Andy Doan15aa23b2012-02-02 16:40:58 -060088 '--dev', dev,
89 '--image_file', imgfile,
90 '--image_size', size,
91 '--hwpack-force-yes',
92 '--hwpack', hwpack_file,
93 '--binary', binary_file,
Andy Doanc6500af2012-03-15 14:44:39 -050094 ]
95
96 if PREINST_SCRIPTS.has_key(hwpack):
97 sdir = os.path.abspath(os.path.dirname(__file__))
98 script = "%s/%s" % (sdir, PREINST_SCRIPTS[hwpack])
99 print "using presintall script: %s" % script
100 args.append('--preinstall-script')
101 args.append(script)
102
Andy Doan15aa23b2012-02-02 16:40:58 -0600103 cmd_runner.run(args, as_root=True).wait()
Andy Doan23ce4e12012-03-21 12:46:21 -0500104 bz2file = compress_image(imgfile)
105 zsync_image(bz2file)
Andy Doan15aa23b2012-02-02 16:40:58 -0600106
107def main():
108 day = today()
109 hwpacks = HWPACKS.keys()
110 binaries = BINARIES.keys()
111
112 p = argparse.ArgumentParser(description=
113 'Builds a matrix of builds from the latest build on snapshots.linaro.org')
114
Andy Doan94bfe312012-02-09 17:57:29 -0800115 p.add_argument('-o', dest='out_dir', default='./out',
Andy Doan15aa23b2012-02-02 16:40:58 -0600116 help='The out directory for downloaded and built files, default=./')
117 p.add_argument('-d', dest='date', default=day,
118 help='The date, default=%s' % day)
119 p.add_argument('-w', dest='hwpacks', action='append',
120 help='The hwpacks to generate for, default=%s' %
121 ', '.join(hwpacks))
122 p.add_argument('-b', dest='binaries', action='append',
123 help='The binaries to generate for, default=%s' %
124 ', '.join(binaries))
125 p.add_argument('-p', dest='platform', default='oneiric',
126 help='The platform, default=oneiric')
127
128 args = p.parse_args()
129 if args.hwpacks:
130 hwpacks = args.hwpacks
131 if args.binaries:
132 binaries = args.binaries
133
134 dm = fetch_image.DownloadManager(args.out_dir)
Andy Doan15aa23b2012-02-02 16:40:58 -0600135
Andy Doan8ff38f02012-02-20 16:32:37 -0600136 binaryf = {}
137 for binary in binaries:
138 url = 'http://snapshots.linaro.org/%s/%s' % (args.platform, binary)
139 (date, url) = crawler.latest_rfs(url)
Andy Doan81211902012-03-14 14:37:30 -0500140 binaryf[binary] = url
Andy Doan15aa23b2012-02-02 16:40:58 -0600141
Andy Doanb00dbc02012-03-15 16:23:06 -0500142 lmc = '%s/linaro-image-tools/linaro-media-create' % args.out_dir
143 odir = '%s/%s' % (args.out_dir, args.date)
144 if not os.path.exists(odir):
145 os.mkdir(odir)
146
Andy Doan15aa23b2012-02-02 16:40:58 -0600147 for hwpack in hwpacks:
Andy Doan108b8e62012-02-15 14:35:01 -0600148 hwpackname = "%s-%s" % (hwpack, args.platform)
Andy Doan8ff38f02012-02-20 16:32:37 -0600149 url = hwpack_available(args.date, hwpack, args.platform)
Andy Doanb00dbc02012-03-15 16:23:06 -0500150
Andy Doan2cfe5e62012-02-09 17:41:45 -0800151 if url is not None and url is not False:
Andy Doan15aa23b2012-02-02 16:40:58 -0600152 hwpf = dm.download(url, None)
153 for binary in binaries:
Andy Doanb00dbc02012-03-15 16:23:06 -0500154 imgfile = "%s/%s-%s_%s.img" %(odir,hwpack,args.platform,binary)
Andy Doan81211902012-03-14 14:37:30 -0500155 rfsf = dm.download(binaryf[binary], None)
Andy Doanb00dbc02012-03-15 16:23:06 -0500156 build_image(lmc, imgfile, hwpack, hwpf, binary, rfsf)
Andy Doan15aa23b2012-02-02 16:40:58 -0600157 else:
Andy Doan8ff38f02012-02-20 16:32:37 -0600158 print '%s hwpack not available for %s' % (args.date,hwpack)
Andy Doan15aa23b2012-02-02 16:40:58 -0600159
160if __name__ == '__main__':
161 main()
162