Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/1172.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added `profile-artifact-urls` subcommand to `task` command.
1 change: 1 addition & 0 deletions CHANGES/pulp-glue/1172.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added `profile_artifact_urls` to `PulpTaskContext`.
9 changes: 9 additions & 0 deletions pulp-glue/pulp_glue/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,15 @@ def cancel(self, task_href: t.Optional[str] = None, background: bool = False) ->
self.pulp_ctx.echo(_("Done."), err=True)
return task

def profile_artifact_urls(self) -> t.Dict[str, str]:
self.pulp_ctx.needs_plugin(PluginRequirement("core", specifier=">=3.57.0"))
result = self.call(
"profile_artifacts",
parameters={self.HREF: self.pulp_href},
)["urls"]
assert isinstance(result, dict)
return result

@property
def scope(self) -> t.Dict[str, t.Any]:
if self.resource_context:
Expand Down
34 changes: 34 additions & 0 deletions pulpcore/cli/core/task.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import re
import typing as t
from contextlib import suppress
from datetime import datetime
from pathlib import Path

import click
import requests
from pulp_glue.common.context import DATETIME_FORMATS, PluginRequirement, PulpEntityContext
from pulp_glue.common.exceptions import PulpException
from pulp_glue.common.i18n import get_translation
Expand Down Expand Up @@ -167,6 +170,37 @@ def cancel(
task_ctx.cancel(task_ctx.pulp_href)


@task.command()
@href_option
@uuid_option
@click.option("--download/--no-download")
@pass_task_context
@pass_pulp_context
def profile_artifact_urls(
pulp_ctx: PulpCLIContext,
task_ctx: PulpTaskContext,
/,
download: bool,
) -> None:
"""Prints download links for profile urls of the task."""
urls = task_ctx.profile_artifact_urls()
pulp_ctx.output_result(urls)
if download:
task_name: str = task_ctx.entity["name"]
uuid_match = re.match(r".*/api/v3/tasks/(?P<uuid>.*)/", task_ctx.entity["pulp_href"])
assert uuid_match is not None
uuid = uuid_match.group("uuid")
profile_artifact_dir = Path(".") / f"task_profile-{task_name}-{uuid}"
profile_artifact_dir.mkdir(exist_ok=True)
with requests.session() as session:
for name, url in urls.items():
profile_artifact_path = profile_artifact_dir / name
click.echo(_("Downloading {path}").format(path=profile_artifact_path))
response = session.get(url)
response.raise_for_status()
profile_artifact_path.write_bytes(response.content)


@task.command()
@click.option(
"--finished-before",
Expand Down
Loading