aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMilo Casagrande <milo.casagrande@linaro.org>2015-01-16 15:08:16 +0100
committerMilo Casagrande <milo.casagrande@linaro.org>2015-01-16 15:08:16 +0100
commitbd345c76fc6c4b643aa47e2ffc57f38cd353e27a (patch)
treebc5385244ae955e0ca60333dcca7415bc967b3d3
parent50b8dae47b629df03507acbbe9366e3b0b587d22 (diff)
doc: Update examples.
Change-Id: I1af965efff474ab57f3beabcdf5d2291dd0baa8a
-rw-r--r--doc/examples.rst129
1 files changed, 129 insertions, 0 deletions
diff --git a/doc/examples.rst b/doc/examples.rst
index 7ab47f9..8d18d25 100644
--- a/doc/examples.rst
+++ b/doc/examples.rst
@@ -331,3 +331,132 @@ Triggering boot email report
if __name__ == "__main__":
main()
+
+
+Upload multiple files
+---------------------
+
+The following example, before sending the files, will load them in memory.
+With big files this might not be convenient.
+
+::
+
+ #!/usr/bin/env python
+
+ """Send multiple files as part of the build process."""
+
+ import requests
+
+ from urlparse import urljoin
+
+ BACKEND_URL = 'http://api.kernelci.org'
+ AUTHORIZATION_TOKEN = 'foo'
+
+
+ def main():
+ headers = {
+ 'Authorization': AUTHORIZATION_TOKEN
+ }
+
+ data = {
+ 'path': 'next/next-20150116/arm64-allnoconfig/'
+ }
+
+ files = [
+ ('file1', ('Image', open('/path/to/Image', 'rb'))),
+ ('file2', ('kernel.config', open('/path/to/kernel.config', 'rb'))),
+ ('file3', ('build.json', open('/path/to/build.json', 'rb'))),
+ ('file4', ('build.log', open('/path/to/build.log', 'rb'))),
+ ('file5', ('System.map', open('/path/to/System.map', 'rb'))),
+ ]
+
+ url = urljoin(BACKEND_URL, '/upload')
+ response = requests.post(url, data=data, headers=headers, files=files)
+
+ print response.content
+
+ if __name__ == "__main__":
+ main()
+
+
+Upload multiple files - 2
+-------------------------
+
+The following example does not load the files in memory, but it relies on an
+external library: `requests-toolbelt <https://pypi.python.org/pypi/requests-toolbelt/>`_.
+
+::
+
+ #!/usr/bin/env python
+
+ """Send a single file to the storage backend."""
+
+ import requests
+
+ from requests_toolbelt import MultipartEncoder
+ from urlparse import urljoin
+
+ BACKEND_URL = 'http://api.kernelci.org'
+ AUTHORIZATION_TOKEN = 'foo'
+
+
+ def main():
+ data = MultipartEncoder(
+ fields={
+ 'path': 'next/next-20150116/arm64-allnoconfig/',
+ 'file1': ('Image', open('/path/to/Image', 'rb')),
+ 'file2': ('kernel.config', open('/path/to/kernel.config', 'rb')),
+ 'file3': ('build.json', open('/path/to/build.json', 'rb')),
+ 'file4': ('build.log', open('/path/to/build.log', 'rb')),
+ 'file5': ('System.map', open('/path/to/System.map', 'rb')),
+ }
+ )
+
+ headers = {
+ 'Authorization': AUTHORIZATION_TOKEN,
+ 'Content-Type': data.content_type
+ }
+
+ url = urljoin(BACKEND_URL, '/upload')
+ response = requests.post(url, headers=headers, data=data)
+
+ print response.content
+
+ if __name__ == "__main__":
+ main()
+
+
+
+Upload a single file
+--------------------
+
+::
+
+ #!/usr/bin/env python
+
+ """Send a single file to the storage backend."""
+
+ import requests
+
+ from urlparse import urljoin
+
+ BACKEND_URL = 'http://api.kernelci.org'
+ AUTHORIZATION_TOKEN = 'foo'
+
+
+ def main():
+ headers = {
+ 'Authorization': AUTHORIZATION_TOKEN
+ }
+
+ files = {
+ 'file': (open('/path/to/boot-arch.json', 'rb'))
+ }
+
+ url = urljoin(BACKEND_URL, '/upload/next/next-20150116/arm64-allnoconfig/lab-name/boot-arch.json')
+ response = requests.put(url, headers=headers, files=files)
+
+ print response.content
+
+ if __name__ == "__main__":
+ main()