Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 1 | #!/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 Doan | fccf484 | 2012-03-08 10:42:19 -0600 | [diff] [blame] | 23 | from linaro_fetch_image import fetch_image |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 24 | from linaro_image_tools import cmd_runner |
| 25 | |
Andy Doan | 8ff38f0 | 2012-02-20 16:32:37 -0600 | [diff] [blame] | 26 | import crawler |
| 27 | |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 28 | import argparse |
| 29 | import bz2 |
| 30 | import datetime |
Andy Doan | c6500af | 2012-03-15 14:44:39 -0500 | [diff] [blame] | 31 | import os |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 32 | import re |
| 33 | |
| 34 | # a mapping of hwpack name to l-m-c name |
| 35 | HWPACKS = { |
Andy Doan | abd4677 | 2012-02-15 18:38:01 -0600 | [diff] [blame] | 36 | 'omap3': 'beagle', |
Andy Doan | 108b8e6 | 2012-02-15 14:35:01 -0600 | [diff] [blame] | 37 | 'overo': 'overo', |
Andy Doan | abd4677 | 2012-02-15 18:38:01 -0600 | [diff] [blame] | 38 | '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 Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 45 | } |
| 46 | # a mapping of binary image to its image_file size |
| 47 | BINARIES = { |
| 48 | 'linaro-o-nano': '512M', |
| 49 | 'linaro-o-alip': '2G', |
| 50 | 'linaro-o-ubuntu-desktop': '3G', |
| 51 | } |
| 52 | |
Andy Doan | c6500af | 2012-03-15 14:44:39 -0500 | [diff] [blame] | 53 | PREINST_SCRIPTS = { |
| 54 | 'lt-snowball': 'ste-preinstall.sh', |
| 55 | } |
| 56 | |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 57 | def today(): |
| 58 | d = datetime.date.today() |
| 59 | return "%d%02d%02d" % (d.year, d.month, d.day) |
| 60 | |
Andy Doan | 8ff38f0 | 2012-02-20 16:32:37 -0600 | [diff] [blame] | 61 | def 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 Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 68 | return False |
| 69 | |
| 70 | def compress_image(imgfile): |
| 71 | print "compressing %s" % imgfile |
| 72 | args = ('bzip2', imgfile) |
| 73 | cmd_runner.run(args).wait() |
Andy Doan | 23ce4e1 | 2012-03-21 12:46:21 -0500 | [diff] [blame] | 74 | return '%s.bz2' % imgfile |
| 75 | |
| 76 | def 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 Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 80 | |
Andy Doan | b00dbc0 | 2012-03-15 16:23:06 -0500 | [diff] [blame] | 81 | def build_image(lmc, imgfile, hwpack, hwpack_file, binary, binary_file): |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 82 | print "building image: %s" % imgfile |
| 83 | dev = HWPACKS[hwpack] |
| 84 | size = BINARIES[binary] |
| 85 | |
Andy Doan | 4fa16dc | 2012-02-09 17:47:45 -0800 | [diff] [blame] | 86 | print 'running l-m-c: %s' % lmc |
Andy Doan | c6500af | 2012-03-15 14:44:39 -0500 | [diff] [blame] | 87 | args = [lmc, |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 88 | '--dev', dev, |
| 89 | '--image_file', imgfile, |
| 90 | '--image_size', size, |
| 91 | '--hwpack-force-yes', |
| 92 | '--hwpack', hwpack_file, |
| 93 | '--binary', binary_file, |
Andy Doan | c6500af | 2012-03-15 14:44:39 -0500 | [diff] [blame] | 94 | ] |
| 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 Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 103 | cmd_runner.run(args, as_root=True).wait() |
Andy Doan | 23ce4e1 | 2012-03-21 12:46:21 -0500 | [diff] [blame] | 104 | bz2file = compress_image(imgfile) |
| 105 | zsync_image(bz2file) |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 106 | |
| 107 | def 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 Doan | 94bfe31 | 2012-02-09 17:57:29 -0800 | [diff] [blame] | 115 | p.add_argument('-o', dest='out_dir', default='./out', |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 116 | 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 Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 135 | |
Andy Doan | 8ff38f0 | 2012-02-20 16:32:37 -0600 | [diff] [blame] | 136 | 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 Doan | 8121190 | 2012-03-14 14:37:30 -0500 | [diff] [blame] | 140 | binaryf[binary] = url |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 141 | |
Andy Doan | b00dbc0 | 2012-03-15 16:23:06 -0500 | [diff] [blame] | 142 | 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 Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 147 | for hwpack in hwpacks: |
Andy Doan | 108b8e6 | 2012-02-15 14:35:01 -0600 | [diff] [blame] | 148 | hwpackname = "%s-%s" % (hwpack, args.platform) |
Andy Doan | 8ff38f0 | 2012-02-20 16:32:37 -0600 | [diff] [blame] | 149 | url = hwpack_available(args.date, hwpack, args.platform) |
Andy Doan | b00dbc0 | 2012-03-15 16:23:06 -0500 | [diff] [blame] | 150 | |
Andy Doan | 2cfe5e6 | 2012-02-09 17:41:45 -0800 | [diff] [blame] | 151 | if url is not None and url is not False: |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 152 | hwpf = dm.download(url, None) |
| 153 | for binary in binaries: |
Andy Doan | b00dbc0 | 2012-03-15 16:23:06 -0500 | [diff] [blame] | 154 | imgfile = "%s/%s-%s_%s.img" %(odir,hwpack,args.platform,binary) |
Andy Doan | 8121190 | 2012-03-14 14:37:30 -0500 | [diff] [blame] | 155 | rfsf = dm.download(binaryf[binary], None) |
Andy Doan | b00dbc0 | 2012-03-15 16:23:06 -0500 | [diff] [blame] | 156 | build_image(lmc, imgfile, hwpack, hwpf, binary, rfsf) |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 157 | else: |
Andy Doan | 8ff38f0 | 2012-02-20 16:32:37 -0600 | [diff] [blame] | 158 | print '%s hwpack not available for %s' % (args.date,hwpack) |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 159 | |
| 160 | if __name__ == '__main__': |
| 161 | main() |
| 162 | |