summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-12-04 02:29:18 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-12-05 18:21:34 +0300
commit1b078ba62b5c9f118f54451833adb44468e52078 (patch)
tree0e31c95887e91caf6b2a7beb94bfa789912332e5
parentf94b330c82a4f29511ed2b6ae9e127276fe7421c (diff)
downloadpublishing-api-1b078ba62b5c9f118f54451833adb44468e52078.tar.gz
linaro-cp.py: Use requests for S3 uploads.
Change-Id: I9a61d388e7182773791fda0ffeb953352e8cf0f1
-rwxr-xr-xlinaro-cp.py22
1 files changed, 22 insertions, 0 deletions
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]