blob: 2294826d360c9fcb33ec0f474ba7c5b91443b325 [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
23from linaro_image_tools import fetch_image
24from 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
31import re
32
33# a mapping of hwpack name to l-m-c name
34HWPACKS = {
Andy Doanabd46772012-02-15 18:38:01 -060035 'omap3': 'beagle',
Andy Doan108b8e62012-02-15 14:35:01 -060036 'overo': 'overo',
Andy Doanabd46772012-02-15 18:38:01 -060037 'lt-panda': 'panda',
38 'lt-mx5':'mx53loco',
39 'lt-mx6': 'mx6qsabrelite',
40 'lt-origen': 'origen',
41 'lt-snowball': 'snowball_sd',
42 'lt-vexpress-a9': 'vexpress-a9',
43 'efikamx': 'efikamx',
Andy Doan15aa23b2012-02-02 16:40:58 -060044}
45# a mapping of binary image to its image_file size
46BINARIES = {
47 'linaro-o-nano': '512M',
48 'linaro-o-alip': '2G',
49 'linaro-o-ubuntu-desktop': '3G',
50}
51
Andy Doan15aa23b2012-02-02 16:40:58 -060052def today():
53 d = datetime.date.today()
54 return "%d%02d%02d" % (d.year, d.month, d.day)
55
Andy Doan8ff38f02012-02-20 16:32:37 -060056def hwpack_available(date, hwpack, platform):
57 url = 'http://snapshots.linaro.org/%s/%s-%s' % (platform, hwpack, platform)
58 hwpacks = crawler.latest_hwpacks(url)
59 for hwpack in hwpacks:
60 if hwpack[0] == date:
61 return hwpack[1]
62
Andy Doan15aa23b2012-02-02 16:40:58 -060063 return False
64
65def compress_image(imgfile):
66 print "compressing %s" % imgfile
67 args = ('bzip2', imgfile)
68 cmd_runner.run(args).wait()
69
Andy Doan108b8e62012-02-15 14:35:01 -060070def build_image(outdir, platform, hwpack, hwpack_file, binary, binary_file):
71 imgfile = "%s/%s-%s_%s.img" %(outdir,hwpack,platform,binary)
Andy Doan15aa23b2012-02-02 16:40:58 -060072 print "building image: %s" % imgfile
73 dev = HWPACKS[hwpack]
74 size = BINARIES[binary]
75
Andy Doanabe13fc2012-02-09 16:00:01 -080076 lmc = '%s/linaro-image-tools/linaro-media-create' % outdir
Andy Doan4fa16dc2012-02-09 17:47:45 -080077 print 'running l-m-c: %s' % lmc
Andy Doanabe13fc2012-02-09 16:00:01 -080078 args = (lmc,
Andy Doan15aa23b2012-02-02 16:40:58 -060079 '--dev', dev,
80 '--image_file', imgfile,
81 '--image_size', size,
82 '--hwpack-force-yes',
83 '--hwpack', hwpack_file,
84 '--binary', binary_file,
85 )
86 cmd_runner.run(args, as_root=True).wait()
87 compress_image(imgfile)
88
89def main():
90 day = today()
91 hwpacks = HWPACKS.keys()
92 binaries = BINARIES.keys()
93
94 p = argparse.ArgumentParser(description=
95 'Builds a matrix of builds from the latest build on snapshots.linaro.org')
96
Andy Doan94bfe312012-02-09 17:57:29 -080097 p.add_argument('-o', dest='out_dir', default='./out',
Andy Doan15aa23b2012-02-02 16:40:58 -060098 help='The out directory for downloaded and built files, default=./')
99 p.add_argument('-d', dest='date', default=day,
100 help='The date, default=%s' % day)
101 p.add_argument('-w', dest='hwpacks', action='append',
102 help='The hwpacks to generate for, default=%s' %
103 ', '.join(hwpacks))
104 p.add_argument('-b', dest='binaries', action='append',
105 help='The binaries to generate for, default=%s' %
106 ', '.join(binaries))
107 p.add_argument('-p', dest='platform', default='oneiric',
108 help='The platform, default=oneiric')
109
110 args = p.parse_args()
111 if args.hwpacks:
112 hwpacks = args.hwpacks
113 if args.binaries:
114 binaries = args.binaries
115
116 dm = fetch_image.DownloadManager(args.out_dir)
Andy Doan15aa23b2012-02-02 16:40:58 -0600117
Andy Doan8ff38f02012-02-20 16:32:37 -0600118 binaryf = {}
119 for binary in binaries:
120 url = 'http://snapshots.linaro.org/%s/%s' % (args.platform, binary)
121 (date, url) = crawler.latest_rfs(url)
122 binaryf[binary] = dm.download(url, None)
Andy Doan15aa23b2012-02-02 16:40:58 -0600123
124 for hwpack in hwpacks:
Andy Doan108b8e62012-02-15 14:35:01 -0600125 hwpackname = "%s-%s" % (hwpack, args.platform)
Andy Doan8ff38f02012-02-20 16:32:37 -0600126 url = hwpack_available(args.date, hwpack, args.platform)
Andy Doan2cfe5e62012-02-09 17:41:45 -0800127 if url is not None and url is not False:
Andy Doan15aa23b2012-02-02 16:40:58 -0600128 hwpf = dm.download(url, None)
129 for binary in binaries:
Andy Doan8ff38f02012-02-20 16:32:37 -0600130 build_image(args.out_dir, args.platform, hwpack, hwpf, binary, binaryf[binary])
Andy Doan15aa23b2012-02-02 16:40:58 -0600131 else:
Andy Doan8ff38f02012-02-20 16:32:37 -0600132 print '%s hwpack not available for %s' % (args.date,hwpack)
Andy Doan15aa23b2012-02-02 16:40:58 -0600133
134if __name__ == '__main__':
135 main()
136