示例#1
0
 def _enqueue_upload_start_task(self, chunksize, num_uploads, filename):
     upload_context = tasks.MultipartUploadContext(
         expected_parts=num_uploads)
     create_multipart_upload_task = tasks.CreateMultipartUploadTask(
         session=self.session, filename=filename,
         parameters=self.params,
         result_queue=self.result_queue, upload_context=upload_context)
     self.executor.submit(create_multipart_upload_task)
     return upload_context
示例#2
0
    def _enqueue_multipart_upload_tasks(self,
                                        filename,
                                        remove_local_file=False):
        # First we need to create a CreateMultipartUpload task,
        # then create UploadTask objects for each of the parts.
        # And finally enqueue a CompleteMultipartUploadTask.
        chunksize = find_chunksize(filename.size, self.chunksize)
        num_uploads = int(math.ceil(filename.size / float(chunksize)))
        upload_context = tasks.MultipartUploadContext(
            expected_parts=num_uploads)
        create_multipart_upload_task = tasks.CreateMultipartUploadTask(
            session=self.session,
            filename=filename,
            parameters=self.params,
            result_queue=self.result_queue,
            upload_context=upload_context)
        self.executer.submit(create_multipart_upload_task)

        for i in range(1, (num_uploads + 1)):
            task = tasks.UploadPartTask(part_number=i,
                                        chunk_size=chunksize,
                                        result_queue=self.result_queue,
                                        upload_context=upload_context,
                                        filename=filename)
            self.executer.submit(task)

        complete_multipart_upload_task = tasks.CompleteMultipartUploadTask(
            session=self.session,
            filename=filename,
            parameters=self.params,
            result_queue=self.result_queue,
            upload_context=upload_context)
        self.executer.submit(complete_multipart_upload_task)
        self._multipart_uploads.append((upload_context, filename))
        if remove_local_file:
            remove_task = tasks.RemoveFileTask(local_filename=filename.src,
                                               upload_context=upload_context)
            self.executer.submit(remove_task)
        return num_uploads