|
2 | 2 | Contains possible interactions with the Galaxy workflow invocations |
3 | 3 | """ |
4 | 4 |
|
| 5 | +import base64 |
5 | 6 | import logging |
6 | 7 | from typing import ( |
7 | 8 | Any, |
@@ -267,6 +268,39 @@ def cancel_invocation(self, invocation_id: str) -> dict[str, Any]: |
267 | 268 | url = self._make_url(invocation_id) |
268 | 269 | return self._delete(url=url) |
269 | 270 |
|
| 271 | + def import_invocation( |
| 272 | + self, history_id: str, model_store_format: str, file_path: Optional[str] = None, url: Optional[str] = None |
| 273 | + ) -> Any: |
| 274 | + """ |
| 275 | + Import a invocation from an archive on disk or a URL. |
| 276 | +
|
| 277 | + :type history_id |
| 278 | + :param history_id: id of the history where the invocation will be imported |
| 279 | +
|
| 280 | + :type model_store_format |
| 281 | + :param model_store_format: archive type that will be imported |
| 282 | +
|
| 283 | + :type file_path: str |
| 284 | + :param file_path: Path to exported history archive on disk. |
| 285 | +
|
| 286 | + :type url: str |
| 287 | + :param url: URL for an exported history archive |
| 288 | +
|
| 289 | + :rtype: dict or list of dicts |
| 290 | + :return: if the import is successful, a list of dictionaries will be returned; otherwise, a single dictionary will be returned. |
| 291 | + """ |
| 292 | + payload: dict[str, Any] = { |
| 293 | + "history_id": history_id, |
| 294 | + "model_store_format": model_store_format, |
| 295 | + } |
| 296 | + if file_path: |
| 297 | + with open(file_path, "rb") as reader: |
| 298 | + payload["store_content_uri"] = "base64://" + base64.b64encode(reader.read()).decode("utf-8") |
| 299 | + else: |
| 300 | + payload["store_content_uri"] = url |
| 301 | + url = "/".join((self._make_url(), "from_store")) |
| 302 | + return self._post(url=url, payload=payload) |
| 303 | + |
270 | 304 | def show_invocation_step(self, invocation_id: str, step_id: str) -> dict[str, Any]: |
271 | 305 | """ |
272 | 306 | See the details of a particular workflow invocation step. |
|
0 commit comments