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.
@@ -0,0 +1,422 @@
1
+ """
2
+ MediaSets commands for managing media sets and media content.
3
+ """
4
+
5
+ import typer
6
+ from typing import Optional
7
+ from pathlib import Path
8
+ from rich.console import Console
9
+
10
+ from ..services.mediasets import MediaSetsService
11
+ from ..utils.formatting import OutputFormatter
12
+ from ..utils.progress import SpinnerProgressTracker
13
+ from ..auth.base import ProfileNotFoundError, MissingCredentialsError
14
+ from ..utils.completion import (
15
+ complete_rid,
16
+ complete_profile,
17
+ complete_output_format,
18
+ cache_rid,
19
+ )
20
+
21
+ app = typer.Typer()
22
+ console = Console()
23
+ formatter = OutputFormatter(console)
24
+
25
+
26
+ @app.command("get")
27
+ def get_media_item(
28
+ media_set_rid: str = typer.Argument(
29
+ ..., help="Media Set Resource Identifier", autocompletion=complete_rid
30
+ ),
31
+ media_item_rid: str = typer.Argument(
32
+ ..., help="Media Item Resource Identifier", autocompletion=complete_rid
33
+ ),
34
+ profile: Optional[str] = typer.Option(
35
+ None, "--profile", "-p", help="Profile name", autocompletion=complete_profile
36
+ ),
37
+ format: str = typer.Option(
38
+ "table",
39
+ "--format",
40
+ "-f",
41
+ help="Output format (table, json, csv)",
42
+ autocompletion=complete_output_format,
43
+ ),
44
+ output: Optional[str] = typer.Option(
45
+ None, "--output", "-o", help="Output file path"
46
+ ),
47
+ preview: bool = typer.Option(False, "--preview", help="Enable preview mode"),
48
+ ):
49
+ """Get detailed information about a specific media item."""
50
+ try:
51
+ cache_rid(media_set_rid)
52
+ cache_rid(media_item_rid)
53
+ service = MediaSetsService(profile=profile)
54
+
55
+ with SpinnerProgressTracker().track_spinner(
56
+ f"Fetching media item {media_item_rid}..."
57
+ ):
58
+ media_info = service.get_media_set_info(
59
+ media_set_rid, media_item_rid, preview=preview
60
+ )
61
+
62
+ formatter.format_media_item_info(media_info, format, output)
63
+
64
+ if output:
65
+ formatter.print_success(f"Media item information saved to {output}")
66
+
67
+ except (ProfileNotFoundError, MissingCredentialsError) as e:
68
+ formatter.print_error(f"Authentication error: {e}")
69
+ raise typer.Exit(1)
70
+ except Exception as e:
71
+ formatter.print_error(f"Failed to get media item: {e}")
72
+ raise typer.Exit(1)
73
+
74
+
75
+ @app.command("get-by-path")
76
+ def get_media_by_path(
77
+ media_set_rid: str = typer.Argument(
78
+ ..., help="Media Set Resource Identifier", autocompletion=complete_rid
79
+ ),
80
+ media_item_path: str = typer.Argument(
81
+ ..., help="Path to media item within the media set"
82
+ ),
83
+ profile: Optional[str] = typer.Option(
84
+ None, "--profile", "-p", help="Profile name", autocompletion=complete_profile
85
+ ),
86
+ branch: Optional[str] = typer.Option(None, "--branch", help="Branch name"),
87
+ format: str = typer.Option(
88
+ "table",
89
+ "--format",
90
+ "-f",
91
+ help="Output format (table, json, csv)",
92
+ autocompletion=complete_output_format,
93
+ ),
94
+ output: Optional[str] = typer.Option(
95
+ None, "--output", "-o", help="Output file path"
96
+ ),
97
+ preview: bool = typer.Option(False, "--preview", help="Enable preview mode"),
98
+ ):
99
+ """Get media item RID by its path within the media set."""
100
+ try:
101
+ cache_rid(media_set_rid)
102
+ service = MediaSetsService(profile=profile)
103
+
104
+ with SpinnerProgressTracker().track_spinner(
105
+ f"Looking up media item at path {media_item_path}..."
106
+ ):
107
+ result = service.get_media_item_by_path(
108
+ media_set_rid, media_item_path, branch_name=branch, preview=preview
109
+ )
110
+
111
+ formatter.format_media_path_lookup(result, format, output)
112
+
113
+ if output:
114
+ formatter.print_success(f"Media item lookup saved to {output}")
115
+
116
+ except (ProfileNotFoundError, MissingCredentialsError) as e:
117
+ formatter.print_error(f"Authentication error: {e}")
118
+ raise typer.Exit(1)
119
+ except Exception as e:
120
+ formatter.print_error(f"Failed to lookup media item by path: {e}")
121
+ raise typer.Exit(1)
122
+
123
+
124
+ @app.command("create")
125
+ def create_transaction(
126
+ media_set_rid: str = typer.Argument(
127
+ ..., help="Media Set Resource Identifier", autocompletion=complete_rid
128
+ ),
129
+ profile: Optional[str] = typer.Option(
130
+ None, "--profile", "-p", help="Profile name", autocompletion=complete_profile
131
+ ),
132
+ branch: Optional[str] = typer.Option(None, "--branch", help="Branch name"),
133
+ preview: bool = typer.Option(False, "--preview", help="Enable preview mode"),
134
+ ):
135
+ """Create a new transaction for uploading to a media set."""
136
+ try:
137
+ cache_rid(media_set_rid)
138
+ service = MediaSetsService(profile=profile)
139
+
140
+ with SpinnerProgressTracker().track_spinner("Creating transaction..."):
141
+ transaction_id = service.create_transaction(
142
+ media_set_rid, branch_name=branch, preview=preview
143
+ )
144
+
145
+ formatter.print_success("Successfully created transaction")
146
+ formatter.print_info(f"Transaction ID: {transaction_id}")
147
+ formatter.print_info(
148
+ "Use this transaction ID for uploads, then commit or abort as needed"
149
+ )
150
+
151
+ except (ProfileNotFoundError, MissingCredentialsError) as e:
152
+ formatter.print_error(f"Authentication error: {e}")
153
+ raise typer.Exit(1)
154
+ except Exception as e:
155
+ formatter.print_error(f"Failed to create transaction: {e}")
156
+ raise typer.Exit(1)
157
+
158
+
159
+ @app.command("commit")
160
+ def commit_transaction(
161
+ media_set_rid: str = typer.Argument(
162
+ ..., help="Media Set Resource Identifier", autocompletion=complete_rid
163
+ ),
164
+ transaction_id: str = typer.Argument(..., help="Transaction ID to commit"),
165
+ profile: Optional[str] = typer.Option(
166
+ None, "--profile", "-p", help="Profile name", autocompletion=complete_profile
167
+ ),
168
+ preview: bool = typer.Option(False, "--preview", help="Enable preview mode"),
169
+ confirm: bool = typer.Option(False, "--yes", "-y", help="Skip confirmation prompt"),
170
+ ):
171
+ """Commit a transaction, making uploaded items available."""
172
+ try:
173
+ if not confirm:
174
+ typer.confirm(
175
+ f"Are you sure you want to commit transaction {transaction_id}?",
176
+ abort=True,
177
+ )
178
+
179
+ service = MediaSetsService(profile=profile)
180
+
181
+ with SpinnerProgressTracker().track_spinner(
182
+ f"Committing transaction {transaction_id}..."
183
+ ):
184
+ service.commit_transaction(media_set_rid, transaction_id, preview=preview)
185
+
186
+ formatter.print_success(f"Successfully committed transaction {transaction_id}")
187
+ formatter.print_info("Uploaded items are now available in the media set")
188
+
189
+ except (ProfileNotFoundError, MissingCredentialsError) as e:
190
+ formatter.print_error(f"Authentication error: {e}")
191
+ raise typer.Exit(1)
192
+ except Exception as e:
193
+ formatter.print_error(f"Failed to commit transaction: {e}")
194
+ raise typer.Exit(1)
195
+
196
+
197
+ @app.command("abort")
198
+ def abort_transaction(
199
+ media_set_rid: str = typer.Argument(
200
+ ..., help="Media Set Resource Identifier", autocompletion=complete_rid
201
+ ),
202
+ transaction_id: str = typer.Argument(..., help="Transaction ID to abort"),
203
+ profile: Optional[str] = typer.Option(
204
+ None, "--profile", "-p", help="Profile name", autocompletion=complete_profile
205
+ ),
206
+ preview: bool = typer.Option(False, "--preview", help="Enable preview mode"),
207
+ confirm: bool = typer.Option(False, "--yes", "-y", help="Skip confirmation prompt"),
208
+ ):
209
+ """Abort a transaction, deleting any uploaded items."""
210
+ try:
211
+ if not confirm:
212
+ typer.confirm(
213
+ f"Are you sure you want to abort transaction {transaction_id}? This will delete uploaded items.",
214
+ abort=True,
215
+ )
216
+
217
+ service = MediaSetsService(profile=profile)
218
+
219
+ with SpinnerProgressTracker().track_spinner(
220
+ f"Aborting transaction {transaction_id}..."
221
+ ):
222
+ service.abort_transaction(media_set_rid, transaction_id, preview=preview)
223
+
224
+ formatter.print_success(f"Successfully aborted transaction {transaction_id}")
225
+ formatter.print_warning(
226
+ "Any uploaded items in this transaction have been deleted"
227
+ )
228
+
229
+ except (ProfileNotFoundError, MissingCredentialsError) as e:
230
+ formatter.print_error(f"Authentication error: {e}")
231
+ raise typer.Exit(1)
232
+ except Exception as e:
233
+ formatter.print_error(f"Failed to abort transaction: {e}")
234
+ raise typer.Exit(1)
235
+
236
+
237
+ @app.command("upload")
238
+ def upload_media(
239
+ media_set_rid: str = typer.Argument(
240
+ ..., help="Media Set Resource Identifier", autocompletion=complete_rid
241
+ ),
242
+ file_path: str = typer.Argument(..., help="Local path to the file to upload"),
243
+ media_item_path: str = typer.Argument(
244
+ ..., help="Path within media set where file should be stored"
245
+ ),
246
+ transaction_id: str = typer.Argument(..., help="Transaction ID for the upload"),
247
+ profile: Optional[str] = typer.Option(
248
+ None, "--profile", "-p", help="Profile name", autocompletion=complete_profile
249
+ ),
250
+ preview: bool = typer.Option(False, "--preview", help="Enable preview mode"),
251
+ ):
252
+ """Upload a media file to a media set within a transaction."""
253
+ try:
254
+ # Validate file exists
255
+ file_path_obj = Path(file_path)
256
+ if not file_path_obj.exists():
257
+ formatter.print_error(f"File not found: {file_path}")
258
+ raise typer.Exit(1)
259
+
260
+ cache_rid(media_set_rid)
261
+ service = MediaSetsService(profile=profile)
262
+
263
+ file_size = file_path_obj.stat().st_size
264
+ formatter.print_info(
265
+ f"Uploading {file_path} ({file_size} bytes) to {media_item_path}"
266
+ )
267
+
268
+ with SpinnerProgressTracker().track_spinner(
269
+ f"Uploading {file_path_obj.name}..."
270
+ ):
271
+ service.upload_media(
272
+ media_set_rid,
273
+ file_path,
274
+ media_item_path,
275
+ transaction_id,
276
+ preview=preview,
277
+ )
278
+
279
+ formatter.print_success(f"Successfully uploaded {file_path_obj.name}")
280
+ formatter.print_info(f"Media item path: {media_item_path}")
281
+ formatter.print_info(f"Transaction ID: {transaction_id}")
282
+ formatter.print_warning(
283
+ "Remember to commit the transaction to make the upload available"
284
+ )
285
+
286
+ except (ProfileNotFoundError, MissingCredentialsError) as e:
287
+ formatter.print_error(f"Authentication error: {e}")
288
+ raise typer.Exit(1)
289
+ except FileNotFoundError as e:
290
+ formatter.print_error(str(e))
291
+ raise typer.Exit(1)
292
+ except Exception as e:
293
+ formatter.print_error(f"Failed to upload media: {e}")
294
+ raise typer.Exit(1)
295
+
296
+
297
+ @app.command("download")
298
+ def download_media(
299
+ media_set_rid: str = typer.Argument(
300
+ ..., help="Media Set Resource Identifier", autocompletion=complete_rid
301
+ ),
302
+ media_item_rid: str = typer.Argument(
303
+ ..., help="Media Item Resource Identifier", autocompletion=complete_rid
304
+ ),
305
+ output_path: str = typer.Argument(
306
+ ..., help="Local path where file should be saved"
307
+ ),
308
+ profile: Optional[str] = typer.Option(
309
+ None, "--profile", "-p", help="Profile name", autocompletion=complete_profile
310
+ ),
311
+ original: bool = typer.Option(
312
+ False, "--original", help="Download original version instead of processed"
313
+ ),
314
+ preview: bool = typer.Option(False, "--preview", help="Enable preview mode"),
315
+ overwrite: bool = typer.Option(
316
+ False, "--overwrite", help="Overwrite existing file"
317
+ ),
318
+ ):
319
+ """Download a media item from a media set."""
320
+ try:
321
+ # Check if output file already exists
322
+ output_path_obj = Path(output_path)
323
+ if output_path_obj.exists() and not overwrite:
324
+ formatter.print_error(f"File already exists: {output_path}")
325
+ formatter.print_info("Use --overwrite to replace existing file")
326
+ raise typer.Exit(1)
327
+
328
+ cache_rid(media_set_rid)
329
+ cache_rid(media_item_rid)
330
+ service = MediaSetsService(profile=profile)
331
+
332
+ version_type = "original" if original else "processed"
333
+ with SpinnerProgressTracker().track_spinner(
334
+ f"Downloading {version_type} media item..."
335
+ ):
336
+ result = service.download_media(
337
+ media_set_rid,
338
+ media_item_rid,
339
+ output_path,
340
+ original=original,
341
+ preview=preview,
342
+ )
343
+
344
+ formatter.print_success("Successfully downloaded media item")
345
+ formatter.print_info(f"Saved to: {result['output_path']}")
346
+ formatter.print_info(f"File size: {result['file_size']} bytes")
347
+ formatter.print_info(
348
+ f"Version: {'original' if result['original'] else 'processed'}"
349
+ )
350
+
351
+ except (ProfileNotFoundError, MissingCredentialsError) as e:
352
+ formatter.print_error(f"Authentication error: {e}")
353
+ raise typer.Exit(1)
354
+ except Exception as e:
355
+ formatter.print_error(f"Failed to download media: {e}")
356
+ raise typer.Exit(1)
357
+
358
+
359
+ @app.command("reference")
360
+ def get_media_reference(
361
+ media_set_rid: str = typer.Argument(
362
+ ..., help="Media Set Resource Identifier", autocompletion=complete_rid
363
+ ),
364
+ media_item_rid: str = typer.Argument(
365
+ ..., help="Media Item Resource Identifier", autocompletion=complete_rid
366
+ ),
367
+ profile: Optional[str] = typer.Option(
368
+ None, "--profile", "-p", help="Profile name", autocompletion=complete_profile
369
+ ),
370
+ format: str = typer.Option(
371
+ "table",
372
+ "--format",
373
+ "-f",
374
+ help="Output format (table, json, csv)",
375
+ autocompletion=complete_output_format,
376
+ ),
377
+ output: Optional[str] = typer.Option(
378
+ None, "--output", "-o", help="Output file path"
379
+ ),
380
+ preview: bool = typer.Option(False, "--preview", help="Enable preview mode"),
381
+ ):
382
+ """Get a reference to a media item (e.g., for embedding)."""
383
+ try:
384
+ cache_rid(media_set_rid)
385
+ cache_rid(media_item_rid)
386
+ service = MediaSetsService(profile=profile)
387
+
388
+ with SpinnerProgressTracker().track_spinner(
389
+ f"Getting reference for media item {media_item_rid}..."
390
+ ):
391
+ reference = service.get_media_reference(
392
+ media_set_rid, media_item_rid, preview=preview
393
+ )
394
+
395
+ formatter.format_media_reference(reference, format, output)
396
+
397
+ if output:
398
+ formatter.print_success(f"Media reference saved to {output}")
399
+
400
+ except (ProfileNotFoundError, MissingCredentialsError) as e:
401
+ formatter.print_error(f"Authentication error: {e}")
402
+ raise typer.Exit(1)
403
+ except Exception as e:
404
+ formatter.print_error(f"Failed to get media reference: {e}")
405
+ raise typer.Exit(1)
406
+
407
+
408
+ @app.callback()
409
+ def main():
410
+ """
411
+ MediaSets operations for managing media sets and media content.
412
+
413
+ This module provides commands to:
414
+ - Get media item information and references
415
+ - Create, commit, and abort upload transactions
416
+ - Upload media files to media sets
417
+ - Download media items from media sets
418
+
419
+ All operations require Resource Identifiers (RIDs) like:
420
+ ri.mediasets.main.media-set.12345678-1234-1234-1234-123456789abc
421
+ """
422
+ pass