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