codekingpro/portable-devtools
114k
1# Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License"). You4# may not use this file except in compliance with the License. A copy of5# the License is located at6#7# http://aws.amazon.com/apache2.0/8#9# or in the "license" file accompanying this file. This file is10# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF11# ANY KIND, either express or implied. See the License for the specific12# language governing permissions and limitations under the License.13from s3transfer.tasks import SubmissionTask, Task14 15 16class 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 manager22 23 :type config: s3transfer.manager.TransferConfig24 :param config: The transfer config associated with the transfer25 manager26 27 :type osutil: s3transfer.utils.OSUtil28 :param osutil: The os utility associated to the transfer manager29 30 :type request_executor: s3transfer.futures.BoundedExecutor31 :param request_executor: The request executor associated with the32 transfer manager33 34 :type transfer_future: s3transfer.futures.TransferFuture35 :param transfer_future: The transfer future associated with the36 transfer request that tasks are being submitted for37 """38 call_args = transfer_future.meta.call_args39 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 55class DeleteObjectTask(Task):56 def _main(self, client, bucket, key, extra_args):57 """58 59 :param client: The S3 client to use when calling DeleteObject60 61 :type bucket: str62 :param bucket: The name of the bucket.63 64 :type key: str65 :param key: The name of the object to delete.66 67 :type extra_args: dict68 :param extra_args: Extra arguments to pass to the DeleteObject call.69 70 """71 client.delete_object(Bucket=bucket, Key=key, **extra_args)72 