aboutsummaryrefslogtreecommitdiff
path: root/build-scripts
diff options
context:
space:
mode:
authorAxel Fagerstedt <axel.fagerstedt@linaro.org>2013-05-30 16:10:31 +0200
committerAxel Fagerstedt <axel.fagerstedt@linaro.org>2013-05-30 16:10:31 +0200
commitaacdf9948450f5945c2ada8b5bf5fd674cdb59a5 (patch)
tree81b946c2618a656d935e34c5eb0c7453d68f0e77 /build-scripts
parent3921ac49a4548b7eb14deecd1c2dfc48ad930ef8 (diff)
Fetch prebuilt images using the snapshots API.
Diffstat (limited to 'build-scripts')
-rw-r--r--build-scripts/build-android-testsuite-restricted15
-rwxr-xr-xbuild-scripts/fetch_prebuilt.py83
2 files changed, 95 insertions, 3 deletions
diff --git a/build-scripts/build-android-testsuite-restricted b/build-scripts/build-android-testsuite-restricted
index 9bc4a8f..beacfe7 100644
--- a/build-scripts/build-android-testsuite-restricted
+++ b/build-scripts/build-android-testsuite-restricted
@@ -54,9 +54,18 @@ trap infrastructure_error ERR
# Combine output with prebuilt android images
if test -n "$ANDROID_PREBUILT_URL"; then
#get prebuilt android
- wget -nv --no-check-certificate $ANDROID_PREBUILT_URL/boot.tar.bz2
- wget -nv --no-check-certificate $ANDROID_PREBUILT_URL/system.tar.bz2
- wget -nv --no-check-certificate $ANDROID_PREBUILT_URL/userdata.tar.bz2
+ ${BUILD_SCRIPT_ROOT}/fetch_prebuilt.py $ANDROID_PREBUILT_URL
+
+ if [ ! -e boot.tar.bz2 ]; then
+ echo "ERROR: boot.tar.bz2 not downloaded"
+ exit 1
+ elif [ ! -e system.tar.bz2 ]; then
+ echo "ERROR: system.tar.bz2 not downloaded"
+ exit 1
+ elif [ ! -e userdata.tar.bz2 ]; then
+ echo "ERROR: userdata.tar.bz2 not downloaded"
+ exit 1
+ fi
# move thw boot tarball
mv boot.tar.bz2 out/.
diff --git a/build-scripts/fetch_prebuilt.py b/build-scripts/fetch_prebuilt.py
new file mode 100755
index 0000000..1c89806
--- /dev/null
+++ b/build-scripts/fetch_prebuilt.py
@@ -0,0 +1,83 @@
+#!/usr/bin/python
+
+import json
+import urlparse
+import shutil
+import urllib2
+import os
+import sys
+
+
+def download(api_urls, files_to_get):
+ """Example of how to use the API to download a/all files in a directory."""
+
+ # Get listing for file(s) pointed to by URL we were given
+ request = urllib2.urlopen(api_urls.ls())
+ listing = json.loads(request.read())["files"]
+
+ for file_info in listing:
+
+ if file_info["type"] == "folder":
+ # Skip folders...
+ continue
+ elif not file_info["name"] in files_to_get:
+ # only grab the specified files
+ continue
+
+ # Get the licenses. They are returned as a JSON document in the form:
+ # {"licenses":
+ # [{"text": "<license text>", "digest": "<digest of license>"},
+ # {"text": "<license text>", "digest": "<digest of license>"},
+ # ...
+ # ]}
+ # Each license has a digest associated with it.
+ request = urllib2.urlopen(api_urls.license(file_info["url"]))
+ licenses = json.loads(request.read())["licenses"]
+
+ if licenses[0] == "Open":
+ headers = {}
+ else:
+ # Dont download any licensed files
+ continue
+
+ # Once the header has been generated, just download the file.
+ req = urllib2.urlopen(urllib2.Request(api_urls.file(file_info["url"]),
+ headers=headers))
+ with open(os.path.basename(file_info["url"]), 'wb') as fp:
+ shutil.copyfileobj(req, fp)
+
+
+class ApiUrls():
+ """Since we want to manipulate URLS, but urlsplit returns an immutable
+ object this is a convenience object to perform the manipulations for us"""
+ def __init__(self, input_url):
+ self.parsed_url = [c for c in urlparse.urlsplit(input_url)]
+ self.path = self.parsed_url[2]
+
+ def ls(self, path=None):
+ if not path:
+ path = self.path
+ self.parsed_url[2] = "/api/ls" + path
+ return urlparse.urlunsplit(self.parsed_url)
+
+ def license(self, path):
+ self.parsed_url[2] = "/api/license" + path
+ return urlparse.urlunsplit(self.parsed_url)
+
+ def file(self, path):
+ self.parsed_url[2] = path
+ return urlparse.urlunsplit(self.parsed_url)
+
+
+if __name__ == '__main__':
+ if len(sys.argv) != 2:
+ # Check that a URL has been supplied.
+ print >> sys.stderr, "Usage: fetch_prebuilt.py <URL>"
+ exit(1)
+
+ api_urls = ApiUrls(sys.argv[1])
+
+ # we are only interested in the fs images
+ files_to_get = "boot.tar.bz2", "system.tar.bz2", "userdata.tar.bz2"
+
+ download(api_urls, files_to_get)