From 1b078ba62b5c9f118f54451833adb44468e52078 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 4 Dec 2016 02:29:18 +0300 Subject: linaro-cp.py: Use requests for S3 uploads. Change-Id: I9a61d388e7182773791fda0ffeb953352e8cf0f1 --- linaro-cp.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/linaro-cp.py b/linaro-cp.py index 066cfe5..49dba6f 100755 --- a/linaro-cp.py +++ b/linaro-cp.py @@ -12,6 +12,9 @@ import time import re import pprint +import requests + + # Public artifacts BUILD-INFO.txt build_info = 'Format-Version: 0.5\n\nFiles-Pattern: *\nLicense-Type: open\n' @@ -159,6 +162,25 @@ class API_v3(API_v1): url, data, headers, retry_count) def _put_s3(self, url, filename, mtype, retry_count=3): + size = os.path.getsize(filename) + headers = {'Content-Type': mtype, 'Content-Length': size} + while retry_count: + try: + with open(filename, 'rb') as f: + resp = requests.put(url, headers=headers, data=f) + if resp.status_code in (200, 201): + return + else: + print("Unsuccessful status:", resp.status_code) + except Exception as e: + print(e) + print('Upload failed for %s, retrying in 2 seconds' % url) + time.sleep(2) + retry_count -= 1 + + return "S3 upload failed" + + response = cStringIO.StringIO() size = os.path.getsize(filename) headers = ['Content-Type: ' + mtype] -- cgit v1.2.3