Anonymous committed 1812f85

The bucket destination path can now be specified

Comments (0)

Files changed (1)

             yield StringIO(chunk)
-def upload_multipart(bucket, path, threads=0, public=False):
-    key = path
+def upload_multipart(bucket, path, dest_path, threads=0, public=False):
+    key = os.path.join(dest_path, path)
     sys.stderr.write('bucket=%s, key=%s\n' % (bucket, key))
     conn = boto.connect_s3()
     bucket = conn.lookup(bucket)
     if threads:
         if not thread_pool:
             raise RuntimeError("Twisted is required for threads - ain't that ironic?")
-        reactor.callWhenRunning(upload_multipart_parallel, bucket, path, mupload, threads)
+        reactor.callWhenRunning(upload_multipart_parallel, bucket, path, dest_path, mupload, threads)
         for (piece, fd) in enumerate(generate_chunk_files(path, True), 1):
-def upload_multipart_parallel(bucket, path, mupload, threads):
+def upload_multipart_parallel(bucket, path, dest_path, mupload, threads):
     sys.stderr.write('thread count: %d\n' %  threads)
     chunks = (os.stat(path).st_size / CHUNK_SIZE) + 1
                       help='Number of threads to use')
     parser.add_option('-p', '--public', dest='public', action='store_true',
                       help='Use this flag to set acl to public-read')
+    parser.add_option('-P', '--path', dest='dest_path',
+                      help='Destination path in the bucket')
     opts, args = parser.parse_args()
     path = args[0]
-    upload_multipart(opts.bucket, path, opts.threads, opts.public)
+    upload_multipart(opts.bucket, path, opts.dest_path or '', opts.threads, opts.public)
 if __name__ == '__main__':