pltr-cli 0.3.0__py3-none-any.whl → 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pltr/cli.py +10 -0
- pltr/commands/dataset.py +309 -0
- pltr/commands/folder.py +338 -0
- pltr/commands/mediasets.py +422 -0
- pltr/commands/orchestration.py +642 -0
- pltr/services/dataset.py +368 -10
- pltr/services/folder.py +167 -0
- pltr/services/mediasets.py +293 -0
- pltr/services/orchestration.py +457 -0
- pltr/utils/formatting.py +638 -0
- {pltr_cli-0.3.0.dist-info → pltr_cli-0.5.0.dist-info}/METADATA +139 -5
- {pltr_cli-0.3.0.dist-info → pltr_cli-0.5.0.dist-info}/RECORD +15 -11
- pltr/services/dataset_full.py +0 -302
- pltr/services/dataset_v2.py +0 -128
- {pltr_cli-0.3.0.dist-info → pltr_cli-0.5.0.dist-info}/WHEEL +0 -0
- {pltr_cli-0.3.0.dist-info → pltr_cli-0.5.0.dist-info}/entry_points.txt +0 -0
- {pltr_cli-0.3.0.dist-info → pltr_cli-0.5.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
"""
|
|
2
|
+
MediaSets service wrapper for Foundry SDK v2 API.
|
|
3
|
+
Provides operations for managing media sets and media content.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from typing import Any, Optional, Dict
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from .base import BaseService
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class MediaSetsService(BaseService):
|
|
13
|
+
"""Service wrapper for Foundry MediaSets operations using v2 API."""
|
|
14
|
+
|
|
15
|
+
def _get_service(self) -> Any:
|
|
16
|
+
"""Get the Foundry MediaSets service."""
|
|
17
|
+
return self.client.media_sets
|
|
18
|
+
|
|
19
|
+
def get_media_set_info(
|
|
20
|
+
self, media_set_rid: str, media_item_rid: str, preview: bool = False
|
|
21
|
+
) -> Dict[str, Any]:
|
|
22
|
+
"""
|
|
23
|
+
Get information about a specific media item in a media set.
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
media_set_rid: Media Set Resource Identifier
|
|
27
|
+
media_item_rid: Media Item Resource Identifier
|
|
28
|
+
preview: Enable preview mode
|
|
29
|
+
|
|
30
|
+
Returns:
|
|
31
|
+
Media item information dictionary
|
|
32
|
+
"""
|
|
33
|
+
try:
|
|
34
|
+
response = self.service.MediaSet.info(
|
|
35
|
+
media_set_rid=media_set_rid,
|
|
36
|
+
media_item_rid=media_item_rid,
|
|
37
|
+
preview=preview,
|
|
38
|
+
)
|
|
39
|
+
return self._format_media_item_info(response)
|
|
40
|
+
except Exception as e:
|
|
41
|
+
raise RuntimeError(f"Failed to get media item info: {e}")
|
|
42
|
+
|
|
43
|
+
def get_media_item_by_path(
|
|
44
|
+
self,
|
|
45
|
+
media_set_rid: str,
|
|
46
|
+
media_item_path: str,
|
|
47
|
+
branch_name: Optional[str] = None,
|
|
48
|
+
preview: bool = False,
|
|
49
|
+
) -> Dict[str, Any]:
|
|
50
|
+
"""
|
|
51
|
+
Get media item RID by its path within the media set.
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
media_set_rid: Media Set Resource Identifier
|
|
55
|
+
media_item_path: Path to the media item within the media set
|
|
56
|
+
branch_name: Branch name (optional)
|
|
57
|
+
preview: Enable preview mode
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
Response containing media item RID
|
|
61
|
+
"""
|
|
62
|
+
try:
|
|
63
|
+
response = self.service.MediaSet.get_rid_by_path(
|
|
64
|
+
media_set_rid=media_set_rid,
|
|
65
|
+
media_item_path=media_item_path,
|
|
66
|
+
branch_name=branch_name,
|
|
67
|
+
preview=preview,
|
|
68
|
+
)
|
|
69
|
+
return {"rid": response.rid, "path": media_item_path}
|
|
70
|
+
except Exception as e:
|
|
71
|
+
raise RuntimeError(f"Failed to get media item by path: {e}")
|
|
72
|
+
|
|
73
|
+
def create_transaction(
|
|
74
|
+
self,
|
|
75
|
+
media_set_rid: str,
|
|
76
|
+
branch_name: Optional[str] = None,
|
|
77
|
+
preview: bool = False,
|
|
78
|
+
) -> str:
|
|
79
|
+
"""
|
|
80
|
+
Create a new transaction for uploading to a media set.
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
media_set_rid: Media Set Resource Identifier
|
|
84
|
+
branch_name: Branch name (optional)
|
|
85
|
+
preview: Enable preview mode
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
Transaction ID
|
|
89
|
+
"""
|
|
90
|
+
try:
|
|
91
|
+
response = self.service.MediaSet.create(
|
|
92
|
+
media_set_rid=media_set_rid,
|
|
93
|
+
branch_name=branch_name,
|
|
94
|
+
preview=preview,
|
|
95
|
+
)
|
|
96
|
+
return response.transaction_id
|
|
97
|
+
except Exception as e:
|
|
98
|
+
raise RuntimeError(f"Failed to create transaction: {e}")
|
|
99
|
+
|
|
100
|
+
def commit_transaction(
|
|
101
|
+
self,
|
|
102
|
+
media_set_rid: str,
|
|
103
|
+
transaction_id: str,
|
|
104
|
+
preview: bool = False,
|
|
105
|
+
) -> None:
|
|
106
|
+
"""
|
|
107
|
+
Commit an open transaction, making uploaded items available.
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
media_set_rid: Media Set Resource Identifier
|
|
111
|
+
transaction_id: Transaction ID to commit
|
|
112
|
+
preview: Enable preview mode
|
|
113
|
+
"""
|
|
114
|
+
try:
|
|
115
|
+
self.service.MediaSet.commit(
|
|
116
|
+
media_set_rid=media_set_rid,
|
|
117
|
+
transaction_id=transaction_id,
|
|
118
|
+
preview=preview,
|
|
119
|
+
)
|
|
120
|
+
except Exception as e:
|
|
121
|
+
raise RuntimeError(f"Failed to commit transaction: {e}")
|
|
122
|
+
|
|
123
|
+
def abort_transaction(
|
|
124
|
+
self,
|
|
125
|
+
media_set_rid: str,
|
|
126
|
+
transaction_id: str,
|
|
127
|
+
preview: bool = False,
|
|
128
|
+
) -> None:
|
|
129
|
+
"""
|
|
130
|
+
Abort an open transaction, deleting any uploaded items.
|
|
131
|
+
|
|
132
|
+
Args:
|
|
133
|
+
media_set_rid: Media Set Resource Identifier
|
|
134
|
+
transaction_id: Transaction ID to abort
|
|
135
|
+
preview: Enable preview mode
|
|
136
|
+
"""
|
|
137
|
+
try:
|
|
138
|
+
self.service.MediaSet.abort(
|
|
139
|
+
media_set_rid=media_set_rid,
|
|
140
|
+
transaction_id=transaction_id,
|
|
141
|
+
preview=preview,
|
|
142
|
+
)
|
|
143
|
+
except Exception as e:
|
|
144
|
+
raise RuntimeError(f"Failed to abort transaction: {e}")
|
|
145
|
+
|
|
146
|
+
def upload_media(
|
|
147
|
+
self,
|
|
148
|
+
media_set_rid: str,
|
|
149
|
+
file_path: str,
|
|
150
|
+
media_item_path: str,
|
|
151
|
+
transaction_id: str,
|
|
152
|
+
preview: bool = False,
|
|
153
|
+
) -> Dict[str, Any]:
|
|
154
|
+
"""
|
|
155
|
+
Upload a media file to a media set within a transaction.
|
|
156
|
+
|
|
157
|
+
Args:
|
|
158
|
+
media_set_rid: Media Set Resource Identifier
|
|
159
|
+
file_path: Local path to the file to upload
|
|
160
|
+
media_item_path: Path within the media set where file should be stored
|
|
161
|
+
transaction_id: Transaction ID for the upload
|
|
162
|
+
preview: Enable preview mode
|
|
163
|
+
|
|
164
|
+
Returns:
|
|
165
|
+
Upload response information
|
|
166
|
+
"""
|
|
167
|
+
try:
|
|
168
|
+
file_path_obj = Path(file_path)
|
|
169
|
+
if not file_path_obj.exists():
|
|
170
|
+
raise FileNotFoundError(f"File not found: {file_path}")
|
|
171
|
+
|
|
172
|
+
with open(file_path_obj, "rb") as file:
|
|
173
|
+
self.service.MediaSet.upload(
|
|
174
|
+
media_set_rid=media_set_rid,
|
|
175
|
+
media_item_path=media_item_path,
|
|
176
|
+
body=file,
|
|
177
|
+
transaction_id=transaction_id,
|
|
178
|
+
preview=preview,
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
return {
|
|
182
|
+
"media_set_rid": media_set_rid,
|
|
183
|
+
"media_item_path": media_item_path,
|
|
184
|
+
"transaction_id": transaction_id,
|
|
185
|
+
"file_size": file_path_obj.stat().st_size,
|
|
186
|
+
"uploaded": True,
|
|
187
|
+
}
|
|
188
|
+
except Exception as e:
|
|
189
|
+
raise RuntimeError(f"Failed to upload media: {e}")
|
|
190
|
+
|
|
191
|
+
def download_media(
|
|
192
|
+
self,
|
|
193
|
+
media_set_rid: str,
|
|
194
|
+
media_item_rid: str,
|
|
195
|
+
output_path: str,
|
|
196
|
+
original: bool = False,
|
|
197
|
+
preview: bool = False,
|
|
198
|
+
) -> Dict[str, Any]:
|
|
199
|
+
"""
|
|
200
|
+
Download a media item from a media set.
|
|
201
|
+
|
|
202
|
+
Args:
|
|
203
|
+
media_set_rid: Media Set Resource Identifier
|
|
204
|
+
media_item_rid: Media Item Resource Identifier
|
|
205
|
+
output_path: Local path where file should be saved
|
|
206
|
+
original: Whether to download original version (vs processed)
|
|
207
|
+
preview: Enable preview mode
|
|
208
|
+
|
|
209
|
+
Returns:
|
|
210
|
+
Download response information
|
|
211
|
+
"""
|
|
212
|
+
try:
|
|
213
|
+
output_path_obj = Path(output_path)
|
|
214
|
+
output_path_obj.parent.mkdir(parents=True, exist_ok=True)
|
|
215
|
+
|
|
216
|
+
if original:
|
|
217
|
+
response = self.service.MediaSet.read_original(
|
|
218
|
+
media_set_rid=media_set_rid,
|
|
219
|
+
media_item_rid=media_item_rid,
|
|
220
|
+
preview=preview,
|
|
221
|
+
)
|
|
222
|
+
else:
|
|
223
|
+
response = self.service.MediaSet.read(
|
|
224
|
+
media_set_rid=media_set_rid,
|
|
225
|
+
media_item_rid=media_item_rid,
|
|
226
|
+
preview=preview,
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
with open(output_path_obj, "wb") as file:
|
|
230
|
+
if hasattr(response, "content"):
|
|
231
|
+
file.write(response.content)
|
|
232
|
+
else:
|
|
233
|
+
# Handle streaming response
|
|
234
|
+
for chunk in response:
|
|
235
|
+
file.write(chunk)
|
|
236
|
+
|
|
237
|
+
file_size = output_path_obj.stat().st_size
|
|
238
|
+
return {
|
|
239
|
+
"media_set_rid": media_set_rid,
|
|
240
|
+
"media_item_rid": media_item_rid,
|
|
241
|
+
"output_path": str(output_path_obj),
|
|
242
|
+
"file_size": file_size,
|
|
243
|
+
"downloaded": True,
|
|
244
|
+
"original": original,
|
|
245
|
+
}
|
|
246
|
+
except Exception as e:
|
|
247
|
+
raise RuntimeError(f"Failed to download media: {e}")
|
|
248
|
+
|
|
249
|
+
def get_media_reference(
|
|
250
|
+
self,
|
|
251
|
+
media_set_rid: str,
|
|
252
|
+
media_item_rid: str,
|
|
253
|
+
preview: bool = False,
|
|
254
|
+
) -> Dict[str, Any]:
|
|
255
|
+
"""
|
|
256
|
+
Get a reference to a media item (e.g., for embedding).
|
|
257
|
+
|
|
258
|
+
Args:
|
|
259
|
+
media_set_rid: Media Set Resource Identifier
|
|
260
|
+
media_item_rid: Media Item Resource Identifier
|
|
261
|
+
preview: Enable preview mode
|
|
262
|
+
|
|
263
|
+
Returns:
|
|
264
|
+
Media reference information
|
|
265
|
+
"""
|
|
266
|
+
try:
|
|
267
|
+
response = self.service.MediaSet.reference(
|
|
268
|
+
media_set_rid=media_set_rid,
|
|
269
|
+
media_item_rid=media_item_rid,
|
|
270
|
+
preview=preview,
|
|
271
|
+
)
|
|
272
|
+
return self._format_media_reference(response)
|
|
273
|
+
except Exception as e:
|
|
274
|
+
raise RuntimeError(f"Failed to get media reference: {e}")
|
|
275
|
+
|
|
276
|
+
def _format_media_item_info(self, info_response: Any) -> Dict[str, Any]:
|
|
277
|
+
"""Format media item info response for display."""
|
|
278
|
+
return {
|
|
279
|
+
"media_item_rid": getattr(info_response, "rid", "unknown"),
|
|
280
|
+
"filename": getattr(info_response, "filename", "unknown"),
|
|
281
|
+
"size": getattr(info_response, "size", 0),
|
|
282
|
+
"content_type": getattr(info_response, "content_type", "unknown"),
|
|
283
|
+
"created_time": getattr(info_response, "created_time", None),
|
|
284
|
+
"updated_time": getattr(info_response, "updated_time", None),
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
def _format_media_reference(self, reference_response: Any) -> Dict[str, Any]:
|
|
288
|
+
"""Format media reference response for display."""
|
|
289
|
+
return {
|
|
290
|
+
"reference_id": getattr(reference_response, "reference_id", "unknown"),
|
|
291
|
+
"url": getattr(reference_response, "url", "unknown"),
|
|
292
|
+
"expires_at": getattr(reference_response, "expires_at", None),
|
|
293
|
+
}
|