mantatech-sdk 0.5b0.dev65__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.
- manta/__init__.light.py +22 -0
- manta/__init__.py +83 -0
- manta/__main__.py +21 -0
- manta/apis/__init__.py +7 -0
- manta/apis/async_user_api.py +6458 -0
- manta/apis/graph.py +498 -0
- manta/apis/module.py +316 -0
- manta/apis/results.py +251 -0
- manta/apis/swarm.py +206 -0
- manta/apis/user_api.py +1016 -0
- manta/cli/__init__.py +1 -0
- manta/cli/commands/__init__.py +1 -0
- manta/cli/commands/base_handler.py +229 -0
- manta/cli/commands/doc.py +192 -0
- manta/cli/commands/install.py +346 -0
- manta/cli/commands/sdk.py +9 -0
- manta/cli/commands/sdk_cluster.py +211 -0
- manta/cli/commands/sdk_config.py +347 -0
- manta/cli/commands/sdk_globals.py +280 -0
- manta/cli/commands/sdk_logs.py +174 -0
- manta/cli/commands/sdk_main.py +167 -0
- manta/cli/commands/sdk_module.py +516 -0
- manta/cli/commands/sdk_nodes.py +168 -0
- manta/cli/commands/sdk_original.py +3873 -0
- manta/cli/commands/sdk_results.py +265 -0
- manta/cli/commands/sdk_swarm.py +454 -0
- manta/cli/commands/sdk_user.py +234 -0
- manta/cli/commands/status.py +292 -0
- manta/cli/component_detector.py +112 -0
- manta/cli/config_manager.py +445 -0
- manta/cli/main.py +265 -0
- manta/cli/utils/__init__.py +27 -0
- manta/cli/utils/converters.py +140 -0
- manta/clients/cluster_management_client.py +486 -0
- manta/clients/local_client.py +149 -0
- manta/clients/module_management_client.py +217 -0
- manta/clients/swarm_management_client.py +562 -0
- manta/clients/user_management_client.py +395 -0
- manta/clients/world_client.py +195 -0
- manta/light/__init__.py +31 -0
- manta/light/globals.py +245 -0
- manta/light/local.py +407 -0
- manta/light/logging_config.py +39 -0
- manta/light/path.py +116 -0
- manta/light/results.py +236 -0
- manta/light/task.py +100 -0
- manta/light/utils.py +217 -0
- manta/light/world.py +177 -0
- mantatech_sdk-0.5b0.dev65.dist-info/METADATA +1039 -0
- mantatech_sdk-0.5b0.dev65.dist-info/RECORD +54 -0
- mantatech_sdk-0.5b0.dev65.dist-info/WHEEL +5 -0
- mantatech_sdk-0.5b0.dev65.dist-info/entry_points.txt +2 -0
- mantatech_sdk-0.5b0.dev65.dist-info/licenses/LICENSE +683 -0
- mantatech_sdk-0.5b0.dev65.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
"""SDK results retrieval and management commands."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import signal
|
|
5
|
+
import time
|
|
6
|
+
|
|
7
|
+
from rich.table import Table
|
|
8
|
+
|
|
9
|
+
from .base_handler import BaseSDKHandler
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class SDKResultsHandler(BaseSDKHandler):
|
|
13
|
+
"""Handle results-related SDK commands."""
|
|
14
|
+
|
|
15
|
+
def add_subparsers(self, parent_parser):
|
|
16
|
+
"""Add results command subparsers."""
|
|
17
|
+
self.parser = parent_parser # Store parser reference
|
|
18
|
+
subparsers = parent_parser.add_subparsers(
|
|
19
|
+
dest="results_command", help="Results commands"
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
# Get results command
|
|
23
|
+
get_parser = subparsers.add_parser("get", help="Get results for a swarm")
|
|
24
|
+
get_parser.add_argument("swarm_id", help="Swarm ID to get results for")
|
|
25
|
+
get_parser.add_argument(
|
|
26
|
+
"--tag", default="latest", help="Result tag (default: latest)"
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
# Export results command
|
|
30
|
+
export_parser = subparsers.add_parser("export", help="Export results to file")
|
|
31
|
+
export_parser.add_argument("swarm_id", help="Swarm ID to export results for")
|
|
32
|
+
export_parser.add_argument(
|
|
33
|
+
"--tag", default="latest", help="Result tag (default: latest)"
|
|
34
|
+
)
|
|
35
|
+
export_parser.add_argument("--output", required=True, help="Output file path")
|
|
36
|
+
|
|
37
|
+
# Stream results command
|
|
38
|
+
stream_parser = subparsers.add_parser(
|
|
39
|
+
"stream", help="Stream results in real-time"
|
|
40
|
+
)
|
|
41
|
+
stream_parser.add_argument("swarm_id", help="Swarm ID to stream results for")
|
|
42
|
+
stream_parser.add_argument(
|
|
43
|
+
"--tag", default="latest", help="Result tag (default: latest)"
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
# List tags command
|
|
47
|
+
list_tags_parser = subparsers.add_parser(
|
|
48
|
+
"list-tags", help="List available result tags for a swarm"
|
|
49
|
+
)
|
|
50
|
+
list_tags_parser.add_argument("swarm_id", help="Swarm ID to list tags for")
|
|
51
|
+
|
|
52
|
+
# Add profile override to all subcommands
|
|
53
|
+
for parser in [get_parser, export_parser, stream_parser, list_tags_parser]:
|
|
54
|
+
parser.add_argument("--profile", help="Use specific profile")
|
|
55
|
+
|
|
56
|
+
def handle(self, args) -> int:
|
|
57
|
+
"""Handle results commands."""
|
|
58
|
+
if not args.results_command:
|
|
59
|
+
if hasattr(self, "parser"):
|
|
60
|
+
self.parser.print_help()
|
|
61
|
+
return 0 # Return 0 for help display
|
|
62
|
+
|
|
63
|
+
if args.results_command == "get":
|
|
64
|
+
return self.get_results(args.swarm_id, getattr(args, "tag", "latest"))
|
|
65
|
+
elif args.results_command == "export":
|
|
66
|
+
return self.export_results(
|
|
67
|
+
args.swarm_id, getattr(args, "tag", "latest"), args.output
|
|
68
|
+
)
|
|
69
|
+
elif args.results_command == "stream":
|
|
70
|
+
return self.stream_results(args.swarm_id, getattr(args, "tag", "latest"))
|
|
71
|
+
elif args.results_command == "list-tags":
|
|
72
|
+
return self.list_tags(args.swarm_id)
|
|
73
|
+
else:
|
|
74
|
+
self.print_error(f"Unknown results command: {args.results_command}")
|
|
75
|
+
return 1
|
|
76
|
+
|
|
77
|
+
def get_results(self, swarm_id: str, tag: str = "latest") -> int:
|
|
78
|
+
"""Get results for a swarm."""
|
|
79
|
+
api = self._get_user_api()
|
|
80
|
+
if not api:
|
|
81
|
+
return 1
|
|
82
|
+
|
|
83
|
+
try:
|
|
84
|
+
|
|
85
|
+
async def run():
|
|
86
|
+
return await api.get_results(swarm_id, tag)
|
|
87
|
+
|
|
88
|
+
results = self._run_with_progress(
|
|
89
|
+
run, f"Fetching results for swarm {swarm_id}..."
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
if results is None:
|
|
93
|
+
return 1
|
|
94
|
+
|
|
95
|
+
if not results:
|
|
96
|
+
self.print("No results found.")
|
|
97
|
+
return 0
|
|
98
|
+
|
|
99
|
+
# Display results
|
|
100
|
+
table = Table(title=f"Results for Swarm: {swarm_id} (Tag: {tag})")
|
|
101
|
+
table.add_column("Result ID", style="cyan")
|
|
102
|
+
table.add_column("Type", style="blue")
|
|
103
|
+
table.add_column("Size", style="green")
|
|
104
|
+
table.add_column("Created", style="yellow")
|
|
105
|
+
|
|
106
|
+
for result in results:
|
|
107
|
+
data = result.get("data", {})
|
|
108
|
+
data_size = len(json.dumps(data)) if data else 0
|
|
109
|
+
|
|
110
|
+
table.add_row(
|
|
111
|
+
result.get("result_id", "Unknown"),
|
|
112
|
+
result.get("result_type", "Unknown"),
|
|
113
|
+
self._format_size(data_size),
|
|
114
|
+
result.get("created_at", "Unknown"),
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
self.console.print(table)
|
|
118
|
+
|
|
119
|
+
# Show first few results as samples
|
|
120
|
+
self.print("\nSample Results:")
|
|
121
|
+
for i, result in enumerate(results[:3]):
|
|
122
|
+
self.print(f"Result {i + 1}:")
|
|
123
|
+
self.print(json.dumps(result.get("data", {}), indent=2))
|
|
124
|
+
if i < 2 and i < len(results) - 1:
|
|
125
|
+
self.print("-" * 40)
|
|
126
|
+
|
|
127
|
+
return 0
|
|
128
|
+
|
|
129
|
+
except Exception as e:
|
|
130
|
+
self.print_error(f"Failed to get results: {e}")
|
|
131
|
+
return 1
|
|
132
|
+
|
|
133
|
+
def export_results(self, swarm_id: str, tag: str, output_file: str) -> int:
|
|
134
|
+
"""Export results to a file."""
|
|
135
|
+
api = self._get_user_api()
|
|
136
|
+
if not api:
|
|
137
|
+
return 1
|
|
138
|
+
|
|
139
|
+
try:
|
|
140
|
+
|
|
141
|
+
async def run():
|
|
142
|
+
return await api.get_results(swarm_id, tag)
|
|
143
|
+
|
|
144
|
+
results = self._run_with_progress(run, "Fetching results for export...")
|
|
145
|
+
|
|
146
|
+
if results is None:
|
|
147
|
+
return 1
|
|
148
|
+
|
|
149
|
+
if not results:
|
|
150
|
+
self.print_error("No results found")
|
|
151
|
+
return 1
|
|
152
|
+
|
|
153
|
+
# Write to file
|
|
154
|
+
with open(output_file, "w") as f:
|
|
155
|
+
json.dump(results, f, indent=2)
|
|
156
|
+
|
|
157
|
+
self.print_success(f"Results exported to {output_file}")
|
|
158
|
+
return 0
|
|
159
|
+
|
|
160
|
+
except Exception as e:
|
|
161
|
+
self.print_error(f"Export failed: {e}")
|
|
162
|
+
return 1
|
|
163
|
+
|
|
164
|
+
def stream_results(self, swarm_id: str, tag: str = "latest") -> int:
|
|
165
|
+
"""Stream results in real-time."""
|
|
166
|
+
api = self._get_user_api()
|
|
167
|
+
if not api:
|
|
168
|
+
return 1
|
|
169
|
+
|
|
170
|
+
self.print(f"Streaming results for swarm: {swarm_id} (Tag: {tag})")
|
|
171
|
+
self.print("Press Ctrl+C to stop streaming...")
|
|
172
|
+
|
|
173
|
+
try:
|
|
174
|
+
# Set up signal handler for graceful shutdown
|
|
175
|
+
shutdown_flag = False
|
|
176
|
+
|
|
177
|
+
def signal_handler(sig, frame):
|
|
178
|
+
nonlocal shutdown_flag
|
|
179
|
+
shutdown_flag = True
|
|
180
|
+
|
|
181
|
+
signal.signal(signal.SIGINT, signal_handler)
|
|
182
|
+
|
|
183
|
+
last_result_count = 0
|
|
184
|
+
|
|
185
|
+
while not shutdown_flag:
|
|
186
|
+
try:
|
|
187
|
+
|
|
188
|
+
async def get_results():
|
|
189
|
+
return await api.get_results(swarm_id, tag)
|
|
190
|
+
|
|
191
|
+
results = self._run_async(get_results())
|
|
192
|
+
|
|
193
|
+
# Show new results since last check
|
|
194
|
+
if results and len(results) > last_result_count:
|
|
195
|
+
new_results = results[last_result_count:]
|
|
196
|
+
|
|
197
|
+
for result in new_results:
|
|
198
|
+
timestamp = result.get("created_at", "unknown")
|
|
199
|
+
data = result.get("data", {})
|
|
200
|
+
self.print(f"[{timestamp}] {json.dumps(data, indent=2)}")
|
|
201
|
+
|
|
202
|
+
last_result_count = len(results)
|
|
203
|
+
|
|
204
|
+
time.sleep(5) # Wait 5 seconds before next poll
|
|
205
|
+
|
|
206
|
+
except KeyboardInterrupt:
|
|
207
|
+
self.print("\nStreaming stopped.")
|
|
208
|
+
return 130 # KeyboardInterrupt exit code
|
|
209
|
+
|
|
210
|
+
except Exception as e:
|
|
211
|
+
self.print_error(f"Streaming failed: {e}")
|
|
212
|
+
return 1
|
|
213
|
+
|
|
214
|
+
def _format_size(self, size: int) -> str:
|
|
215
|
+
"""Format byte size to human readable string."""
|
|
216
|
+
for unit in ["B", "KB", "MB", "GB"]:
|
|
217
|
+
if size < 1024.0:
|
|
218
|
+
return f"{size:.1f} {unit}"
|
|
219
|
+
size /= 1024.0
|
|
220
|
+
return f"{size:.1f} TB"
|
|
221
|
+
|
|
222
|
+
def list_tags(self, swarm_id: str) -> int:
|
|
223
|
+
"""List available result tags for a swarm."""
|
|
224
|
+
api = self._get_user_api()
|
|
225
|
+
if not api:
|
|
226
|
+
return 1
|
|
227
|
+
|
|
228
|
+
try:
|
|
229
|
+
|
|
230
|
+
async def run():
|
|
231
|
+
return await api.list_result_tags(swarm_id)
|
|
232
|
+
|
|
233
|
+
tags_info = self._run_with_progress(
|
|
234
|
+
run, f"Fetching result tags for swarm {swarm_id}..."
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
if tags_info is None:
|
|
238
|
+
return 1
|
|
239
|
+
|
|
240
|
+
if not tags_info or not tags_info.get("tags"):
|
|
241
|
+
self.print("No result tags found for this swarm.")
|
|
242
|
+
return 0
|
|
243
|
+
|
|
244
|
+
# Display tags in a table
|
|
245
|
+
table = Table(title=f"Result Tags for Swarm: {swarm_id}")
|
|
246
|
+
table.add_column("Tag", style="cyan")
|
|
247
|
+
table.add_column("Count", style="green")
|
|
248
|
+
table.add_column("Total Size", style="yellow")
|
|
249
|
+
table.add_column("Last Updated", style="blue")
|
|
250
|
+
|
|
251
|
+
tags = tags_info.get("tags", {})
|
|
252
|
+
for tag, tag_data in tags.items():
|
|
253
|
+
count = tag_data.get("count", 0)
|
|
254
|
+
size = tag_data.get("total_size", 0)
|
|
255
|
+
last_updated = tag_data.get("last_updated", "Unknown")
|
|
256
|
+
|
|
257
|
+
table.add_row(tag, str(count), self._format_size(size), last_updated)
|
|
258
|
+
|
|
259
|
+
self.console.print(table)
|
|
260
|
+
|
|
261
|
+
return 0
|
|
262
|
+
|
|
263
|
+
except Exception as e:
|
|
264
|
+
self.print_error(f"Failed to list result tags: {e}")
|
|
265
|
+
return 1
|