From 055e11307760899d8fffdde586d519da4e65206e Mon Sep 17 00:00:00 2001 From: Stanley Zhang Date: Sat, 23 Mar 2024 22:10:36 +1300 Subject: [PATCH] Add support of contains/startswith to RPM content fixes #687 --- pulp-glue/pulp_glue/rpm/context.py | 3 +++ pulpcore/cli/rpm/content.py | 35 +++++++++++++++++++++++++- tests/scripts/pulp_rpm/test_content.sh | 2 ++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/pulp-glue/pulp_glue/rpm/context.py b/pulp-glue/pulp_glue/rpm/context.py index 8a6925765..5107276f1 100644 --- a/pulp-glue/pulp_glue/rpm/context.py +++ b/pulp-glue/pulp_glue/rpm/context.py @@ -94,6 +94,9 @@ def preprocess_entity(self, body: EntityDefinition, partial: bool = False) -> En self.pulp_ctx.needs_plugin(PluginRequirement("rpm", specifier=">=3.18.0")) else: PulpException(_("--relative-path must be provided")) + contains_startswith = ["name__contains", "name__startswith", "release__contains", "release__startswith", "arch__contains", "arch__startswith"] + if any(k in body for k in contains_startswith): + self.pulp_ctx.needs_plugin(PluginRequirement("rpm", specifier = ">=3.20.0")) return body diff --git a/pulpcore/cli/rpm/content.py b/pulpcore/cli/rpm/content.py index ffb133ad5..bf316f844 100644 --- a/pulpcore/cli/rpm/content.py +++ b/pulpcore/cli/rpm/content.py @@ -1,7 +1,10 @@ import typing as t import click -from pulp_glue.common.context import PulpEntityContext +from pulp_glue.common.context import ( + PluginRequirement, + PulpEntityContext, +) from pulp_glue.common.i18n import get_translation from pulp_glue.core.context import PulpArtifactContext from pulp_glue.rpm.context import ( @@ -108,10 +111,18 @@ def content() -> None: exclude_field_option, pulp_option("--repository-version"), pulp_option("--arch", allowed_with_contexts=(PulpRpmPackageContext,)), + pulp_option( + "--arch-contains", "arch__contains", allowed_with_contexts=(PulpRpmPackageContext,), + needs_plugins=[PluginRequirement("rpm", specifier=">=3.20.0")], + ), pulp_option( "--arch-in", "arch__in", multiple=True, allowed_with_contexts=(PulpRpmPackageContext,) ), pulp_option("--arch-ne", "arch__ne", allowed_with_contexts=(PulpRpmPackageContext,)), + pulp_option( + "--arch-startswith", "arch__startswith", allowed_with_contexts=(PulpRpmPackageContext,), + needs_plugins=[PluginRequirement("rpm", specifier=">=3.20.0")], + ), pulp_option("--epoch", allowed_with_contexts=(PulpRpmPackageContext,)), pulp_option( "--epoch-in", "epoch__in", multiple=True, allowed_with_contexts=(PulpRpmPackageContext,) @@ -129,6 +140,12 @@ def content() -> None: allowed_with_contexts=(PulpRpmModulemdDefaultsContext,), ), pulp_option("--name", allowed_with_contexts=(PulpRpmPackageContext, PulpRpmModulemdContext)), + pulp_option( + "--name-contains", + "name__contains", + allowed_with_contexts=(PulpRpmPackageContext, PulpRpmModulemdContext), + needs_plugins=[PluginRequirement("rpm", specifier=">=3.20.0")], + ), pulp_option( "--name-in", "name__in", @@ -140,6 +157,12 @@ def content() -> None: "name__ne", allowed_with_contexts=(PulpRpmPackageContext, PulpRpmModulemdContext), ), + pulp_option( + "--name-startswith", + "name__startswith", + allowed_with_contexts=(PulpRpmPackageContext, PulpRpmModulemdContext), + needs_plugins=[PluginRequirement("rpm", specifier=">=3.20.0")], + ), pulp_option("--package-href", allowed_with_contexts=(PulpRpmPackageContext,)), pulp_option("--pkgId", allowed_with_contexts=(PulpRpmPackageContext,)), pulp_option( @@ -149,10 +172,20 @@ def content() -> None: allowed_with_contexts=(PulpRpmPackageContext,), ), pulp_option("--release", allowed_with_contexts=(PulpRpmPackageContext,)), + pulp_option( + "--release-contains", "release__contains", allowed_with_contexts=(PulpRpmPackageContext,), + needs_plugins=[PluginRequirement("rpm", specifier=">=3.20.0")], + ), pulp_option( "--release-in", "release__in", multiple=True, allowed_with_contexts=(PulpRpmPackageContext,) ), pulp_option("--release-ne", "release__ne", allowed_with_contexts=(PulpRpmPackageContext,)), + pulp_option( + "--release-startswith", + "release__startswith", + allowed_with_contexts=(PulpRpmPackageContext,), + needs_plugins=[PluginRequirement("rpm", specifier=">=3.20.0")], + ), pulp_option("--severity", allowed_with_contexts=(PulpRpmAdvisoryContext,)), pulp_option( "--severity-in", diff --git a/tests/scripts/pulp_rpm/test_content.sh b/tests/scripts/pulp_rpm/test_content.sh index b5c2fe3cc..c19d1b441 100755 --- a/tests/scripts/pulp_rpm/test_content.sh +++ b/tests/scripts/pulp_rpm/test_content.sh @@ -126,6 +126,8 @@ do done expect_succ pulp rpm content list --name-in "${RPM_NAME}" --name-in "${RPM2_NAME}" +expect_succ pulp rpm content list --name-contains "${RPM_NAME}" +expect_succ pulp rpm content list --name-startswith "${RPM_NAME}" pulp rpm content list expect_succ test "$(echo "${OUTPUT}" | jq -r 'length')" -eq 2