covert to Release/Snapshot classes
This allows us to get rid of the dumb
if args.release
logic sprinkled around
diff --git a/build-images.py b/build-images.py
index 7f57b43..7c2633c 100755
--- a/build-images.py
+++ b/build-images.py
@@ -112,56 +112,76 @@
bz2file = compress_image(imgfile)
zsync_image(bz2file)
-def get_image_dir(outdir, url):
- '''covert a url like:
- http://snapshots.linaro.org/oneiric/lt-origen-oneiric/20120321/1/images/hwpack/hwpack_linaro-lt-origen_20120321-1_armel_supported.tar.gz
- to:
- oneiric/lt-origen-oneiric/20120321/1/images
- '''
- path = urlparse.urlparse(url).path
- path = os.path.dirname(path)
- path = os.path.split(path)[0]
+class SnapshotCrawler:
+ def __init__(self, date, platform, hwpacks, binaries):
+ self.date = date
+ self.platform = platform
+ self.hwpacks = hwpacks
+ self.binaries = binaries
- path = '%s/%s' % (outdir, path)
- if not os.path.exists(path):
- os.makedirs(path)
- return path
-
-def get_snapshot_binaries(binaries, platform):
- binaryf = {}
- for binary in binaries:
- url = 'http://snapshots.linaro.org/%s/%s' % (platform, binary)
- (date, url) = crawler.latest_rfs(url)
- binaryf[binary] = url
-
- return binaryf
-
-def get_release_binaries(cycle, binaries, platform):
- binaryf = {}
- for binary in binaries:
- url = 'http://releases.linaro.org/%s/ubuntu/%s-images/%s' % (cycle,
- platform, binary)
- url = crawler.list_rfs(url)
- if url is not None:
+ def get_binaries(self):
+ '''return a hash table of binary->url'''
+ binaryf = {}
+ for binary in self.binaries:
+ url = 'http://snapshots.linaro.org/%s/%s' % (self.platform, binary)
+ (date, url) = crawler.latest_rfs(url)
binaryf[binary] = url
- return binaryf
-def get_snapshot_hwpack(date, hwpack, platform):
- ''' returns the url to the hwpack on snapshots.l.o if it exists'''
- hwpackname = "%s-%s" % (hwpack, platform)
- return hwpack_available(date, hwpack, platform)
+ return binaryf
-def get_release_hwpacks(cycle, platform):
- ''' returns an array of hwpacks on releases.l.o'''
- url = 'http://releases.linaro.org/%s/ubuntu/%s-hwpacks' % (cycle,platform)
- return crawler.list_hwpacks(url)
+ def get_hwpack_url(self, hwpack):
+ hwpackname = "%s-%s" % (hwpack, self.platform)
+ return hwpack_available(self.date, hwpack, self.platform)
-def get_release_hwpack(hwpack_urls, hwpack):
- pat = re.compile('hwpack_linaro-%s_' % hwpack)
- for url in hwpack_urls:
- if pat.search(url):
- return url
- return None
+ def get_image_name(self, odir, hwpack, hwpack_url, binary):
+
+ #covert a url like:
+ # http://snapshots.linaro.org/oneiric/lt-origen-oneiric/20120321/1/images/hwpack/hwpack_linaro-lt-origen_20120321-1_armel_supported.tar.gz
+ # to:
+ # oneiric/lt-origen-oneiric/20120321/1/images/<file>.img
+ path = urlparse.urlparse(hwpack_url).path
+ path = os.path.dirname(path)
+ path = os.path.split(path)[0]
+
+ path = '%s/%s' % (odir, path)
+ if not os.path.exists(path):
+ os.makedirs(path)
+ return "%s/%s-%s_%s.img" %(path,hwpack,self.platform,binary)
+
+class ReleaseCrawler:
+ def __init__(self, cycle, platform, hwpacks, binaries):
+ self.cycle = cycle
+ self.platform = platform
+ self.hwpacks = hwpacks
+ self.binaries = binaries
+
+ #inialize our list of hwpacks
+ url = 'http://releases.linaro.org/%s/ubuntu/%s-hwpacks' % (cycle,platform)
+ self.hwpack_urls = crawler.list_hwpacks(url)
+
+ def get_hwpack_url(self, hwpack):
+ pat = re.compile('hwpack_linaro-%s_' % hwpack)
+ for url in self.hwpack_urls:
+ if pat.search(url):
+ return url
+ return None
+
+ def get_binaries(self):
+ '''return a hash table of binary->url'''
+ binaryf = {}
+ for binary in self.binaries:
+ url = 'http://releases.linaro.org/%s/ubuntu/%s-images/%s' % (
+ self.cycle, self.platform, binary)
+ url = crawler.list_rfs(url)
+ if url is not None:
+ binaryf[binary] = url
+ return binaryf
+
+ def get_image_name(self, odir, hwpack, hwpack_url, binary):
+ path = '%s/%s/%s/%s' % (odir, self.cycle, self.platform, binary)
+ if not os.path.exists(path):
+ os.makedirs(path)
+ return "%s/%s-%s.img" %(path,hwpack,binary)
def main():
day = today()
@@ -198,29 +218,22 @@
dm = fetch_image.DownloadManager(args.out_dir)
if args.release:
- hwpack_urls = get_release_hwpacks(args.date, args.platform)
- binaryf = get_release_binaries(args.date, binaries, args.platform)
+ site = ReleaseCrawler(args.date, args.platform, hwpacks, binaries)
else:
- binaryf = get_snapshot_binaries(binaries, args.platform)
+ site = SnapshotCrawler(args.date, args.platform, hwpacks, binaries)
+
+ binaryf = site.get_binaries()
lmc = '%s/linaro-image-tools/linaro-media-create' % args.out_dir
- odir_root = '%s/pre-built' % args.out_dir
+ odir = '%s/pre-built' % args.out_dir
for hwpack in hwpacks:
- if args.release:
- url = get_release_hwpack(hwpack_urls, hwpack)
- else:
- url = get_snapshot_hwpack(args.date, hwpack, args.platform)
+ url = site.get_hwpack_url(hwpack)
if url is not None and url is not False:
- if args.release:
- odir = '/'.join((odir_root, args.date, args.platform))
- else:
- odir = get_image_dir(odir_root, url)
-
hwpf = dm.download(url, None)
for binary in binaries:
- imgfile = "%s/%s-%s_%s.img" %(odir,hwpack,args.platform,binary)
+ imgfile = site.get_image_name(odir,hwpack,url,binary)
rfsf = dm.download(binaryf[binary], None)
build_image(lmc, imgfile, hwpack, hwpf, binary, rfsf)
else: