blob: 1def1c00c7a2f4260571ad3f0b36a998a6635f58 [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 Doan15aa23b2012-02-02 16:40:58 -0600123def main():
124 day = today()
125 hwpacks = HWPACKS.keys()
126 binaries = BINARIES.keys()
127
128 p = argparse.ArgumentParser(description=
129 'Builds a matrix of builds from the latest build on snapshots.linaro.org')
130
Andy Doan94bfe312012-02-09 17:57:29 -0800131 p.add_argument('-o', dest='out_dir', default='./out',
Andy Doan15aa23b2012-02-02 16:40:58 -0600132 help='The out directory for downloaded and built files, default=./')
133 p.add_argument('-d', dest='date', default=day,
134 help='The date, default=%s' % day)
135 p.add_argument('-w', dest='hwpacks', action='append',
136 help='The hwpacks to generate for, default=%s' %
137 ', '.join(hwpacks))
138 p.add_argument('-b', dest='binaries', action='append',
139 help='The binaries to generate for, default=%s' %
140 ', '.join(binaries))
141 p.add_argument('-p', dest='platform', default='oneiric',
142 help='The platform, default=oneiric')
143
144 args = p.parse_args()
145 if args.hwpacks:
146 hwpacks = args.hwpacks
147 if args.binaries:
148 binaries = args.binaries
149
150 dm = fetch_image.DownloadManager(args.out_dir)
Andy Doan15aa23b2012-02-02 16:40:58 -0600151
Andy Doan8ff38f02012-02-20 16:32:37 -0600152 binaryf = {}
153 for binary in binaries:
154 url = 'http://snapshots.linaro.org/%s/%s' % (args.platform, binary)
155 (date, url) = crawler.latest_rfs(url)
Andy Doan81211902012-03-14 14:37:30 -0500156 binaryf[binary] = url
Andy Doan15aa23b2012-02-02 16:40:58 -0600157
Andy Doanb00dbc02012-03-15 16:23:06 -0500158 lmc = '%s/linaro-image-tools/linaro-media-create' % args.out_dir
Andy Doane449bce2012-03-21 15:22:31 -0500159 odir_root = '%s/pre-built' % args.out_dir
Andy Doanb00dbc02012-03-15 16:23:06 -0500160
Andy Doan15aa23b2012-02-02 16:40:58 -0600161 for hwpack in hwpacks:
Andy Doan108b8e62012-02-15 14:35:01 -0600162 hwpackname = "%s-%s" % (hwpack, args.platform)
Andy Doan8ff38f02012-02-20 16:32:37 -0600163 url = hwpack_available(args.date, hwpack, args.platform)
Andy Doanb00dbc02012-03-15 16:23:06 -0500164
Andy Doan2cfe5e62012-02-09 17:41:45 -0800165 if url is not None and url is not False:
Andy Doane449bce2012-03-21 15:22:31 -0500166 odir = get_image_dir(odir_root, url)
167
Andy Doan15aa23b2012-02-02 16:40:58 -0600168 hwpf = dm.download(url, None)
169 for binary in binaries:
Andy Doanb00dbc02012-03-15 16:23:06 -0500170 imgfile = "%s/%s-%s_%s.img" %(odir,hwpack,args.platform,binary)
Andy Doan81211902012-03-14 14:37:30 -0500171 rfsf = dm.download(binaryf[binary], None)
Andy Doanb00dbc02012-03-15 16:23:06 -0500172 build_image(lmc, imgfile, hwpack, hwpf, binary, rfsf)
Andy Doan15aa23b2012-02-02 16:40:58 -0600173 else:
Andy Doan8ff38f02012-02-20 16:32:37 -0600174 print '%s hwpack not available for %s' % (args.date,hwpack)
Andy Doan15aa23b2012-02-02 16:40:58 -0600175
176if __name__ == '__main__':
177 main()
178