Skip to content

Commit 61ffe9a

Browse files
author
libm
committed
Added aws upload support
1 parent f132f6d commit 61ffe9a

File tree

1 file changed

+54
-5
lines changed

1 file changed

+54
-5
lines changed

tools/package_binaries.py

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,18 @@
1313
################################
1414
# Parse command line args
1515
parser = argparse.ArgumentParser(description='Package nw binaries.')
16-
parser.add_argument('-p','--path',help='Where to find the binaries, like out/Release', required=False)
17-
parser.add_argument('-s','--step',help='Execute specified step. (could be "nw", "chromedriver" or "symbol")', required=False)
16+
parser.add_argument('-p','--path', help='Where to find the binaries, like out/Release', required=False)
17+
parser.add_argument('-s','--step', help='Execute specified step. (could be "nw", "chromedriver" or "symbol")', required=False)
18+
# AWS uploader args
19+
# Example: package_binaries.py -u -b linux_32bit -r 123 -n 99 -t my_bucket -i <id> -k <key>
20+
parser.add_argument('-u','--upload', help='Run aws uploader', action='store_true', required=False)
21+
parser.add_argument('-b','--buildername', help='Builder name', required=False)
22+
parser.add_argument('-r','--revision', help='Build revision',required=False)
23+
parser.add_argument('-n','--number', help='Build number', required=False)
24+
parser.add_argument('-t','--bucket', help='AWS bucket name', required=False)
25+
parser.add_argument('-i','--awsid', help='AWS_ACCESS_KEY_ID', required=False)
26+
parser.add_argument('-k','--awskey', help='AWS_SECRET_ACCESS_KEY', required=False)
27+
1828
args = parser.parse_args()
1929

2030
################################
@@ -24,6 +34,7 @@
2434
arch = None # ia32/x64
2535
step = None # nw/chromedriver/symbol
2636
nw_ver = None # x.xx
37+
dist_dir = None # .../out/Release/dist
2738

2839
step = args.step
2940
binaries_location = args.path
@@ -38,6 +49,8 @@
3849
if not os.path.isdir(binaries_location):
3950
print 'Invalid path: ' + binaries_location
4051
exit(-1)
52+
binaries_location = os.path.normpath(binaries_location)
53+
dist_dir = os.path.join(binaries_location, 'dist')
4154

4255
print 'Working on ' + binaries_location
4356

@@ -208,12 +221,10 @@ def compress(from_dir, to_dir, fname, compress):
208221

209222

210223
def make_packages(targets):
211-
dist_dir = os.path.join(binaries_location, 'dist')
212224

213225
# check file existance
214226
for t in targets:
215227
for f in t['input']:
216-
print f
217228
src = os.path.join(binaries_location, f)
218229
if not os.path.exists(src):
219230
print 'File does not exist: ', src
@@ -230,6 +241,7 @@ def make_packages(targets):
230241
# now let's do it
231242
os.mkdir(dist_dir)
232243
for t in targets:
244+
print 'Making "' + t['output'] + '.' + t['compress'] + '"'
233245
if (t.has_key('folder') and t['folder'] == True) or len(t['input']) > 1:
234246
# copy files into a folder then pack
235247
folder = os.path.join(dist_dir, t['output'])
@@ -263,7 +275,44 @@ def make_packages(targets):
263275
targets.append(generate_target_chromedriver(platform_name, arch, nw_ver))
264276
targets.append(generate_target_symbols(platform_name, arch, nw_ver))
265277

266-
make_packages(targets)
278+
if args.upload != True:
279+
print 'Creating packages...'
280+
make_packages(targets)
281+
exit(0)
282+
################################################################
283+
# aws uploader
284+
285+
from datetime import date
286+
287+
print 'Starting aws uploader...'
288+
289+
# Init variables
290+
builder_name = args.buildername
291+
got_revision = args.revision
292+
build_number = args.number
293+
bucket_name = args.bucket
294+
awsid = args.awsid
295+
awskey = args.awskey
296+
date = date.today().strftime('%m-%d-%y')
297+
298+
upload_path = ''.join(['/' + date,
299+
'/' + builder_name + '-build-' + build_number + '-' + got_revision])
300+
301+
print 'Upload path: ' + upload_path
302+
file_list = os.listdir(dist_dir)
303+
if len(file_list) == 0:
304+
print 'Cannot find packages!'
305+
exit(-1)
306+
307+
import boto
308+
conn = boto.connect_s3(awsid, awskey)
309+
bucket = conn.get_bucket(bucket_name)
310+
for f in file_list:
311+
print 'Uploading "' + f + '" ...'
312+
key = bucket.new_key(os.path.join(upload_path, f))
313+
key.set_contents_from_filename(os.path.join(dist_dir, f))
314+
315+
print 'Done.'
267316

268317

269318
# vim: et:ts=4:sw=4

0 commit comments

Comments
 (0)