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 |
Andy Doan | e449bce | 2012-03-21 15:22:31 -0500 | [diff] [blame^] | 33 | import urlparse |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 34 | |
| 35 | # a mapping of hwpack name to l-m-c name |
| 36 | HWPACKS = { |
Andy Doan | abd4677 | 2012-02-15 18:38:01 -0600 | [diff] [blame] | 37 | 'omap3': 'beagle', |
Andy Doan | 108b8e6 | 2012-02-15 14:35:01 -0600 | [diff] [blame] | 38 | 'overo': 'overo', |
Andy Doan | abd4677 | 2012-02-15 18:38:01 -0600 | [diff] [blame] | 39 | '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 Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 46 | } |
| 47 | # a mapping of binary image to its image_file size |
| 48 | BINARIES = { |
| 49 | 'linaro-o-nano': '512M', |
| 50 | 'linaro-o-alip': '2G', |
| 51 | 'linaro-o-ubuntu-desktop': '3G', |
| 52 | } |
| 53 | |
Andy Doan | c6500af | 2012-03-15 14:44:39 -0500 | [diff] [blame] | 54 | PREINST_SCRIPTS = { |
| 55 | 'lt-snowball': 'ste-preinstall.sh', |
| 56 | } |
| 57 | |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 58 | def today(): |
| 59 | d = datetime.date.today() |
| 60 | return "%d%02d%02d" % (d.year, d.month, d.day) |
| 61 | |
Andy Doan | 8ff38f0 | 2012-02-20 16:32:37 -0600 | [diff] [blame] | 62 | def 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 Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 69 | return False |
| 70 | |
| 71 | def compress_image(imgfile): |
| 72 | print "compressing %s" % imgfile |
| 73 | args = ('bzip2', imgfile) |
| 74 | cmd_runner.run(args).wait() |
Andy Doan | 23ce4e1 | 2012-03-21 12:46:21 -0500 | [diff] [blame] | 75 | return '%s.bz2' % imgfile |
| 76 | |
| 77 | def 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 Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 81 | |
Andy Doan | b00dbc0 | 2012-03-15 16:23:06 -0500 | [diff] [blame] | 82 | def build_image(lmc, imgfile, hwpack, hwpack_file, binary, binary_file): |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 83 | print "building image: %s" % imgfile |
| 84 | dev = HWPACKS[hwpack] |
| 85 | size = BINARIES[binary] |
| 86 | |
Andy Doan | 4fa16dc | 2012-02-09 17:47:45 -0800 | [diff] [blame] | 87 | print 'running l-m-c: %s' % lmc |
Andy Doan | c6500af | 2012-03-15 14:44:39 -0500 | [diff] [blame] | 88 | args = [lmc, |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 89 | '--dev', dev, |
| 90 | '--image_file', imgfile, |
| 91 | '--image_size', size, |
| 92 | '--hwpack-force-yes', |
| 93 | '--hwpack', hwpack_file, |
| 94 | '--binary', binary_file, |
Andy Doan | c6500af | 2012-03-15 14:44:39 -0500 | [diff] [blame] | 95 | ] |
| 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 Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 104 | cmd_runner.run(args, as_root=True).wait() |
Andy Doan | 23ce4e1 | 2012-03-21 12:46:21 -0500 | [diff] [blame] | 105 | bz2file = compress_image(imgfile) |
| 106 | zsync_image(bz2file) |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 107 | |
Andy Doan | e449bce | 2012-03-21 15:22:31 -0500 | [diff] [blame^] | 108 | def 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 Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 123 | def 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 Doan | 94bfe31 | 2012-02-09 17:57:29 -0800 | [diff] [blame] | 131 | p.add_argument('-o', dest='out_dir', default='./out', |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 132 | 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 Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 151 | |
Andy Doan | 8ff38f0 | 2012-02-20 16:32:37 -0600 | [diff] [blame] | 152 | 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 Doan | 8121190 | 2012-03-14 14:37:30 -0500 | [diff] [blame] | 156 | binaryf[binary] = url |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 157 | |
Andy Doan | b00dbc0 | 2012-03-15 16:23:06 -0500 | [diff] [blame] | 158 | lmc = '%s/linaro-image-tools/linaro-media-create' % args.out_dir |
Andy Doan | e449bce | 2012-03-21 15:22:31 -0500 | [diff] [blame^] | 159 | odir_root = '%s/pre-built' % args.out_dir |
Andy Doan | b00dbc0 | 2012-03-15 16:23:06 -0500 | [diff] [blame] | 160 | |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 161 | for hwpack in hwpacks: |
Andy Doan | 108b8e6 | 2012-02-15 14:35:01 -0600 | [diff] [blame] | 162 | hwpackname = "%s-%s" % (hwpack, args.platform) |
Andy Doan | 8ff38f0 | 2012-02-20 16:32:37 -0600 | [diff] [blame] | 163 | url = hwpack_available(args.date, hwpack, args.platform) |
Andy Doan | b00dbc0 | 2012-03-15 16:23:06 -0500 | [diff] [blame] | 164 | |
Andy Doan | 2cfe5e6 | 2012-02-09 17:41:45 -0800 | [diff] [blame] | 165 | if url is not None and url is not False: |
Andy Doan | e449bce | 2012-03-21 15:22:31 -0500 | [diff] [blame^] | 166 | odir = get_image_dir(odir_root, url) |
| 167 | |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 168 | hwpf = dm.download(url, None) |
| 169 | for binary in binaries: |
Andy Doan | b00dbc0 | 2012-03-15 16:23:06 -0500 | [diff] [blame] | 170 | imgfile = "%s/%s-%s_%s.img" %(odir,hwpack,args.platform,binary) |
Andy Doan | 8121190 | 2012-03-14 14:37:30 -0500 | [diff] [blame] | 171 | rfsf = dm.download(binaryf[binary], None) |
Andy Doan | b00dbc0 | 2012-03-15 16:23:06 -0500 | [diff] [blame] | 172 | build_image(lmc, imgfile, hwpack, hwpf, binary, rfsf) |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 173 | else: |
Andy Doan | 8ff38f0 | 2012-02-20 16:32:37 -0600 | [diff] [blame] | 174 | print '%s hwpack not available for %s' % (args.date,hwpack) |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 175 | |
| 176 | if __name__ == '__main__': |
| 177 | main() |
| 178 | |