summaryrefslogtreecommitdiff
path: root/linaro-cp.py
diff options
context:
space:
mode:
Diffstat (limited to 'linaro-cp.py')
-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]