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 | |
| 23 | from linaro_image_tools import fetch_image |
| 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 |
| 31 | import re |
| 32 | |
| 33 | # a mapping of hwpack name to l-m-c name |
| 34 | HWPACKS = { |
Andy Doan | abd4677 | 2012-02-15 18:38:01 -0600 | [diff] [blame] | 35 | 'omap3': 'beagle', |
Andy Doan | 108b8e6 | 2012-02-15 14:35:01 -0600 | [diff] [blame] | 36 | 'overo': 'overo', |
Andy Doan | abd4677 | 2012-02-15 18:38:01 -0600 | [diff] [blame] | 37 | '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 Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 44 | } |
| 45 | # a mapping of binary image to its image_file size |
| 46 | BINARIES = { |
| 47 | 'linaro-o-nano': '512M', |
| 48 | 'linaro-o-alip': '2G', |
| 49 | 'linaro-o-ubuntu-desktop': '3G', |
| 50 | } |
| 51 | |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 52 | def today(): |
| 53 | d = datetime.date.today() |
| 54 | return "%d%02d%02d" % (d.year, d.month, d.day) |
| 55 | |
Andy Doan | 8ff38f0 | 2012-02-20 16:32:37 -0600 | [diff] [blame^] | 56 | def 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 Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 63 | return False |
| 64 | |
| 65 | def compress_image(imgfile): |
| 66 | print "compressing %s" % imgfile |
| 67 | args = ('bzip2', imgfile) |
| 68 | cmd_runner.run(args).wait() |
| 69 | |
Andy Doan | 108b8e6 | 2012-02-15 14:35:01 -0600 | [diff] [blame] | 70 | def build_image(outdir, platform, hwpack, hwpack_file, binary, binary_file): |
| 71 | imgfile = "%s/%s-%s_%s.img" %(outdir,hwpack,platform,binary) |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 72 | print "building image: %s" % imgfile |
| 73 | dev = HWPACKS[hwpack] |
| 74 | size = BINARIES[binary] |
| 75 | |
Andy Doan | abe13fc | 2012-02-09 16:00:01 -0800 | [diff] [blame] | 76 | lmc = '%s/linaro-image-tools/linaro-media-create' % outdir |
Andy Doan | 4fa16dc | 2012-02-09 17:47:45 -0800 | [diff] [blame] | 77 | print 'running l-m-c: %s' % lmc |
Andy Doan | abe13fc | 2012-02-09 16:00:01 -0800 | [diff] [blame] | 78 | args = (lmc, |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 79 | '--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 | |
| 89 | def 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 Doan | 94bfe31 | 2012-02-09 17:57:29 -0800 | [diff] [blame] | 97 | p.add_argument('-o', dest='out_dir', default='./out', |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 98 | 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 Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 117 | |
Andy Doan | 8ff38f0 | 2012-02-20 16:32:37 -0600 | [diff] [blame^] | 118 | 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 Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 123 | |
| 124 | for hwpack in hwpacks: |
Andy Doan | 108b8e6 | 2012-02-15 14:35:01 -0600 | [diff] [blame] | 125 | hwpackname = "%s-%s" % (hwpack, args.platform) |
Andy Doan | 8ff38f0 | 2012-02-20 16:32:37 -0600 | [diff] [blame^] | 126 | url = hwpack_available(args.date, hwpack, args.platform) |
Andy Doan | 2cfe5e6 | 2012-02-09 17:41:45 -0800 | [diff] [blame] | 127 | if url is not None and url is not False: |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 128 | hwpf = dm.download(url, None) |
| 129 | for binary in binaries: |
Andy Doan | 8ff38f0 | 2012-02-20 16:32:37 -0600 | [diff] [blame^] | 130 | build_image(args.out_dir, args.platform, hwpack, hwpf, binary, binaryf[binary]) |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 131 | else: |
Andy Doan | 8ff38f0 | 2012-02-20 16:32:37 -0600 | [diff] [blame^] | 132 | print '%s hwpack not available for %s' % (args.date,hwpack) |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 133 | |
| 134 | if __name__ == '__main__': |
| 135 | main() |
| 136 | |