Skip to content

Commit

Permalink
WIP Add global repository version list command
Browse files Browse the repository at this point in the history
fixes pulp#631
  • Loading branch information
mdellweg committed Mar 6, 2023
1 parent 314dc7c commit f04bfb7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pulp-glue/pulp_glue/common/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,10 @@ def pulp_href(self, value: str) -> None:
self._entity_lookup = {"pulp_href": value}
self._entity = None

@property
def tangible(self) -> bool:
return self._entity or self._entity_lookup

def __init__(
self,
pulp_ctx: PulpContext,
Expand Down Expand Up @@ -734,6 +738,7 @@ class PulpRepositoryVersionContext(PulpEntityContext):

ENTITY = _("repository version")
ENTITIES = _("repository versions")
ID_PREFIX = "repository_versions"
repository_ctx: "PulpRepositoryContext"

def __init__(self, pulp_ctx: PulpContext, repository_ctx: "PulpRepositoryContext") -> None:
Expand All @@ -742,7 +747,10 @@ def __init__(self, pulp_ctx: PulpContext, repository_ctx: "PulpRepositoryContext

@property
def scope(self) -> Dict[str, Any]:
return {self.repository_ctx.HREF: self.repository_ctx.pulp_href}
if self.repository_ctx.tangible:
return {self.repository_ctx.HREF: self.repository_ctx.pulp_href}
else:
return {}

def repair(self, href: Optional[str] = None) -> Any:
return self.call("repair", parameters={self.HREF: href or self.pulp_href}, body={})
Expand All @@ -759,7 +767,7 @@ class PulpRepositoryContext(PulpEntityContext):
ENTITIES = _("repositories")
HREF_PATTERN = r"repositories/(?P<plugin>[\w\-_]+)/(?P<resource_type>[\w\-_]+)/"
ID_PREFIX = "repositories"
VERSION_CONTEXT: ClassVar[Type[PulpRepositoryVersionContext]]
VERSION_CONTEXT: ClassVar[Type[PulpRepositoryVersionContext]] = PulpRepositoryVersionContext
NULLABLES = {"description", "retain_repo_versions"}

def get_version_context(self) -> PulpRepositoryVersionContext:
Expand Down
17 changes: 17 additions & 0 deletions pulpcore/cli/core/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
list_command,
name_filter_options,
pass_pulp_context,
pass_repository_context,
pulp_group,
)

Expand All @@ -30,3 +31,19 @@ def repository(ctx: click.Context, pulp_ctx: PulpCLIContext) -> None:
filter_options = name_filter_options

repository.add_command(list_command(decorators=filter_options))


@repository.group
@pass_repository_context
@click.pass_context
def version(ctx: click.Context, repository_ctx: PulpRepositoryContext) -> None:
"""
Subcommands perform actions on all repository versions.
Please look for the plugin specific repository version commands for more detailed actions.
i.e. `pulp file repository version <...>'
"""
ctx.obj = repository_ctx.get_version_context()


version.add_command(list_command())

0 comments on commit f04bfb7

Please sign in to comment.