in Scripts/DeviceFarmScripts/run_ios_ci.py [0:0]
def upload_file(client, projectArn, unique_prefix, filepath, _type):
filename = os.path.basename(filepath)
print('Upload file name: ' + unique_prefix + "_" + filename)
response = client.create_upload(projectArn=projectArn,
name=unique_prefix+"_"+filename,
type=_type
)
# Get the upload ARN, which we'll return later.
upload_arn = response['upload']['arn']
# We're going to extract the URL of the upload and use Requests to upload it
upload_url = response['upload']['url']
with open(filepath, 'rb') as file_stream:
print(f"Uploading {filepath} to Device Farm as {response['upload']['name']}... ", end='')
put_req = requests.put(upload_url, data=file_stream)
print('File upload status code: ' + str(put_req.status_code) + ' reason: ' + put_req.reason)
if not put_req.ok:
raise Exception("Couldn't upload, requests said we're not ok. Requests says: " + put_req.reason)
started = datetime.datetime.now()
device_farm_upload_status = client.get_upload(arn=upload_arn)
while device_farm_upload_status['upload']['status'] != 'SUCCEEDED':
print(f"Upload of {filename} in state {response['upload']['status']} after " + str(
datetime.datetime.now() - started))
if device_farm_upload_status['upload']['status'] == 'FAILED':
print('File upload status code: ' + str(device_farm_upload_status.status_code) + ' reason: ' + device_farm_upload_status.reason)
print('Upload failed to process')
sys.exit(-1)
time.sleep(1)
device_farm_upload_status = client.get_upload(arn=upload_arn)
return upload_arn