Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Renamed confusing "id" to "seq" in Multipart.py

  • Loading branch information...
commit b78cd50a2cdd431c0c738b54725e51fe3e43695d 1 parent d057748
@mludvig mludvig authored
Showing with 15 additions and 16 deletions.
  1. +15 −15 S3/MultiPart.py
  2. +0 −1  S3/S3.py
View
30 S3/MultiPart.py
@@ -18,8 +18,8 @@ def __init__(self, s3, file, uri):
self.s3 = s3
self.file = file
self.uri = uri
- self.upload_id = None
self.parts = {}
+ self.upload_id = self.initiate_multipart_upload()
def initiate_multipart_upload(self):
"""
@@ -35,7 +35,7 @@ def initiate_multipart_upload(self):
def upload_all_parts(self):
"""
Execute a full multipart upload on a file
- Returns the id/etag dict
+ Returns the seq/etag dict
TODO use num_processes to thread it
"""
if not self.upload_id:
@@ -46,38 +46,38 @@ def upload_all_parts(self):
nr_parts = file_size / self.chunk_size + (file_size % self.chunk_size and 1)
debug("MultiPart: Uploading %s in %d parts" % (self.file.name, nr_parts))
- id = 1
+ seq = 1
while size_left > 0:
- offset = self.chunk_size * (id - 1)
+ offset = self.chunk_size * (seq - 1)
current_chunk_size = min(file_size - offset, self.chunk_size)
size_left -= current_chunk_size
labels = {
'source' : unicodise(self.file.name),
'destination' : unicodise(self.uri.uri()),
- 'extra' : "[part %d of %d, %s]" % (id, nr_parts, "%d%sB" % formatSize(current_chunk_size, human_readable = True))
+ 'extra' : "[part %d of %d, %s]" % (seq, nr_parts, "%d%sB" % formatSize(current_chunk_size, human_readable = True))
}
try:
- self.upload_part(id, offset, current_chunk_size, labels)
+ self.upload_part(seq, offset, current_chunk_size, labels)
except S3UploadError, e:
- error(u"Upload of '%s' part %d failed too many times. Aborting multipart upload." % (self.file.name, id))
+ error(u"Upload of '%s' part %d failed too many times. Aborting multipart upload." % (self.file.name, seq))
self.abort_upload()
raise e
- id += 1
+ seq += 1
- debug("MultiPart: Upload finished: %d parts", id - 1)
+ debug("MultiPart: Upload finished: %d parts", seq - 1)
- def upload_part(self, id, offset, chunk_size, labels):
+ def upload_part(self, seq, offset, chunk_size, labels):
"""
Upload a file chunk
http://docs.amazonwebservices.com/AmazonS3/latest/API/index.html?mpUploadUploadPart.html
"""
# TODO implement Content-MD5
- debug("Uploading part %i of %r (%s bytes)" % (id, self.upload_id, chunk_size))
+ debug("Uploading part %i of %r (%s bytes)" % (seq, self.upload_id, chunk_size))
headers = { "content-length": chunk_size }
- query_string = "?partNumber=%i&uploadId=%s" % (id, self.upload_id)
+ query_string = "?partNumber=%i&uploadId=%s" % (seq, self.upload_id)
request = self.s3.create_request("OBJECT_PUT", uri = self.uri, headers = headers, extra = query_string)
response = self.s3.send_file(request, self.file, labels, offset = offset, chunk_size = chunk_size)
- self.parts[id] = response["headers"]["etag"]
+ self.parts[seq] = response["headers"]["etag"]
return response
def complete_multipart_upload(self):
@@ -89,8 +89,8 @@ def complete_multipart_upload(self):
parts_xml = []
part_xml = "<Part><PartNumber>%i</PartNumber><ETag>%s</ETag></Part>"
- for id, etag in self.parts.items():
- parts_xml.append(part_xml % (id, etag))
+ for seq, etag in self.parts.items():
+ parts_xml.append(part_xml % (seq, etag))
body = "<CompleteMultipartUpload>%s</CompleteMultipartUpload>" % ("".join(parts_xml))
headers = { "content-length": len(body) }
View
1  S3/S3.py
@@ -743,7 +743,6 @@ def send_file(self, request, file, labels, throttle = 0, retries = _max_retries,
def send_file_multipart(self, file, headers, uri, size):
upload = MultiPartUpload(self, file, uri)
- upload_id = upload.initiate_multipart_upload()
chunk_size = self.config.multipart_chunk_size_mb * 1024 * 1024
Please sign in to comment.
Something went wrong with that request. Please try again.