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/1216.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a bug where Python repository content addition/removal failed due to duplicate filenames.
33 changes: 19 additions & 14 deletions pulpcore/cli/python/locale/de/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-03-19 11:46+0100\n"
"POT-Creation-Date: 2025-08-01 16:28+0200\n"
"PO-Revision-Date: 2021-12-06 11:24+0100\n"
"Last-Translator: Matthias Dellweg <mdellweg@redhat.com>\n"
"Language-Team: \n"
Expand All @@ -17,26 +17,26 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 3.0\n"

#: pulpcore/cli/python/content.py:47
#: pulpcore/cli/python/content.py:49
msgid ""
"Repository to add the content to in the form "
"'[[<plugin>:]<resource_type>:]<name>' or by href."
msgstr ""

#: pulpcore/cli/python/content.py:71 pulpcore/cli/python/content.py:96
#: pulpcore/cli/python/content.py:73 pulpcore/cli/python/content.py:106
msgid "Exact name of file"
msgstr ""

#: pulpcore/cli/python/content.py:75
#: pulpcore/cli/python/content.py:77
#, fuzzy
msgid "Digest of the artifact to use [deprecated]"
msgstr "Fingerabdruck des zu verwendenden Artefakts"

#: pulpcore/cli/python/content.py:80
#: pulpcore/cli/python/content.py:82
msgid "Remote url to download and create python content from"
msgstr ""

#: pulpcore/cli/python/content.py:97
#: pulpcore/cli/python/content.py:107
msgid "Path to file"
msgstr "Pfad zur Datei"

Expand Down Expand Up @@ -74,33 +74,38 @@ msgstr ""
msgid "Failed to load content from {requirements_file}"
msgstr ""

#: pulpcore/cli/python/repository.py:54
#: pulpcore/cli/python/repository.py:58
msgid ""
"Remote used for synching in the form '[[<plugin>:]<resource_type>:]<name>' "
"or by href."
msgstr ""

#: pulpcore/cli/python/repository.py:104
msgid "Filename of the python package"
#: pulpcore/cli/python/repository.py:86
#, python-brace-format
msgid "Validation of '{parameter}' failed: {error}"
msgstr ""

#: pulpcore/cli/python/repository.py:131
msgid "Filename of the python package."
msgstr ""

#: pulpcore/cli/python/repository.py:112
#: pulpcore/cli/python/repository.py:142
msgid ""
"JSON string with a list of objects to add to the repository.\n"
" Each object should have the key: \"filename\"\n"
" Each object must contain the following keys: \"sha256\", \"filename\".\n"
" The argument prefixed with the '@' can be the path to a JSON file with a "
"list of objects."
msgstr ""

#: pulpcore/cli/python/repository.py:121
#: pulpcore/cli/python/repository.py:151
msgid ""
"JSON string with a list of objects to remove from the repository.\n"
" Each object should have the key: \"filename\"\n"
" Each object must contain the following keys: \"sha256\", \"filename\".\n"
" The argument prefixed with the '@' can be the path to a JSON file with a "
"list of objects."
msgstr ""

#: pulpcore/cli/python/repository.py:172
#: pulpcore/cli/python/repository.py:202
#, python-brace-format
msgid ""
"Repository '{name}' does not have a default remote. Please specify with '--"
Expand Down
33 changes: 19 additions & 14 deletions pulpcore/cli/python/locale/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-03-19 11:46+0100\n"
"POT-Creation-Date: 2025-08-01 16:28+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand All @@ -17,25 +17,25 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

#: pulpcore/cli/python/content.py:47
#: pulpcore/cli/python/content.py:49
msgid ""
"Repository to add the content to in the form "
"'[[<plugin>:]<resource_type>:]<name>' or by href."
msgstr ""

#: pulpcore/cli/python/content.py:71 pulpcore/cli/python/content.py:96
#: pulpcore/cli/python/content.py:73 pulpcore/cli/python/content.py:106
msgid "Exact name of file"
msgstr ""

#: pulpcore/cli/python/content.py:75
#: pulpcore/cli/python/content.py:77
msgid "Digest of the artifact to use [deprecated]"
msgstr ""

#: pulpcore/cli/python/content.py:80
#: pulpcore/cli/python/content.py:82
msgid "Remote url to download and create python content from"
msgstr ""

#: pulpcore/cli/python/content.py:97
#: pulpcore/cli/python/content.py:107
msgid "Path to file"
msgstr ""

Expand Down Expand Up @@ -72,33 +72,38 @@ msgstr ""
msgid "Failed to load content from {requirements_file}"
msgstr ""

#: pulpcore/cli/python/repository.py:54
#: pulpcore/cli/python/repository.py:58
msgid ""
"Remote used for synching in the form '[[<plugin>:]<resource_type>:]<name>' "
"or by href."
msgstr ""

#: pulpcore/cli/python/repository.py:104
msgid "Filename of the python package"
#: pulpcore/cli/python/repository.py:86
#, python-brace-format
msgid "Validation of '{parameter}' failed: {error}"
msgstr ""

#: pulpcore/cli/python/repository.py:131
msgid "Filename of the python package."
msgstr ""

#: pulpcore/cli/python/repository.py:112
#: pulpcore/cli/python/repository.py:142
msgid ""
"JSON string with a list of objects to add to the repository.\n"
" Each object should have the key: \"filename\"\n"
" Each object must contain the following keys: \"sha256\", \"filename\".\n"
" The argument prefixed with the '@' can be the path to a JSON file with a "
"list of objects."
msgstr ""

#: pulpcore/cli/python/repository.py:121
#: pulpcore/cli/python/repository.py:151
msgid ""
"JSON string with a list of objects to remove from the repository.\n"
" Each object should have the key: \"filename\"\n"
" Each object must contain the following keys: \"sha256\", \"filename\".\n"
" The argument prefixed with the '@' can be the path to a JSON file with a "
"list of objects."
msgstr ""

#: pulpcore/cli/python/repository.py:172
#: pulpcore/cli/python/repository.py:202
#, python-brace-format
msgid ""
"Repository '{name}' does not have a default remote. Please specify with '--"
Expand Down
58 changes: 44 additions & 14 deletions pulpcore/cli/python/repository.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import typing as t

import click
import schema as s
from pulp_glue.common.context import (
EntityFieldDefinition,
PluginRequirement,
Expand All @@ -15,14 +16,17 @@
)

from pulp_cli.generic import (
GroupOption,
PulpCLIContext,
create_command,
create_content_json_callback,
destroy_command,
href_option,
json_callback,
label_command,
label_select_option,
list_command,
load_file_wrapper,
name_option,
pass_pulp_context,
pass_repository_context,
Expand Down Expand Up @@ -56,16 +60,35 @@
)


def _content_callback(
ctx: click.Context, param: click.Parameter, value: t.Optional[str]
) -> t.Optional[str]:
def _content_callback(ctx: click.Context, param: click.Parameter, value: t.Any) -> t.Any:
if value:
pulp_ctx = ctx.find_object(PulpCLIContext)
assert pulp_ctx is not None
ctx.obj = PulpPythonContentContext(pulp_ctx, entity={"filename": value})
ctx.obj = PulpPythonContentContext(pulp_ctx, entity=value)
return value


CONTENT_LIST_SCHEMA = s.Schema([{"sha256": str, "filename": s.And(str, len)}])


@load_file_wrapper
def _content_list_callback(
ctx: click.Context, param: click.Parameter, value: t.Optional[str]
) -> t.Any:
if value is None:
return None

result = json_callback(ctx, param, value)
try:
return CONTENT_LIST_SCHEMA.validate(result)
except s.SchemaError as e:
raise click.ClickException(
_("Validation of '{parameter}' failed: {error}").format(
parameter=param.name, error=str(e)
)
)


@pulp_group()
@click.option(
"-t",
Expand Down Expand Up @@ -97,20 +120,27 @@ def repository(ctx: click.Context, pulp_ctx: PulpCLIContext, /, repo_type: str)
pulp_labels_option,
]
create_options = update_options + [click.option("--name", required=True)]
package_option = click.option(
"--filename",
callback=_content_callback,
expose_value=False,
help=_("Filename of the python package"),
package_options = [
click.option("--sha256", cls=GroupOption, expose_value=False, group=["filename"]),
click.option(
"--filename",
callback=_content_callback,
expose_value=False,
cls=GroupOption,
group=["sha256"],
help=_("Filename of the python package."),
),
]
content_json_callback = create_content_json_callback(
PulpPythonContentContext, schema=CONTENT_LIST_SCHEMA
)
content_json_callback = create_content_json_callback(PulpPythonContentContext)
modify_options = [
click.option(
"--add-content",
callback=content_json_callback,
help=_(
"""JSON string with a list of objects to add to the repository.
Each object should have the key: "filename"
Each object must contain the following keys: "sha256", "filename".
The argument prefixed with the '@' can be the path to a JSON file with a list of objects."""
),
),
Expand All @@ -119,7 +149,7 @@ def repository(ctx: click.Context, pulp_ctx: PulpCLIContext, /, repo_type: str)
callback=content_json_callback,
help=_(
"""JSON string with a list of objects to remove from the repository.
Each object should have the key: "filename"
Each object must contain the following keys: "sha256", "filename".
The argument prefixed with the '@' can be the path to a JSON file with a list of objects."""
),
),
Expand All @@ -136,8 +166,8 @@ def repository(ctx: click.Context, pulp_ctx: PulpCLIContext, /, repo_type: str)
repository.add_command(
repository_content_command(
contexts={"package": PulpPythonContentContext},
add_decorators=[package_option],
remove_decorators=[package_option],
add_decorators=package_options,
remove_decorators=package_options,
modify_decorators=modify_options,
base_default_plugin="python",
base_default_type="python",
Expand Down
8 changes: 4 additions & 4 deletions tests/scripts/pulp_python/test_content.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fi

expect_succ pulp python repository create --name "cli_test_python_repository"
HREF="$(echo "$OUTPUT" | jq -r '.pulp_href')"
expect_succ pulp python repository content add --repository "cli_test_python_repository" --filename "shelf-reader-0.1.tar.gz"
expect_succ pulp python repository content add --repository "$HREF" --filename "shelf-reader-0.1.tar.gz" --base-version 0
expect_succ pulp python repository content remove --repository "cli_test_python_repository" --filename "shelf-reader-0.1.tar.gz"
expect_succ pulp python repository content remove --repository "$HREF" --filename "shelf-reader-0.1.tar.gz" --base-version 1
expect_succ pulp python repository content add --repository "cli_test_python_repository" --sha256 "$sha256" --filename "shelf-reader-0.1.tar.gz"
expect_succ pulp python repository content add --repository "$HREF" --sha256 "$sha256" --filename "shelf-reader-0.1.tar.gz" --base-version 0
expect_succ pulp python repository content remove --repository "cli_test_python_repository" --sha256 "$sha256" --filename "shelf-reader-0.1.tar.gz"
expect_succ pulp python repository content remove --repository "$HREF" --sha256 "$sha256" --filename "shelf-reader-0.1.tar.gz" --base-version 1
Loading