Updates to the release scripts

Change-Id: I4584bd5c66c22bb2ffe3d8f73923cff8807d5008
diff --git a/tools/build/onos-release b/tools/build/onos-release
index 4cb931f..1546fb2 100755
--- a/tools/build/onos-release
+++ b/tools/build/onos-release
@@ -18,6 +18,7 @@
 
 # Change the version
 onos-change-version $NEW_VERSION
+export ONOS_VERSION=$NEW_VERSION
 
 # Build ONOS & deploy to staging repo using the release profile.
 onos-build && onos-package && mvn -Prelease clean deploy -DskipTests
diff --git a/tools/build/onos-upload-bits b/tools/build/onos-upload-bits
index 3ac6bd6..ae5b9c2 100755
--- a/tools/build/onos-upload-bits
+++ b/tools/build/onos-upload-bits
@@ -2,9 +2,11 @@
 # -----------------------------------------------------------------------------
 # Uploads ONOS distributable bits.
 # -----------------------------------------------------------------------------
-
 [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
 . $ONOS_ROOT/tools/build/envDefaults
 
-# TODO: upload to EC2
+#FIXME need to export s3Creds
+#FIXME verify that ONOS_VERSION is set
 
+# upload to EC2
+upload-to-s3 -d release/ /tmp/onos-$ONOS_VERSION.*
diff --git a/tools/build/upload-to-s3 b/tools/build/upload-to-s3
new file mode 100755
index 0000000..8b02d3b
--- /dev/null
+++ b/tools/build/upload-to-s3
@@ -0,0 +1,63 @@
+#!/usr/bin/python
+
+"""
+Upload a file to S3
+"""
+
+from sys import argv, stdout
+from time import time
+from os.path import basename
+from optparse import OptionParser
+
+from boto.s3.key import Key
+from boto.s3.connection import S3Connection
+
+
+def uploadFile( bucket, filename, dest=None ):
+    "Upload a file to a bucket"
+    if not bucket:
+        bucket = 'onos'
+    if not dest: 
+        key = basename( filename )
+    else:
+        key = dest + basename( filename ) #FIXME add the /
+    print '* Uploading', filename, 'to bucket', bucket, 'as', key
+    stdout.flush()
+    start = time()
+    def callback( transmitted, size ):
+        "Progress callback for set_contents_from_filename"
+        elapsed = time() - start
+        percent = 100.0 * transmitted / size
+        kbps = .001 * transmitted / elapsed
+        print ( '\r%d bytes transmitted of %d (%.2f%%),'
+                ' %.2f KB/sec ' %
+                ( transmitted, size, percent, kbps ) ),
+        stdout.flush()
+    conn = S3Connection()
+    bucket = conn.get_bucket( bucket )
+    k = Key( bucket )
+    k.key = key
+    k.set_contents_from_filename( filename, cb=callback, num_cb=100 )
+    print
+    elapsed = time() - start
+    print "* elapsed time: %.2f seconds" % elapsed
+
+if __name__ == '__main__':
+    usage = "Usage: %prog [options] <file to upload>"
+    parser = OptionParser(usage=usage)
+    parser.add_option("-b", "--bucket", dest="bucket",
+                      help="Bucket on S3")
+    parser.add_option("-d", "--dest", dest="dest",
+                      help="Destination path in bucket")
+    parser.add_option("-k", "--key", dest="awsKey",
+                      help="Bucket on S3")
+    parser.add_option("-s", "--secret", dest="awsSecret",
+                      help="Bucket on S3")
+    (options, args) = parser.parse_args()
+    
+    if len( args ) == 0:
+        parser.error("missing filenames")
+    for file in args:
+        uploadFile( options.bucket, file, options.dest )
+
+    #FIXME key and secret are unused