delete.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. class DeleteSubmissionTask(SubmissionTask):
  15. """Task for submitting tasks to execute an object deletion."""
  16. def _submit(self, client, request_executor, transfer_future, **kwargs):
  17. """
  18. :param client: The client associated with the transfer manager
  19. :type config: s3transfer.manager.TransferConfig
  20. :param config: The transfer config associated with the transfer
  21. manager
  22. :type osutil: s3transfer.utils.OSUtil
  23. :param osutil: The os utility associated to the transfer manager
  24. :type request_executor: s3transfer.futures.BoundedExecutor
  25. :param request_executor: The request executor associated with the
  26. transfer manager
  27. :type transfer_future: s3transfer.futures.TransferFuture
  28. :param transfer_future: The transfer future associated with the
  29. transfer request that tasks are being submitted for
  30. """
  31. call_args = transfer_future.meta.call_args
  32. self._transfer_coordinator.submit(
  33. request_executor,
  34. DeleteObjectTask(
  35. transfer_coordinator=self._transfer_coordinator,
  36. main_kwargs={
  37. 'client': client,
  38. 'bucket': call_args.bucket,
  39. 'key': call_args.key,
  40. 'extra_args': call_args.extra_args,
  41. },
  42. is_final=True,
  43. ),
  44. )
  45. class DeleteObjectTask(Task):
  46. def _main(self, client, bucket, key, extra_args):
  47. """
  48. :param client: The S3 client to use when calling DeleteObject
  49. :type bucket: str
  50. :param bucket: The name of the bucket.
  51. :type key: str
  52. :param key: The name of the object to delete.
  53. :type extra_args: dict
  54. :param extra_args: Extra arguments to pass to the DeleteObject call.
  55. """
  56. client.delete_object(Bucket=bucket, Key=key, **extra_args)