Debian Codegraph @

src/globus_sdk/services/transfer/data/delete_data.py

raw
1 from __future__ import annotations
2
3 import datetime
4 import logging
5 import typing as t
6 import uuid
7
8 from globus_sdk._internal.remarshal import stringify
9 from globus_sdk._missing import MISSING, MissingType
10 from globus_sdk._payload import GlobusPayload
11
12 log = logging.getLogger(__name__)
13
14
15 class DeleteData(GlobusPayload):
16 r"""
17 Convenience class for constructing a delete document, to use as the
18 `data` parameter to
19 :meth:`submit_delete <globus_sdk.TransferClient.submit_delete>`.
20
21 At least one item must be added using
22 :meth:`add_item <globus_sdk.DeleteData.add_item>`.
23
24 :param endpoint: The endpoint ID which is targeted by this deletion Task
25 :param label: A string label for the Task
26 :param submission_id: A submission ID value fetched via :meth:`get_submission_id
27 <globus_sdk.TransferClient.get_submission_id>`. By default, the SDK
28 will fetch and populate this field when :meth:`submit_delete
29 <globus_sdk.TransferClient.submit_delete>` is called.
30 :param recursive: Recursively delete subdirectories on the target endpoint
31 [default: ``False``]
32 :param ignore_missing: Ignore nonexistent files and directories instead of treating
33 them as errors. [default: ``False``]
34 :param interpret_globs: Enable expansion of ``\*?[]`` characters in the last
35 component of paths, unless they are escaped with a preceding backslash, ``\\``
36 [default: ``False``]
37 :param deadline: An ISO-8601 timestamp (as a string) or a datetime object which
38 defines a deadline for the deletion. At the deadline, even if the data deletion
39 is not complete, the job will be canceled. We recommend ensuring that the
40 timestamp is in UTC to avoid confusion and ambiguity. Examples of ISO-8601
41 timestamps include ``2017-10-12 09:30Z``, ``2017-10-12 12:33:54+00:00``, and
42 ``2017-10-12``
43 :param notify_on_succeeded: Send a notification email when the delete task
44 completes with a status of SUCCEEDED.
45 [default: ``True``]
46 :param notify_on_failed: Send a notification email when the delete task completes
47 with a status of FAILED.
48 [default: ``True``]
49 :param notify_on_inactive: Send a notification email when the delete task changes
50 status to INACTIVE. e.g. From credentials expiring.
51 [default: ``True``]
52 :param local_user: Optional value passed to identity mapping specifying which local
53 user account to map to. Only usable with Globus Connect Server v5 mapped
54 collections.
55 :param additional_fields: additional fields to be added to the delete
56 document. Mostly intended for internal use
57
58 **Examples**
59
60 See the :meth:`submit_delete <globus_sdk.TransferClient.submit_delete>`
61 documentation for example usage.
62
63 **External Documentation**
64
65 See the
66 `Task document definition
67 <https://docs.globus.org/api/transfer/task_submit/#document_types>`_
68 and
69 `Delete specific fields
70 <https://docs.globus.org/api/transfer/task_submit/#delete_specific_fields>`_
71 in the REST documentation for more details on Delete Task documents.
72
73 .. automethodlist:: globus_sdk.TransferData
74 """
75
76 def __init__(
77 self,
78 endpoint: uuid.UUID | str,
79 *,
80 label: str | MissingType = MISSING,
81 submission_id: uuid.UUID | str | MissingType = MISSING,
82 recursive: bool | MissingType = MISSING,
83 ignore_missing: bool | MissingType = MISSING,
84 interpret_globs: bool | MissingType = MISSING,
85 deadline: str | datetime.datetime | MissingType = MISSING,
86 notify_on_succeeded: bool | MissingType = MISSING,
87 notify_on_failed: bool | MissingType = MISSING,
88 notify_on_inactive: bool | MissingType = MISSING,
89 local_user: str | MissingType = MISSING,
90 additional_fields: dict[str, t.Any] | None = None,
91 ) -> None:
92 super().__init__()
93 self["DATA_TYPE"] = "delete"
94 self["DATA"] = []
95 self["endpoint"] = endpoint
96 self["label"] = label
97 self["submission_id"] = submission_id
98 self["deadline"] = stringify(deadline)
99 self["local_user"] = local_user
100 self["recursive"] = recursive
101 self["ignore_missing"] = ignore_missing
102 self["interpret_globs"] = interpret_globs
103 self["notify_on_succeeded"] = notify_on_succeeded
104 self["notify_on_failed"] = notify_on_failed
105 self["notify_on_inactive"] = notify_on_inactive
106
107 for k, v in self.items():
108 log.debug("DeleteData.%s = %s", k, v)
109
110 if additional_fields is not None:
111 self.update(additional_fields)
112 for option, value in additional_fields.items():
113 log.debug(
114 f"DeleteData.{option} = {value} (option passed "
115 "in via additional_fields)"
116 )
117
118 def add_item(
119 self,
120 path: str,
121 *,
122 additional_fields: dict[str, t.Any] | None = None,
123 ) -> None:
124 """
125 Add a file or directory or symlink to be deleted. If any of the paths
126 are directories, ``recursive`` must be set True on the top level
127 ``DeleteData``. Symlinks will never be followed, only deleted.
128
129 Appends a delete_item document to the DATA key of the delete
130 document.
131
132 :param path: Path to the directory or file to be deleted
133 :param additional_fields: additional fields to be added to the delete item
134 """
135 item_data = {
136 "DATA_TYPE": "delete_item",
137 "path": path,
138 **(additional_fields or {}),
139 }
140 log.debug('DeleteData[{}].add_item: "{}"'.format(self["endpoint"], path))
141 self["DATA"].append(item_data)
142
143 def iter_items(self) -> t.Iterator[dict[str, t.Any]]:
144 """
145 An iterator of items created by ``add_item``.
146
147 Each item takes the form of a dictionary.
148 """
149 yield from iter(self["DATA"])