From f04bfb72ba236d57c73063da1423847b6f9b07fc Mon Sep 17 00:00:00 2001 From: Matthias Dellweg Date: Mon, 6 Mar 2023 13:48:32 +0100 Subject: [PATCH] WIP Add global repository version list command fixes #631 --- pulp-glue/pulp_glue/common/context.py | 12 ++++++++++-- pulpcore/cli/core/repository.py | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/pulp-glue/pulp_glue/common/context.py b/pulp-glue/pulp_glue/common/context.py index d32b36fc4..31337d56d 100644 --- a/pulp-glue/pulp_glue/common/context.py +++ b/pulp-glue/pulp_glue/common/context.py @@ -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, @@ -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: @@ -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={}) @@ -759,7 +767,7 @@ class PulpRepositoryContext(PulpEntityContext): ENTITIES = _("repositories") HREF_PATTERN = r"repositories/(?P[\w\-_]+)/(?P[\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: diff --git a/pulpcore/cli/core/repository.py b/pulpcore/cli/core/repository.py index 980b5f8c1..4bfe12156 100644 --- a/pulpcore/cli/core/repository.py +++ b/pulpcore/cli/core/repository.py @@ -7,6 +7,7 @@ list_command, name_filter_options, pass_pulp_context, + pass_repository_context, pulp_group, ) @@ -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())