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 | 4202d88 | 2012-03-29 21:36:09 -0500 | [diff] [blame] | 34 | import sys |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 35 | |
| 36 | # a mapping of hwpack name to l-m-c name |
| 37 | HWPACKS = { |
Andy Doan | abd4677 | 2012-02-15 18:38:01 -0600 | [diff] [blame] | 38 | 'omap3': 'beagle', |
Andy Doan | 108b8e6 | 2012-02-15 14:35:01 -0600 | [diff] [blame] | 39 | 'overo': 'overo', |
Andy Doan | abd4677 | 2012-02-15 18:38:01 -0600 | [diff] [blame] | 40 | 'lt-panda': 'panda', |
| 41 | 'lt-mx5':'mx53loco', |
| 42 | 'lt-mx6': 'mx6qsabrelite', |
| 43 | 'lt-origen': 'origen', |
| 44 | 'lt-snowball': 'snowball_sd', |
| 45 | 'lt-vexpress-a9': 'vexpress-a9', |
| 46 | 'efikamx': 'efikamx', |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 47 | } |
| 48 | # a mapping of binary image to its image_file size |
| 49 | BINARIES = { |
Andy Doan | 4202d88 | 2012-03-29 21:36:09 -0500 | [diff] [blame] | 50 | # daily oneiric snapshots |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 51 | 'linaro-o-nano': '512M', |
| 52 | 'linaro-o-alip': '2G', |
| 53 | 'linaro-o-ubuntu-desktop': '3G', |
Andy Doan | 4202d88 | 2012-03-29 21:36:09 -0500 | [diff] [blame] | 54 | # release images |
| 55 | 'nano': '512M', |
| 56 | 'alip': '2G', |
| 57 | 'ubuntu-desktop': '3G', |
| 58 | 'linarotv-xbmc': '3G', |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 59 | } |
| 60 | |
Andy Doan | c6500af | 2012-03-15 14:44:39 -0500 | [diff] [blame] | 61 | PREINST_SCRIPTS = { |
| 62 | 'lt-snowball': 'ste-preinstall.sh', |
| 63 | } |
| 64 | |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 65 | def today(): |
| 66 | d = datetime.date.today() |
| 67 | return "%d%02d%02d" % (d.year, d.month, d.day) |
| 68 | |
Andy Doan | 8ff38f0 | 2012-02-20 16:32:37 -0600 | [diff] [blame] | 69 | def hwpack_available(date, hwpack, platform): |
| 70 | url = 'http://snapshots.linaro.org/%s/%s-%s' % (platform, hwpack, platform) |
| 71 | hwpacks = crawler.latest_hwpacks(url) |
| 72 | for hwpack in hwpacks: |
| 73 | if hwpack[0] == date: |
| 74 | return hwpack[1] |
| 75 | |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 76 | return False |
| 77 | |
| 78 | def compress_image(imgfile): |
| 79 | print "compressing %s" % imgfile |
| 80 | args = ('bzip2', imgfile) |
| 81 | cmd_runner.run(args).wait() |
Andy Doan | 23ce4e1 | 2012-03-21 12:46:21 -0500 | [diff] [blame] | 82 | return '%s.bz2' % imgfile |
| 83 | |
| 84 | def zsync_image(imgfile): |
| 85 | print "making zsync file for %s" % imgfile |
| 86 | args = ('zsyncmake', '-o', '%s.zsync'%imgfile, imgfile) |
| 87 | cmd_runner.run(args).wait() |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 88 | |
Andy Doan | b00dbc0 | 2012-03-15 16:23:06 -0500 | [diff] [blame] | 89 | def build_image(lmc, imgfile, hwpack, hwpack_file, binary, binary_file): |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 90 | print "building image: %s" % imgfile |
| 91 | dev = HWPACKS[hwpack] |
| 92 | size = BINARIES[binary] |
| 93 | |
Andy Doan | 4fa16dc | 2012-02-09 17:47:45 -0800 | [diff] [blame] | 94 | print 'running l-m-c: %s' % lmc |
Andy Doan | c6500af | 2012-03-15 14:44:39 -0500 | [diff] [blame] | 95 | args = [lmc, |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 96 | '--dev', dev, |
| 97 | '--image_file', imgfile, |
| 98 | '--image_size', size, |
| 99 | '--hwpack-force-yes', |
| 100 | '--hwpack', hwpack_file, |
| 101 | '--binary', binary_file, |
Andy Doan | c6500af | 2012-03-15 14:44:39 -0500 | [diff] [blame] | 102 | ] |
| 103 | |
| 104 | if PREINST_SCRIPTS.has_key(hwpack): |
| 105 | sdir = os.path.abspath(os.path.dirname(__file__)) |
| 106 | script = "%s/%s" % (sdir, PREINST_SCRIPTS[hwpack]) |
| 107 | print "using presintall script: %s" % script |
| 108 | args.append('--preinstall-script') |
| 109 | args.append(script) |
| 110 | |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 111 | cmd_runner.run(args, as_root=True).wait() |
Andy Doan | 23ce4e1 | 2012-03-21 12:46:21 -0500 | [diff] [blame] | 112 | bz2file = compress_image(imgfile) |
| 113 | zsync_image(bz2file) |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 114 | |
Andy Doan | 184cd3b | 2012-03-29 22:20:02 -0500 | [diff] [blame^] | 115 | class SnapshotCrawler: |
| 116 | def __init__(self, date, platform, hwpacks, binaries): |
| 117 | self.date = date |
| 118 | self.platform = platform |
| 119 | self.hwpacks = hwpacks |
| 120 | self.binaries = binaries |
Andy Doan | e449bce | 2012-03-21 15:22:31 -0500 | [diff] [blame] | 121 | |
Andy Doan | 184cd3b | 2012-03-29 22:20:02 -0500 | [diff] [blame^] | 122 | def get_binaries(self): |
| 123 | '''return a hash table of binary->url''' |
| 124 | binaryf = {} |
| 125 | for binary in self.binaries: |
| 126 | url = 'http://snapshots.linaro.org/%s/%s' % (self.platform, binary) |
| 127 | (date, url) = crawler.latest_rfs(url) |
Andy Doan | 4202d88 | 2012-03-29 21:36:09 -0500 | [diff] [blame] | 128 | binaryf[binary] = url |
Andy Doan | 4202d88 | 2012-03-29 21:36:09 -0500 | [diff] [blame] | 129 | |
Andy Doan | 184cd3b | 2012-03-29 22:20:02 -0500 | [diff] [blame^] | 130 | return binaryf |
Andy Doan | a397737 | 2012-03-29 12:22:44 -0500 | [diff] [blame] | 131 | |
Andy Doan | 184cd3b | 2012-03-29 22:20:02 -0500 | [diff] [blame^] | 132 | def get_hwpack_url(self, hwpack): |
| 133 | hwpackname = "%s-%s" % (hwpack, self.platform) |
| 134 | return hwpack_available(self.date, hwpack, self.platform) |
Andy Doan | 4202d88 | 2012-03-29 21:36:09 -0500 | [diff] [blame] | 135 | |
Andy Doan | 184cd3b | 2012-03-29 22:20:02 -0500 | [diff] [blame^] | 136 | def get_image_name(self, odir, hwpack, hwpack_url, binary): |
| 137 | |
| 138 | #covert a url like: |
| 139 | # http://snapshots.linaro.org/oneiric/lt-origen-oneiric/20120321/1/images/hwpack/hwpack_linaro-lt-origen_20120321-1_armel_supported.tar.gz |
| 140 | # to: |
| 141 | # oneiric/lt-origen-oneiric/20120321/1/images/<file>.img |
| 142 | path = urlparse.urlparse(hwpack_url).path |
| 143 | path = os.path.dirname(path) |
| 144 | path = os.path.split(path)[0] |
| 145 | |
| 146 | path = '%s/%s' % (odir, path) |
| 147 | if not os.path.exists(path): |
| 148 | os.makedirs(path) |
| 149 | return "%s/%s-%s_%s.img" %(path,hwpack,self.platform,binary) |
| 150 | |
| 151 | class ReleaseCrawler: |
| 152 | def __init__(self, cycle, platform, hwpacks, binaries): |
| 153 | self.cycle = cycle |
| 154 | self.platform = platform |
| 155 | self.hwpacks = hwpacks |
| 156 | self.binaries = binaries |
| 157 | |
| 158 | #inialize our list of hwpacks |
| 159 | url = 'http://releases.linaro.org/%s/ubuntu/%s-hwpacks' % (cycle,platform) |
| 160 | self.hwpack_urls = crawler.list_hwpacks(url) |
| 161 | |
| 162 | def get_hwpack_url(self, hwpack): |
| 163 | pat = re.compile('hwpack_linaro-%s_' % hwpack) |
| 164 | for url in self.hwpack_urls: |
| 165 | if pat.search(url): |
| 166 | return url |
| 167 | return None |
| 168 | |
| 169 | def get_binaries(self): |
| 170 | '''return a hash table of binary->url''' |
| 171 | binaryf = {} |
| 172 | for binary in self.binaries: |
| 173 | url = 'http://releases.linaro.org/%s/ubuntu/%s-images/%s' % ( |
| 174 | self.cycle, self.platform, binary) |
| 175 | url = crawler.list_rfs(url) |
| 176 | if url is not None: |
| 177 | binaryf[binary] = url |
| 178 | return binaryf |
| 179 | |
| 180 | def get_image_name(self, odir, hwpack, hwpack_url, binary): |
| 181 | path = '%s/%s/%s/%s' % (odir, self.cycle, self.platform, binary) |
| 182 | if not os.path.exists(path): |
| 183 | os.makedirs(path) |
| 184 | return "%s/%s-%s.img" %(path,hwpack,binary) |
Andy Doan | 4202d88 | 2012-03-29 21:36:09 -0500 | [diff] [blame] | 185 | |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 186 | def main(): |
| 187 | day = today() |
| 188 | hwpacks = HWPACKS.keys() |
| 189 | binaries = BINARIES.keys() |
| 190 | |
| 191 | p = argparse.ArgumentParser(description= |
Andy Doan | a397737 | 2012-03-29 12:22:44 -0500 | [diff] [blame] | 192 | 'Builds a matrix of builds from the latest build on ' |
| 193 | 'snapshots.linaro.org or release images on releases.linaro.org') |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 194 | |
Andy Doan | 94bfe31 | 2012-02-09 17:57:29 -0800 | [diff] [blame] | 195 | p.add_argument('-o', dest='out_dir', default='./out', |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 196 | help='The out directory for downloaded and built files, default=./') |
| 197 | p.add_argument('-d', dest='date', default=day, |
| 198 | help='The date, default=%s' % day) |
| 199 | p.add_argument('-w', dest='hwpacks', action='append', |
| 200 | help='The hwpacks to generate for, default=%s' % |
| 201 | ', '.join(hwpacks)) |
| 202 | p.add_argument('-b', dest='binaries', action='append', |
| 203 | help='The binaries to generate for, default=%s' % |
| 204 | ', '.join(binaries)) |
| 205 | p.add_argument('-p', dest='platform', default='oneiric', |
| 206 | help='The platform, default=oneiric') |
Andy Doan | 4202d88 | 2012-03-29 21:36:09 -0500 | [diff] [blame] | 207 | p.add_argument('-r', dest='release', action='store_true', default=False, |
| 208 | help='If this is for release images. NOTE: the "date" arg' |
| 209 | 'will then become the cycle ie -d 12.03') |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 210 | |
| 211 | args = p.parse_args() |
Andy Doan | a397737 | 2012-03-29 12:22:44 -0500 | [diff] [blame] | 212 | |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 213 | if args.hwpacks: |
| 214 | hwpacks = args.hwpacks |
| 215 | if args.binaries: |
| 216 | binaries = args.binaries |
| 217 | |
| 218 | dm = fetch_image.DownloadManager(args.out_dir) |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 219 | |
Andy Doan | 4202d88 | 2012-03-29 21:36:09 -0500 | [diff] [blame] | 220 | if args.release: |
Andy Doan | 184cd3b | 2012-03-29 22:20:02 -0500 | [diff] [blame^] | 221 | site = ReleaseCrawler(args.date, args.platform, hwpacks, binaries) |
Andy Doan | 4202d88 | 2012-03-29 21:36:09 -0500 | [diff] [blame] | 222 | else: |
Andy Doan | 184cd3b | 2012-03-29 22:20:02 -0500 | [diff] [blame^] | 223 | site = SnapshotCrawler(args.date, args.platform, hwpacks, binaries) |
| 224 | |
| 225 | binaryf = site.get_binaries() |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 226 | |
Andy Doan | b00dbc0 | 2012-03-15 16:23:06 -0500 | [diff] [blame] | 227 | lmc = '%s/linaro-image-tools/linaro-media-create' % args.out_dir |
Andy Doan | 184cd3b | 2012-03-29 22:20:02 -0500 | [diff] [blame^] | 228 | odir = '%s/pre-built' % args.out_dir |
Andy Doan | b00dbc0 | 2012-03-15 16:23:06 -0500 | [diff] [blame] | 229 | |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 230 | for hwpack in hwpacks: |
Andy Doan | 184cd3b | 2012-03-29 22:20:02 -0500 | [diff] [blame^] | 231 | url = site.get_hwpack_url(hwpack) |
Andy Doan | b00dbc0 | 2012-03-15 16:23:06 -0500 | [diff] [blame] | 232 | |
Andy Doan | 2cfe5e6 | 2012-02-09 17:41:45 -0800 | [diff] [blame] | 233 | if url is not None and url is not False: |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 234 | hwpf = dm.download(url, None) |
| 235 | for binary in binaries: |
Andy Doan | 184cd3b | 2012-03-29 22:20:02 -0500 | [diff] [blame^] | 236 | imgfile = site.get_image_name(odir,hwpack,url,binary) |
Andy Doan | 8121190 | 2012-03-14 14:37:30 -0500 | [diff] [blame] | 237 | rfsf = dm.download(binaryf[binary], None) |
Andy Doan | b00dbc0 | 2012-03-15 16:23:06 -0500 | [diff] [blame] | 238 | build_image(lmc, imgfile, hwpack, hwpf, binary, rfsf) |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 239 | else: |
Andy Doan | 8ff38f0 | 2012-02-20 16:32:37 -0600 | [diff] [blame] | 240 | print '%s hwpack not available for %s' % (args.date,hwpack) |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 241 | |
| 242 | if __name__ == '__main__': |
| 243 | main() |
| 244 | |