|
| 1 | +import re |
1 | 2 | import typing as t |
2 | 3 | from contextlib import suppress |
3 | 4 | from datetime import datetime |
| 5 | +from pathlib import Path |
4 | 6 |
|
5 | 7 | import click |
| 8 | +import requests |
6 | 9 | from pulp_glue.common.context import DATETIME_FORMATS, PluginRequirement, PulpEntityContext |
7 | 10 | from pulp_glue.common.exceptions import PulpException |
8 | 11 | from pulp_glue.common.i18n import get_translation |
@@ -167,6 +170,37 @@ def cancel( |
167 | 170 | task_ctx.cancel(task_ctx.pulp_href) |
168 | 171 |
|
169 | 172 |
|
| 173 | +@task.command() |
| 174 | +@href_option |
| 175 | +@uuid_option |
| 176 | +@click.option("--download/--no-download") |
| 177 | +@pass_task_context |
| 178 | +@pass_pulp_context |
| 179 | +def profile_artifact_urls( |
| 180 | + pulp_ctx: PulpCLIContext, |
| 181 | + task_ctx: PulpTaskContext, |
| 182 | + /, |
| 183 | + download: bool, |
| 184 | +) -> None: |
| 185 | + """Prints download links for profile urls of the task.""" |
| 186 | + urls = task_ctx.profile_artifact_urls() |
| 187 | + pulp_ctx.output_result(urls) |
| 188 | + if download: |
| 189 | + task_name: str = task_ctx.entity["name"] |
| 190 | + uuid_match = re.match(r".*/api/v3/tasks/(?P<uuid>.*)/", task_ctx.entity["pulp_href"]) |
| 191 | + assert uuid_match is not None |
| 192 | + uuid = uuid_match.group("uuid") |
| 193 | + profile_artifact_dir = Path(".") / f"task_profile-{task_name}-{uuid}" |
| 194 | + profile_artifact_dir.mkdir(exist_ok=True) |
| 195 | + with requests.session() as session: |
| 196 | + for name, url in urls.items(): |
| 197 | + profile_artifact_path = profile_artifact_dir / name |
| 198 | + click.echo(_("Downloading {path}").format(path=profile_artifact_path)) |
| 199 | + response = session.get(url) |
| 200 | + response.raise_for_status() |
| 201 | + profile_artifact_path.write_bytes(response.content) |
| 202 | + |
| 203 | + |
170 | 204 | @task.command() |
171 | 205 | @click.option( |
172 | 206 | "--finished-before", |
|
0 commit comments