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