|
1 | | -import typing as t |
2 | | - |
3 | 1 | import click |
4 | 2 |
|
5 | | -from pulp_glue.common.context import ( |
6 | | - EntityDefinition, |
7 | | - EntityFieldDefinition, |
8 | | - PluginRequirement, |
9 | | - PulpEntityContext, |
10 | | -) |
| 3 | +from pulp_glue.common.context import PluginRequirement |
11 | 4 | from pulp_glue.common.i18n import get_translation |
12 | 5 | from pulp_glue.python.context import ( |
13 | 6 | PulpPythonDistributionContext, |
|
27 | 20 | label_command, |
28 | 21 | list_command, |
29 | 22 | name_option, |
30 | | - pass_entity_context, |
31 | 23 | pass_pulp_context, |
32 | 24 | pulp_group, |
33 | 25 | pulp_labels_option, |
34 | 26 | pulp_option, |
35 | 27 | resource_option, |
36 | 28 | show_command, |
| 29 | + update_command, |
37 | 30 | ) |
38 | 31 |
|
39 | 32 | translation = get_translation(__package__) |
@@ -110,77 +103,8 @@ def distribution(ctx: click.Context, pulp_ctx: PulpCLIContext, /, distribution_t |
110 | 103 | distribution.add_command(list_command(decorators=distribution_filter_options)) |
111 | 104 | distribution.add_command(show_command(decorators=lookup_options)) |
112 | 105 | distribution.add_command(create_command(decorators=create_options)) |
| 106 | +distribution.add_command( |
| 107 | + update_command(decorators=lookup_options + update_options + [click.option("--base-path")]) |
| 108 | +) |
113 | 109 | distribution.add_command(destroy_command(decorators=lookup_options)) |
114 | 110 | distribution.add_command(label_command(decorators=nested_lookup_options)) |
115 | | - |
116 | | - |
117 | | -def apply_decorators(decorators_list: list[t.Callable[..., t.Any]]) -> t.Callable[..., t.Any]: |
118 | | - def decorator(func: t.Callable[..., t.Any]) -> t.Callable[..., t.Any]: |
119 | | - for d in decorators_list: |
120 | | - func = d(func) |
121 | | - return func |
122 | | - |
123 | | - return decorator |
124 | | - |
125 | | - |
126 | | -@distribution.command() |
127 | | -@apply_decorators(lookup_options + update_options + [click.option("--base-path")]) |
128 | | -@pass_entity_context |
129 | | -def update( |
130 | | - distribution_ctx: PulpEntityContext, |
131 | | - /, |
132 | | - publication: str | None, |
133 | | - repository: EntityFieldDefinition, |
134 | | - version: int | None, |
135 | | - content_guard: EntityFieldDefinition, |
136 | | - allow_uploads: bool | None, |
137 | | - remote: EntityFieldDefinition, |
138 | | - pulp_labels: dict[str, str] | None, |
139 | | - base_path: str | None, |
140 | | -) -> None: |
141 | | - """ |
142 | | - Update a Python distribution. |
143 | | - """ |
144 | | - assert isinstance(distribution_ctx, PulpPythonDistributionContext) |
145 | | - |
146 | | - dist_body: EntityDefinition = distribution_ctx.entity |
147 | | - body: EntityDefinition = dict() |
148 | | - |
149 | | - if publication is not None: |
150 | | - body["publication"] = publication |
151 | | - if content_guard is not None: |
152 | | - body["content_guard"] = content_guard |
153 | | - if allow_uploads is not None: |
154 | | - body["allow_uploads"] = allow_uploads |
155 | | - if remote is not None: |
156 | | - body["remote"] = remote |
157 | | - if pulp_labels is not None: |
158 | | - body["pulp_labels"] = pulp_labels |
159 | | - if base_path is not None: |
160 | | - body["base_path"] = base_path |
161 | | - |
162 | | - if repository is not None and isinstance(repository, PulpPythonRepositoryContext): |
163 | | - repo = repository.entity |
164 | | - if version is not None: |
165 | | - if dist_body.get("repository"): |
166 | | - distribution_ctx.update(body={"repository": ""}, non_blocking=True) |
167 | | - body["repository_version"] = f"{repo['versions_href']}{version}/" |
168 | | - else: |
169 | | - if dist_body.get("repository_version"): |
170 | | - distribution_ctx.update(body={"repository_version": ""}, non_blocking=True) |
171 | | - body["repository"] = repo["pulp_href"] |
172 | | - elif version is not None: |
173 | | - if dist_body.get("repository"): |
174 | | - distribution_ctx.update(body={"repository": ""}, non_blocking=True) |
175 | | - body["repository_version"] = f"{dist_body['repository']}versions/{version}/" |
176 | | - elif dist_body.get("repository_version"): |
177 | | - repository_href = dist_body["repository_version"].partition("versions")[0] |
178 | | - body["repository_version"] = f"{repository_href}versions/{version}/" |
179 | | - else: |
180 | | - raise click.ClickException( |
181 | | - _( |
182 | | - "Distribution doesn't have a repository set, " |
183 | | - "please specify the repository to use with --repository" |
184 | | - ) |
185 | | - ) |
186 | | - distribution_ctx.update(body=body) |
0 commit comments