You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.5 KiB

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