| 1 |
# Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"). You |
| 4 |
# may not use this file except in compliance with the License. A copy of |
| 5 |
# the License is located at |
| 6 |
# |
| 7 |
# http://aws.amazon.com/apache2.0/ |
| 8 |
# |
| 9 |
# or in the "license" file accompanying this file. This file is |
| 10 |
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 11 |
# ANY KIND, either express or implied. See the License for the specific |
| 12 |
# language governing permissions and limitations under the License. |
| 13 |
from s3transfer.tasks import SubmissionTask, Task |
| 14 |
|
| 15 |
|
| 16 |
class DeleteSubmissionTask(SubmissionTask): |
| 17 |
"""Task for submitting tasks to execute an object deletion.""" |
| 18 |
|
| 19 |
def _submit(self, client, request_executor, transfer_future, **kwargs): |
| 20 |
""" |
| 21 |
:param client: The client associated with the transfer manager |
| 22 |
|
| 23 |
:type config: s3transfer.manager.TransferConfig |
| 24 |
:param config: The transfer config associated with the transfer |
| 25 |
manager |
| 26 |
|
| 27 |
:type osutil: s3transfer.utils.OSUtil |
| 28 |
:param osutil: The os utility associated to the transfer manager |
| 29 |
|
| 30 |
:type request_executor: s3transfer.futures.BoundedExecutor |
| 31 |
:param request_executor: The request executor associated with the |
| 32 |
transfer manager |
| 33 |
|
| 34 |
:type transfer_future: s3transfer.futures.TransferFuture |
| 35 |
:param transfer_future: The transfer future associated with the |
| 36 |
transfer request that tasks are being submitted for |
| 37 |
""" |
| 38 |
call_args = transfer_future.meta.call_args |
| 39 |
|
| 40 |
self._transfer_coordinator.submit( |
| 41 |
request_executor, |
| 42 |
DeleteObjectTask( |
| 43 |
transfer_coordinator=self._transfer_coordinator, |
| 44 |
main_kwargs={ |
| 45 |
'client': client, |
| 46 |
'bucket': call_args.bucket, |
| 47 |
'key': call_args.key, |
| 48 |
'extra_args': call_args.extra_args, |
| 49 |
}, |
| 50 |
is_final=True, |
| 51 |
), |
| 52 |
) |
| 53 |
|
| 54 |
|
| 55 |
class DeleteObjectTask(Task): |
| 56 |
def _main(self, client, bucket, key, extra_args): |
| 57 |
""" |
| 58 |
|
| 59 |
:param client: The S3 client to use when calling DeleteObject |
| 60 |
|
| 61 |
:type bucket: str |
| 62 |
:param bucket: The name of the bucket. |
| 63 |
|
| 64 |
:type key: str |
| 65 |
:param key: The name of the object to delete. |
| 66 |
|
| 67 |
:type extra_args: dict |
| 68 |
:param extra_args: Extra arguments to pass to the DeleteObject call. |
| 69 |
|
| 70 |
""" |
| 71 |
client.delete_object(Bucket=bucket, Key=key, **extra_args) |