Fathi Boudra | cd8f58d | 2012-06-15 17:43:39 +0300 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 3 | # Copyright (C) 2012 Linaro |
| 4 | # |
| 5 | # Author: Andy Doan <andy.doan@linaro.org> |
| 6 | # |
| 7 | # This file is part of Linaro Daily Prebuilt Images. |
| 8 | # |
| 9 | # Linaro Daily Prebuilt Images is free software; you can redistribute it and/or |
| 10 | # modify it under the terms of the GNU General Public License |
| 11 | # as published by the Free Software Foundation; either version 2 |
| 12 | # of the License, or (at your option) any later version. |
| 13 | # |
| 14 | # Linaro Daily Prebuilt Images is distributed in the hope that it will be useful, |
| 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | # GNU General Public License for more details. |
| 18 | # |
| 19 | # You should have received a copy of the GNU General Public License |
| 20 | # along with Linaro Image Tools; if not, write to the Free Software |
| 21 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
| 22 | # USA. |
| 23 | |
Andy Doan | fccf484 | 2012-03-08 10:42:19 -0600 | [diff] [blame] | 24 | from linaro_fetch_image import fetch_image |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 25 | from linaro_image_tools import cmd_runner |
| 26 | |
Andy Doan | 8ff38f0 | 2012-02-20 16:32:37 -0600 | [diff] [blame] | 27 | import crawler |
| 28 | |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 29 | import argparse |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 30 | import datetime |
Ricardo Salveti de Araujo | b39eb80 | 2012-06-23 00:55:31 -0300 | [diff] [blame] | 31 | import time |
Andy Doan | 3634c47 | 2012-04-17 12:50:58 -0500 | [diff] [blame] | 32 | import hashlib |
Andy Doan | c6500af | 2012-03-15 14:44:39 -0500 | [diff] [blame] | 33 | import os |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 34 | import re |
Andy Doan | e449bce | 2012-03-21 15:22:31 -0500 | [diff] [blame] | 35 | import urlparse |
Andy Doan | 35ee9dc | 2012-05-11 01:10:12 -0500 | [diff] [blame] | 36 | import string |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 37 | |
Andy Doan | ea2e1ea | 2012-04-23 11:56:29 -0500 | [diff] [blame] | 38 | class HwPack: |
| 39 | def __init__(self, lmcname, eula=False, pre_inst_script=None): |
| 40 | self.lmcname = lmcname |
| 41 | if eula: |
| 42 | self.eula = 'EULA.txt' |
| 43 | else: |
Andy Doan | 4aabf02 | 2012-04-26 14:30:29 -0500 | [diff] [blame] | 44 | self.eula = 'OPEN-EULA.txt' |
Andy Doan | ea2e1ea | 2012-04-23 11:56:29 -0500 | [diff] [blame] | 45 | self.pre_inst_script = pre_inst_script |
| 46 | |
| 47 | def do_eula(self, imgfile): |
| 48 | fname = '%s/%s' % (os.path.dirname(imgfile), self.eula) |
| 49 | with file(fname, 'a'): |
| 50 | pass #just need the file to exist |
| 51 | |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 52 | # a mapping of hwpack name to l-m-c name |
| 53 | HWPACKS = { |
Fathi Boudra | 8b59a50 | 2013-01-18 10:20:04 +0200 | [diff] [blame] | 54 | 'arndale': HwPack('arndale'), |
Fathi Boudra | 6539389 | 2013-10-19 14:16:04 +0300 | [diff] [blame] | 55 | 'arndale-be': HwPack('arndale'), |
Andy Doan | ea2e1ea | 2012-04-23 11:56:29 -0500 | [diff] [blame] | 56 | 'beagleboard': HwPack('beagle'), |
Koen Kooi | 4fb28db | 2013-10-11 10:12:58 +0200 | [diff] [blame] | 57 | 'beaglebone': HwPack('beaglebone'), |
Fathi Boudra | 02454c9 | 2012-12-01 06:58:42 +0200 | [diff] [blame] | 58 | 'efikamx': HwPack('efikamx'), |
Fathi Boudra | b97042a | 2013-04-04 17:49:22 +0300 | [diff] [blame] | 59 | 'highbank': HwPack('highbank'), |
Fathi Boudra | 02454c9 | 2012-12-01 06:58:42 +0200 | [diff] [blame] | 60 | 'igep': HwPack('igep'), |
| 61 | 'leb-origen': HwPack('origen'), |
Fathi Boudra | c9a6c6d | 2013-05-28 09:22:52 +0300 | [diff] [blame] | 62 | 'lsk-vexpress': HwPack('vexpress'), |
Fathi Boudra | d65c75f | 2013-08-23 15:23:44 +0300 | [diff] [blame] | 63 | 'lsk-vexpress64': HwPack('vexpress'), |
Andy Doan | ea2e1ea | 2012-04-23 11:56:29 -0500 | [diff] [blame] | 64 | 'lt-mx5': HwPack('mx53loco'), |
| 65 | 'lt-mx6': HwPack('mx6qsabrelite'), |
Andy Doan | 490f620 | 2012-04-25 10:56:08 -0500 | [diff] [blame] | 66 | 'lt-origen': HwPack('origen'), |
Fathi Boudra | 02454c9 | 2012-12-01 06:58:42 +0200 | [diff] [blame] | 67 | 'lt-panda': HwPack('panda'), |
| 68 | 'lt-panda-x11-base': HwPack('panda'), |
Fathi Boudra | 1337ec6 | 2012-12-02 21:11:56 +0200 | [diff] [blame] | 69 | 'lt-snowball': HwPack('snowball_sd', True, 'ste-preinstall.sh'), |
| 70 | 'lt-snowball-x11-base': HwPack('snowball_sd', True, 'ste-preinstall.sh'), |
Ricardo Salveti de Araujo | a798c50 | 2012-06-27 19:05:10 -0300 | [diff] [blame] | 71 | 'lt-vexpress': HwPack('vexpress'), |
Fathi Boudra | d871dc8 | 2014-06-11 10:28:07 +0300 | [diff] [blame] | 72 | 'lt-vexpress64': HwPack('vexpress'), |
Fathi Boudra | 02454c9 | 2012-12-01 06:58:42 +0200 | [diff] [blame] | 73 | 'origen': HwPack('origen'), |
| 74 | 'overo': HwPack('overo'), |
| 75 | 'panda': HwPack('panda'), |
Fathi Boudra | 6539389 | 2013-10-19 14:16:04 +0300 | [diff] [blame] | 76 | 'panda-be': HwPack('panda'), |
Fathi Boudra | 1337ec6 | 2012-12-02 21:11:56 +0200 | [diff] [blame] | 77 | 'snowball': HwPack('snowball_sd', True), |
Fathi Boudra | 02454c9 | 2012-12-01 06:58:42 +0200 | [diff] [blame] | 78 | 'ti-panda-x11-base': HwPack('panda'), |
Andy Doan | edffb5d | 2012-04-25 11:22:19 -0500 | [diff] [blame] | 79 | 'vexpress': HwPack('vexpress'), |
Ricardo Salveti de Araujo | 688f24f | 2012-10-17 02:40:36 -0300 | [diff] [blame] | 80 | 'vexpress64': HwPack('vexpress'), |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 81 | } |
| 82 | # a mapping of binary image to its image_file size |
| 83 | BINARIES = { |
Andy Doan | 4202d88 | 2012-03-29 21:36:09 -0500 | [diff] [blame] | 84 | 'alip': '2G', |
Fathi Boudra | 02454c9 | 2012-12-01 06:58:42 +0200 | [diff] [blame] | 85 | 'developer': '1G', |
Marcin Juszkiewicz | b33194a | 2013-02-27 00:31:14 +0100 | [diff] [blame] | 86 | 'lamp-armv8': '2G', |
Andrew McDermott | ee96ebb | 2013-08-22 19:26:03 +0100 | [diff] [blame] | 87 | 'leg-java-armv8': '4G', |
Andy Doan | 4202d88 | 2012-03-29 21:36:09 -0500 | [diff] [blame] | 88 | 'linarotv-xbmc': '3G', |
Ricardo Salveti de Araujo | 688f24f | 2012-10-17 02:40:36 -0300 | [diff] [blame] | 89 | 'minimal-armv8': '512M', |
Fathi Boudra | 02454c9 | 2012-12-01 06:58:42 +0200 | [diff] [blame] | 90 | 'nano': '1G', |
| 91 | 'nano-lava': '1G', |
Ricardo Salveti de Araujo | d0fe5c4 | 2012-10-17 03:29:58 -0300 | [diff] [blame] | 92 | 'sdk-armv8': '2G', |
Fathi Boudra | 02454c9 | 2012-12-01 06:58:42 +0200 | [diff] [blame] | 93 | 'server': '1G', |
| 94 | 'ubuntu-desktop': '3G', |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 95 | } |
| 96 | |
Fathi Boudra | 75e299a | 2012-08-26 19:04:03 +0300 | [diff] [blame] | 97 | SNAPSHOTS_URL = "http://snapshots.linaro.org" |
| 98 | |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 99 | def today(): |
| 100 | d = datetime.date.today() |
| 101 | return "%d%02d%02d" % (d.year, d.month, d.day) |
| 102 | |
Ricardo Salveti de Araujo | b39eb80 | 2012-06-23 00:55:31 -0300 | [diff] [blame] | 103 | def download(dm, url): |
| 104 | print "INFO: Fetching", url |
| 105 | before = time.time() |
| 106 | dfile = dm.download(url, None, verbose=False) |
| 107 | delta_min, delta_secs = divmod(int(time.time() - before), 60) |
| 108 | print "INFO: Downloaded file '%s' in %d min(s) and %d sec(s)" % ( |
| 109 | dfile, delta_min, delta_secs) |
| 110 | return dfile |
| 111 | |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 112 | def compress_image(imgfile): |
Ricardo Salveti de Araujo | ba7dacf | 2012-06-23 01:08:24 -0300 | [diff] [blame] | 113 | print "INFO: compressing %s" % imgfile |
Ricardo Salveti de Araujo | d678850 | 2012-06-23 01:19:18 -0300 | [diff] [blame] | 114 | before = time.time() |
Ricardo Salveti de Araujo | 7edc48b | 2012-06-23 03:55:04 -0300 | [diff] [blame] | 115 | args = ('gzip', imgfile) |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 116 | cmd_runner.run(args).wait() |
Ricardo Salveti de Araujo | d678850 | 2012-06-23 01:19:18 -0300 | [diff] [blame] | 117 | delta_min, delta_secs = divmod(int(time.time() - before), 60) |
| 118 | print "INFO: file compressed in %d min(s) and %d sec(s)" % ( |
| 119 | delta_min, delta_secs) |
Ricardo Salveti de Araujo | 7edc48b | 2012-06-23 03:55:04 -0300 | [diff] [blame] | 120 | return '%s.gz' % imgfile |
Andy Doan | 23ce4e1 | 2012-03-21 12:46:21 -0500 | [diff] [blame] | 121 | |
Ricardo Salveti de Araujo | d3743e9 | 2012-08-15 01:50:10 -0300 | [diff] [blame] | 122 | def zsync_image(platform, imgfile): |
Ricardo Salveti de Araujo | ba7dacf | 2012-06-23 01:08:24 -0300 | [diff] [blame] | 123 | print "INFO: making zsync file for %s" % imgfile |
Ricardo Salveti de Araujo | d678850 | 2012-06-23 01:19:18 -0300 | [diff] [blame] | 124 | before = time.time() |
Fathi Boudra | 75e299a | 2012-08-26 19:04:03 +0300 | [diff] [blame] | 125 | basepath = "%s/%s/pre-built" % (SNAPSHOTS_URL, platform) |
Paul Larson | 2a8e67b | 2012-08-06 09:47:14 -0500 | [diff] [blame] | 126 | imgpath=os.sep.join(imgfile.split(os.sep)[-3:]) |
| 127 | zurl=basepath + os.sep + imgpath |
| 128 | args = ('zsyncmake', '-b 2048', '-u', zurl, '-o', '%s.zsync' % imgfile, |
| 129 | imgfile) |
Andy Doan | 23ce4e1 | 2012-03-21 12:46:21 -0500 | [diff] [blame] | 130 | cmd_runner.run(args).wait() |
Ricardo Salveti de Araujo | d678850 | 2012-06-23 01:19:18 -0300 | [diff] [blame] | 131 | delta_min, delta_secs = divmod(int(time.time() - before), 60) |
| 132 | print "INFO: zsync generated in %d min(s) and %d sec(s)" % ( |
| 133 | delta_min, delta_secs) |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 134 | |
Andy Doan | 3634c47 | 2012-04-17 12:50:58 -0500 | [diff] [blame] | 135 | def md5sum(fname): |
| 136 | md5 = hashlib.md5() |
| 137 | with open(fname, 'rb') as f: |
| 138 | while True: |
| 139 | data = f.read(4096) |
| 140 | if not data: break |
| 141 | md5.update(data) |
| 142 | return md5.hexdigest() |
| 143 | |
Fathi Boudra | ef3cd83 | 2012-12-09 10:01:25 +0200 | [diff] [blame] | 144 | def create_image_info(infofile, gzfile, binary_file, hwpack_url, \ |
| 145 | rootfs_url, platform): |
Ricardo Salveti de Araujo | b93a7ec | 2012-05-29 14:07:53 -0300 | [diff] [blame] | 146 | ''' prints out the md5sum and hwpack/rootfs info for the given image |
Andy Doan | 3634c47 | 2012-04-17 12:50:58 -0500 | [diff] [blame] | 147 | ''' |
Ricardo Salveti de Araujo | 7edc48b | 2012-06-23 03:55:04 -0300 | [diff] [blame] | 148 | print "INFO: building image info for: %s" % gzfile |
| 149 | md5 = md5sum(gzfile) |
Andy Doan | 3634c47 | 2012-04-17 12:50:58 -0500 | [diff] [blame] | 150 | |
| 151 | binary_file = os.path.basename(binary_file) |
Andy Doan | 35ee9dc | 2012-05-11 01:10:12 -0500 | [diff] [blame] | 152 | tfile = '%s/image_info_template.html' % os.path.dirname(__file__) |
Andy Doan | 3634c47 | 2012-04-17 12:50:58 -0500 | [diff] [blame] | 153 | |
Andy Doan | 35ee9dc | 2012-05-11 01:10:12 -0500 | [diff] [blame] | 154 | tmpl = None |
| 155 | with open(tfile) as f: |
| 156 | buff = f.read() |
| 157 | tmpl = string.Template(buff) |
| 158 | |
| 159 | title = 'Pre-Built Image Info' |
Ricardo Salveti de Araujo | b93a7ec | 2012-05-29 14:07:53 -0300 | [diff] [blame] | 160 | |
| 161 | # build hwpack manifest and rootfs packages links |
Fathi Boudra | ef3cd83 | 2012-12-09 10:01:25 +0200 | [diff] [blame] | 162 | hwpack_name = os.path.basename(hwpack_url) |
| 163 | hwpack_manifest_url = ("%s" % hwpack_url).replace(".tar.gz", ".manifest.txt") |
| 164 | hwpack_manifest = os.path.basename(hwpack_manifest_url) |
Ricardo Salveti de Araujo | b93a7ec | 2012-05-29 14:07:53 -0300 | [diff] [blame] | 165 | |
Fathi Boudra | ef3cd83 | 2012-12-09 10:01:25 +0200 | [diff] [blame] | 166 | rootfs_name = os.path.basename(rootfs_url) |
| 167 | rootfs_packages_url = ("%s" % rootfs_url).replace(".tar.gz", ".packages") |
| 168 | rootfs_packages = os.path.basename(rootfs_packages_url) |
| 169 | |
| 170 | if platform == "openembedded": |
| 171 | rootfs_packages_url = "n/a" |
| 172 | rootfs_packages = "n/a" |
Ricardo Salveti de Araujo | b93a7ec | 2012-05-29 14:07:53 -0300 | [diff] [blame] | 173 | |
Ricardo Salveti de Araujo | 894040a | 2012-05-29 14:07:55 -0300 | [diff] [blame] | 174 | # try to get information from Jenkins, if available |
| 175 | jenkins_buildn = os.environ.get('BUILD_NUMBER') or 'Not Found' |
| 176 | jenkins_build_url = os.environ.get('BUILD_URL') or 'http://ci.linaro.org' |
| 177 | |
Ricardo Salveti de Araujo | b93a7ec | 2012-05-29 14:07:53 -0300 | [diff] [blame] | 178 | buff = tmpl.substitute( |
Ricardo Salveti de Araujo | 7edc48b | 2012-06-23 03:55:04 -0300 | [diff] [blame] | 179 | title=title, md5=md5, image_name=os.path.basename(gzfile), |
Ricardo Salveti de Araujo | b93a7ec | 2012-05-29 14:07:53 -0300 | [diff] [blame] | 180 | hwpack_name=hwpack_name, hwpack_url=hwpack_url, |
| 181 | rootfs_name=rootfs_name, rootfs_url=rootfs_url, |
| 182 | hwpack_manifest_name=hwpack_manifest, |
| 183 | hwpack_manifest_url=hwpack_manifest_url, |
| 184 | rootfs_packages_name=rootfs_packages, |
Ricardo Salveti de Araujo | 894040a | 2012-05-29 14:07:55 -0300 | [diff] [blame] | 185 | rootfs_packages_url=rootfs_packages_url, |
| 186 | jenkins_buildn=jenkins_buildn, |
| 187 | jenkins_build_url=jenkins_build_url) |
Andy Doan | 3c0c389 | 2012-04-25 11:09:53 -0500 | [diff] [blame] | 188 | with open(infofile, 'w') as f: |
Andy Doan | 35ee9dc | 2012-05-11 01:10:12 -0500 | [diff] [blame] | 189 | f.write(buff) |
Andy Doan | 3634c47 | 2012-04-17 12:50:58 -0500 | [diff] [blame] | 190 | |
Fathi Boudra | 1062dcf | 2013-12-15 14:32:32 +0200 | [diff] [blame] | 191 | def build_image(lmc, imgfile, hwpack, hwpack_file, binary, |
Ricardo Salveti de Araujo | 688f24f | 2012-10-17 02:40:36 -0300 | [diff] [blame] | 192 | binary_file, fastmodel=False): |
Ricardo Salveti de Araujo | ba7dacf | 2012-06-23 01:08:24 -0300 | [diff] [blame] | 193 | print "INFO: building image: %s" % imgfile |
Andy Doan | ea2e1ea | 2012-04-23 11:56:29 -0500 | [diff] [blame] | 194 | hwpi = HWPACKS[hwpack] |
Marcin Juszkiewicz | c5c7512 | 2013-04-17 11:14:50 +0200 | [diff] [blame] | 195 | try: |
| 196 | size = BINARIES[binary] |
| 197 | except: |
| 198 | size = '3G' |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 199 | |
Fathi Boudra | 1062dcf | 2013-12-15 14:32:32 +0200 | [diff] [blame] | 200 | args = [lmc, |
Fathi Boudra | 885753b | 2012-12-05 20:58:32 +0200 | [diff] [blame] | 201 | '--image-size', size, |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 202 | '--hwpack-force-yes', |
| 203 | '--hwpack', hwpack_file, |
| 204 | '--binary', binary_file, |
Andy Doan | c6500af | 2012-03-15 14:44:39 -0500 | [diff] [blame] | 205 | ] |
| 206 | |
Ricardo Salveti de Araujo | 688f24f | 2012-10-17 02:40:36 -0300 | [diff] [blame] | 207 | if fastmodel: |
| 208 | args += ['--dev', 'fastmodel', |
| 209 | '--output-directory', os.path.dirname(imgfile), |
Fathi Boudra | 885753b | 2012-12-05 20:58:32 +0200 | [diff] [blame] | 210 | '--image-file', os.path.basename(imgfile)] |
Ricardo Salveti de Araujo | 688f24f | 2012-10-17 02:40:36 -0300 | [diff] [blame] | 211 | else: |
| 212 | args += ['--dev', hwpi.lmcname, |
Fathi Boudra | 885753b | 2012-12-05 20:58:32 +0200 | [diff] [blame] | 213 | '--image-file', imgfile] |
Ricardo Salveti de Araujo | 688f24f | 2012-10-17 02:40:36 -0300 | [diff] [blame] | 214 | |
Andy Doan | ea2e1ea | 2012-04-23 11:56:29 -0500 | [diff] [blame] | 215 | if hwpi.pre_inst_script is not None: |
Andy Doan | c6500af | 2012-03-15 14:44:39 -0500 | [diff] [blame] | 216 | sdir = os.path.abspath(os.path.dirname(__file__)) |
Andy Doan | ea2e1ea | 2012-04-23 11:56:29 -0500 | [diff] [blame] | 217 | script = "%s/%s" % (sdir, hwpi.pre_inst_script) |
Fathi Boudra | c775b8a | 2013-05-19 10:06:14 +0300 | [diff] [blame] | 218 | print "INFO: using preinstall script: %s" % script |
Andy Doan | c6500af | 2012-03-15 14:44:39 -0500 | [diff] [blame] | 219 | args.append('--preinstall-script') |
| 220 | args.append(script) |
| 221 | |
Fathi Boudra | c775b8a | 2013-05-19 10:06:14 +0300 | [diff] [blame] | 222 | bootloader = os.environ.get("BOOTLOADER") |
| 223 | if bootloader is None: |
| 224 | print 'INFO: Use default bootloader (u_boot)' |
| 225 | else: |
| 226 | print 'INFO: Use specified bootlooader (%s)' % bootloader |
| 227 | args.append('--bootloader') |
| 228 | args.append(bootloader) |
| 229 | |
Ricardo Salveti de Araujo | ba7dacf | 2012-06-23 01:08:24 -0300 | [diff] [blame] | 230 | print "INFO: running l-m-c:", " ".join([str(arg) for arg in args]) |
| 231 | |
Andy Doan | ea2e1ea | 2012-04-23 11:56:29 -0500 | [diff] [blame] | 232 | hwpi.do_eula(imgfile) |
Ricardo Salveti de Araujo | d678850 | 2012-06-23 01:19:18 -0300 | [diff] [blame] | 233 | |
| 234 | # some useful information so we know how much time it took per lmc run |
| 235 | before = time.time() |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 236 | cmd_runner.run(args, as_root=True).wait() |
Ricardo Salveti de Araujo | d678850 | 2012-06-23 01:19:18 -0300 | [diff] [blame] | 237 | delta_min, delta_secs = divmod(int(time.time() - before), 60) |
| 238 | print "INFO: linaro-media-create took %d min(s) and %d sec(s) to run" % ( |
| 239 | delta_min, delta_secs) |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 240 | |
Andy Doan | 184cd3b | 2012-03-29 22:20:02 -0500 | [diff] [blame] | 241 | class SnapshotCrawler: |
Marcin Juszkiewicz | db17b46 | 2013-04-09 09:51:46 +0200 | [diff] [blame] | 242 | def __init__(self, platform, hwpacks, binaries, platform_hwpack): |
Andy Doan | 184cd3b | 2012-03-29 22:20:02 -0500 | [diff] [blame] | 243 | self.platform = platform |
Marcin Juszkiewicz | db17b46 | 2013-04-09 09:51:46 +0200 | [diff] [blame] | 244 | self.platform_hwpack = platform_hwpack |
Andy Doan | 184cd3b | 2012-03-29 22:20:02 -0500 | [diff] [blame] | 245 | self.hwpacks = hwpacks |
| 246 | self.binaries = binaries |
Andy Doan | e449bce | 2012-03-21 15:22:31 -0500 | [diff] [blame] | 247 | |
Andy Doan | 184cd3b | 2012-03-29 22:20:02 -0500 | [diff] [blame] | 248 | def get_binaries(self): |
| 249 | '''return a hash table of binary->url''' |
| 250 | binaryf = {} |
| 251 | for binary in self.binaries: |
Fathi Boudra | 75e299a | 2012-08-26 19:04:03 +0300 | [diff] [blame] | 252 | url = "%s/%s/images/%s" % (SNAPSHOTS_URL, self.platform, binary) |
Andy Doan | 184cd3b | 2012-03-29 22:20:02 -0500 | [diff] [blame] | 253 | (date, url) = crawler.latest_rfs(url) |
Andy Doan | 4202d88 | 2012-03-29 21:36:09 -0500 | [diff] [blame] | 254 | binaryf[binary] = url |
Andy Doan | 4202d88 | 2012-03-29 21:36:09 -0500 | [diff] [blame] | 255 | |
Andy Doan | 184cd3b | 2012-03-29 22:20:02 -0500 | [diff] [blame] | 256 | return binaryf |
Andy Doan | a397737 | 2012-03-29 12:22:44 -0500 | [diff] [blame] | 257 | |
Ricardo Salveti de Araujo | 0352cb9 | 2012-06-22 21:48:34 -0300 | [diff] [blame] | 258 | def get_hwpacks(self): |
| 259 | '''return a hash table of hwpack->urls (date, url)''' |
| 260 | hwpackf = {} |
| 261 | for hwpack in self.hwpacks: |
Marcin Juszkiewicz | db17b46 | 2013-04-09 09:51:46 +0200 | [diff] [blame] | 262 | url = "%s/%s/hwpacks/%s" % (SNAPSHOTS_URL, self.platform_hwpack, hwpack) |
Ricardo Salveti de Araujo | 0352cb9 | 2012-06-22 21:48:34 -0300 | [diff] [blame] | 263 | hwpackf[hwpack] = crawler.latest_hwpacks(url) |
| 264 | |
| 265 | return hwpackf |
Andy Doan | 4202d88 | 2012-03-29 21:36:09 -0500 | [diff] [blame] | 266 | |
Andy Doan | 184cd3b | 2012-03-29 22:20:02 -0500 | [diff] [blame] | 267 | def get_image_name(self, odir, hwpack, hwpack_url, binary): |
| 268 | |
Fathi Boudra | 684e5e4 | 2012-11-30 04:19:33 +0100 | [diff] [blame] | 269 | #convert a url like: |
| 270 | # http://snapshots.linaro.org/SERIE/hwpacks/HWPACK_NAME/HWPACK_BUILD_NUMBER/HWPACK_FILE_NAME |
Andy Doan | 184cd3b | 2012-03-29 22:20:02 -0500 | [diff] [blame] | 271 | # to: |
Fathi Boudra | 684e5e4 | 2012-11-30 04:19:33 +0100 | [diff] [blame] | 272 | # SERIE/pre-built/HWPACK_NAME/HWPACK_BUILD_NUMBER/HWPACK_FILE_NAME.img |
Andy Doan | 184cd3b | 2012-03-29 22:20:02 -0500 | [diff] [blame] | 273 | path = urlparse.urlparse(hwpack_url).path |
Andy Doan | 66e2d5c | 2012-04-18 23:01:59 -0500 | [diff] [blame] | 274 | parts = path.split('/') |
| 275 | name = parts[-1] #use for the file name below |
| 276 | path = '/'.join(parts[-3:-1]) |
Andy Doan | 184cd3b | 2012-03-29 22:20:02 -0500 | [diff] [blame] | 277 | |
| 278 | path = '%s/%s' % (odir, path) |
| 279 | if not os.path.exists(path): |
| 280 | os.makedirs(path) |
Andy Doan | 66e2d5c | 2012-04-18 23:01:59 -0500 | [diff] [blame] | 281 | |
| 282 | date = re.search(r'_(\d+-\d+)_', name).group(1) |
Ricardo Salveti de Araujo | 99d5248 | 2012-06-22 16:05:09 -0300 | [diff] [blame] | 283 | 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] | 284 | |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 285 | def main(): |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 286 | hwpacks = HWPACKS.keys() |
| 287 | binaries = BINARIES.keys() |
| 288 | |
| 289 | p = argparse.ArgumentParser(description= |
Andy Doan | a397737 | 2012-03-29 12:22:44 -0500 | [diff] [blame] | 290 | 'Builds a matrix of builds from the latest build on ' |
| 291 | 'snapshots.linaro.org or release images on releases.linaro.org') |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 292 | |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 293 | p.add_argument('-w', dest='hwpacks', action='append', |
| 294 | help='The hwpacks to generate for, default=%s' % |
Fathi Boudra | abe1130 | 2012-12-01 19:04:53 +0200 | [diff] [blame] | 295 | ', '.join(hwpacks)) |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 296 | p.add_argument('-b', dest='binaries', action='append', |
| 297 | help='The binaries to generate for, default=%s' % |
Fathi Boudra | abe1130 | 2012-12-01 19:04:53 +0200 | [diff] [blame] | 298 | ', '.join(binaries)) |
Fathi Boudra | aa6cbf8 | 2013-12-09 20:46:04 +0200 | [diff] [blame] | 299 | p.add_argument('-p', dest='platform', default='ubuntu', |
| 300 | help='The platform, default=ubuntu') |
Marcin Juszkiewicz | db17b46 | 2013-04-09 09:51:46 +0200 | [diff] [blame] | 301 | p.add_argument('-pw', dest='platform_hwpack', default=False, |
| 302 | help='The platform for hwpack, default - same as platform') |
Fathi Boudra | f9b3904 | 2012-12-01 19:09:11 +0200 | [diff] [blame] | 303 | p.add_argument('-o', dest='out_dir', default='./out', |
| 304 | help='The out directory for downloaded and built files, default=./out') |
| 305 | p.add_argument('-d', dest='date', default="", |
| 306 | help='The date (YYYYMMDD) as reference for hwpack') |
Andy Doan | 4202d88 | 2012-03-29 21:36:09 -0500 | [diff] [blame] | 307 | p.add_argument('-r', dest='release', action='store_true', default=False, |
| 308 | help='If this is for release images. NOTE: the "date" arg' |
| 309 | 'will then become the cycle ie -d 12.03') |
Ricardo Salveti de Araujo | 688f24f | 2012-10-17 02:40:36 -0300 | [diff] [blame] | 310 | p.add_argument('-f', dest='fastmodel', action='store_true', |
| 311 | help='Build for the fastmodel target (for vexpress hwpack)') |
| 312 | |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 313 | |
| 314 | args = p.parse_args() |
Andy Doan | a397737 | 2012-03-29 12:22:44 -0500 | [diff] [blame] | 315 | |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 316 | if args.hwpacks: |
| 317 | hwpacks = args.hwpacks |
| 318 | if args.binaries: |
| 319 | binaries = args.binaries |
Marcin Juszkiewicz | db17b46 | 2013-04-09 09:51:46 +0200 | [diff] [blame] | 320 | if not args.platform_hwpack: |
Marcin Juszkiewicz | f7c892f | 2013-04-10 08:20:28 +0200 | [diff] [blame] | 321 | platform_hwpack = args.platform |
Marcin Juszkiewicz | db17b46 | 2013-04-09 09:51:46 +0200 | [diff] [blame] | 322 | else: |
| 323 | platform_hwpack = args.platform_hwpack |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 324 | |
Andy Doan | 1c6ef8b | 2012-04-23 12:28:50 -0500 | [diff] [blame] | 325 | crawler.cookie_setup() |
| 326 | |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 327 | dm = fetch_image.DownloadManager(args.out_dir) |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 328 | |
Andy Doan | 4202d88 | 2012-03-29 21:36:09 -0500 | [diff] [blame] | 329 | if args.release: |
Marcin Juszkiewicz | db17b46 | 2013-04-09 09:51:46 +0200 | [diff] [blame] | 330 | #TODO: add platform_hwpack |
Andy Doan | 184cd3b | 2012-03-29 22:20:02 -0500 | [diff] [blame] | 331 | site = ReleaseCrawler(args.date, args.platform, hwpacks, binaries) |
Andy Doan | 4202d88 | 2012-03-29 21:36:09 -0500 | [diff] [blame] | 332 | else: |
Marcin Juszkiewicz | db17b46 | 2013-04-09 09:51:46 +0200 | [diff] [blame] | 333 | site = SnapshotCrawler(args.platform, hwpacks, binaries, platform_hwpack) |
Andy Doan | 184cd3b | 2012-03-29 22:20:02 -0500 | [diff] [blame] | 334 | |
Ricardo Salveti de Araujo | 0352cb9 | 2012-06-22 21:48:34 -0300 | [diff] [blame] | 335 | hwpackf = site.get_hwpacks() |
Andy Doan | 184cd3b | 2012-03-29 22:20:02 -0500 | [diff] [blame] | 336 | binaryf = site.get_binaries() |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 337 | |
Fathi Boudra | 1062dcf | 2013-12-15 14:32:32 +0200 | [diff] [blame] | 338 | lmc = '%s/linaro-image-tools/linaro-media-create' % args.out_dir |
Andy Doan | 184cd3b | 2012-03-29 22:20:02 -0500 | [diff] [blame] | 339 | odir = '%s/pre-built' % args.out_dir |
Andy Doan | b00dbc0 | 2012-03-15 16:23:06 -0500 | [diff] [blame] | 340 | |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 341 | for hwpack in hwpacks: |
Ricardo Salveti de Araujo | 0352cb9 | 2012-06-22 21:48:34 -0300 | [diff] [blame] | 342 | url = None |
| 343 | # check if the user wanted a hwpack from a specific date |
| 344 | if args.date: |
| 345 | try: |
| 346 | dates = [elem[0] for elem in hwpackf[hwpack]] |
| 347 | index = dates.index(args.date) |
| 348 | url = hwpackf[hwpack][index][1] |
| 349 | except: |
| 350 | print "ERROR: Could not find hwpack '%s' with date '%s'" \ |
| 351 | ", skipping pre-built image for it" % (hwpack, args.date) |
| 352 | else: |
| 353 | # just grab the latest hwpack |
| 354 | try: |
| 355 | url = hwpackf[hwpack][0][1] |
| 356 | except: |
| 357 | print "ERROR: Could not find a valid hwpack url for '%s'" \ |
| 358 | ", skipping pre-built image for it" % (hwpack) |
Andy Doan | b00dbc0 | 2012-03-15 16:23:06 -0500 | [diff] [blame] | 359 | |
Andy Doan | 2cfe5e6 | 2012-02-09 17:41:45 -0800 | [diff] [blame] | 360 | if url is not None and url is not False: |
Ricardo Salveti de Araujo | b39eb80 | 2012-06-23 00:55:31 -0300 | [diff] [blame] | 361 | hwpf = download(dm, url) |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 362 | for binary in binaries: |
Ricardo Salveti de Araujo | b93a7ec | 2012-05-29 14:07:53 -0300 | [diff] [blame] | 363 | # create the image and metadata |
Ricardo Salveti de Araujo | 99d5248 | 2012-06-22 16:05:09 -0300 | [diff] [blame] | 364 | imgfile = site.get_image_name(odir, hwpack, url, binary) |
Ricardo Salveti de Araujo | b93a7ec | 2012-05-29 14:07:53 -0300 | [diff] [blame] | 365 | infofile = '%s.html' % os.path.splitext(imgfile)[0] |
Ricardo Salveti de Araujo | b39eb80 | 2012-06-23 00:55:31 -0300 | [diff] [blame] | 366 | rfsf = download(dm, binaryf[binary]) |
Fathi Boudra | 1062dcf | 2013-12-15 14:32:32 +0200 | [diff] [blame] | 367 | build_image(lmc, imgfile, hwpack, hwpf, binary, rfsf, |
Ricardo Salveti de Araujo | 688f24f | 2012-10-17 02:40:36 -0300 | [diff] [blame] | 368 | args.fastmodel) |
Ricardo Salveti de Araujo | 7edc48b | 2012-06-23 03:55:04 -0300 | [diff] [blame] | 369 | gzfile = compress_image(imgfile) |
Ricardo Salveti de Araujo | d3743e9 | 2012-08-15 01:50:10 -0300 | [diff] [blame] | 370 | zsync_image(args.platform, gzfile) |
Fathi Boudra | ef3cd83 | 2012-12-09 10:01:25 +0200 | [diff] [blame] | 371 | create_image_info(infofile, gzfile, imgfile, url, \ |
| 372 | binaryf[binary], args.platform) |
Andy Doan | 15aa23b | 2012-02-02 16:40:58 -0600 | [diff] [blame] | 373 | |
| 374 | if __name__ == '__main__': |
| 375 | main() |