forked from nwjs/nw.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaws_uploader.py
More file actions
executable file
·103 lines (85 loc) · 3.24 KB
/
Copy pathaws_uploader.py
File metadata and controls
executable file
·103 lines (85 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python
import argparse
import boto
import datetime
import json
import os
import sys
import time
# Set timeout, for retry
#if not boto.config.has_section('Boto'):
# boto.config.add_section('Boto')
#boto.config.set('Boto','http_socket_timeout','30')
################################
# Parse command line args
parser = argparse.ArgumentParser(description='AWS uploader, please fill in your aws key and id in Boto config (~/.boto)')
parser.add_argument('-p','--path', help='Optional. Where to find the binaries, normally out/Release/dist', required=False)
parser.add_argument('-b','--buildername', help='Builder name, e.g. linux_32bit', required=True)
parser.add_argument('-r','--revision', help='Commit revision',required=True)
parser.add_argument('-n','--number', help='Build number', required=True)
parser.add_argument('-t','--bucket', help='AWS bucket name', required=True)
parser.add_argument('-d','--dlpath', help='AWS bucket path', required=True)
args = parser.parse_args()
################################
# Check and init variables
dist_dir = args.path
builder_name = args.buildername
got_revision = args.revision
build_number = args.number
bucket_name = args.bucket
dlpath = args.dlpath
date = datetime.date.today().strftime('%m-%d-%Y')
# If the binaries location is not given, calculate it from script related dir.
if dist_dir == None:
dist_dir = os.path.join(os.path.dirname(__file__),
os.pardir, os.pardir, os.pardir, 'out', 'Release')
dist_dir = os.path.join(dist_dir, 'dist')
if not os.path.isabs(dist_dir):
dist_dir = os.path.join(os.getcwd(), dist_dir)
if not os.path.isdir(dist_dir):
print 'Invalid path: ' + dist_dir
exit(-1)
dist_dir = os.path.normpath(dist_dir)
# it's for S3, so always use '/' here
#upload_path = ''.join(['/' + date,
# '/' + builder_name + '-build-' + build_number + '-' + got_revision])
upload_path = '/' + dlpath;
file_list = os.listdir(dist_dir)
if len(file_list) == 0:
print 'Cannot find packages!'
exit(-1)
# move node-webkit- to the top of the list.
for i in range(len(file_list)):
fname = file_list[i]
if fname.startswith('node-webkit-v'):
del file_list[i]
file_list.insert(0,fname)
break
def print_progress(transmitted, total):
print ' %d%% transferred of total: %d bytes.' % (transmitted*100/total, total)
sys.stdout.flush()
def aws_upload(upload_path, file_list):
conn = boto.connect_s3()
print 'Connecting to S3 ...'
sys.stdout.flush()
bucket = conn.get_bucket(bucket_name)
print 'Uploading to: ' + upload_path
for f in file_list:
print 'Uploading "' + f + '" ...'
sys.stdout.flush()
# use '/' for s3
path_prefix = ''
if builder_name.startswith("win64") and (f == 'nw.lib' or f == 'nw.exp') :
path_prefix = 'x64'
key = bucket.new_key(upload_path + '/' + path_prefix + '/' + f)
key.set_contents_from_filename(filename=os.path.join(dist_dir, f), cb=print_progress, num_cb=50, replace=True)
for retry in range(3):
try:
aws_upload(upload_path, file_list)
break
except Exception, e:
print e
sys.stdout.flush()
time.sleep(30) #wait for 30s and try again.
print 'Done.'
# vim: et:ts=4:sw=4