Skip to content

Commit e115543

Browse files
authored
Merge pull request #23 from /issues/8
pulp_distribution: sort repository versions numerically
2 parents 842d724 + 094aef2 commit e115543

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

plugins/filter/filters.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright (c) 2021 StackHPC Ltd.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
15+
def sort_publications(pubs):
16+
"""Sort a list of publications by repository version.
17+
18+
Higher repository versions are listed first.
19+
"""
20+
def key(pub):
21+
# Format: /pulp/api/v3/repositories/rpm/rpm/<repo UUID>/versions/<version>/
22+
rv = pub["repository_version"]
23+
return int(rv.split("/")[-2])
24+
25+
return sorted(pubs, key=key, reverse=True)
26+
27+
28+
class FilterModule(object):
29+
30+
def filters(self):
31+
return {
32+
"sort_publications": sort_publications
33+
}

roles/pulp_distribution/tasks/deb.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
# If the distribution references a specific version:
3030
specific_pub: "{{ pulp_pubs_list.publications | selectattr('repository_version', 'equalto', repo.pulp_href ~ 'versions/' ~ item.version | default ~ '/') }}"
3131
# If the distribution uses the latest version:
32-
latest_pub: "{{ pulp_pubs_list.publications | selectattr('repository', 'equalto', repo.pulp_href) | sort(attribute='repository_version', reverse=True) }}"
32+
latest_pub: "{{ pulp_pubs_list.publications | selectattr('repository', 'equalto', repo.pulp_href) | stackhpc.pulp.sort_publications }}"
3333
# If another distribution is being promoted to this one:
3434
promoted_dist: "{{ pulp_dists_list.distributions | selectattr('name', 'equalto', item.distribution | default) }}"
3535
promoted_pub: "{{ pulp_pubs_list.publications | selectattr('pulp_href', 'equalto', (promoted_dist | first).publication | default) }}"

roles/pulp_distribution/tasks/rpm.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
# If the distribution references a specific version:
3030
specific_pub: "{{ pulp_pubs_list.publications | selectattr('repository_version', 'equalto', repo.pulp_href ~ 'versions/' ~ item.version | default ~ '/') }}"
3131
# If the distribution uses the latest version:
32-
latest_pub: "{{ pulp_pubs_list.publications | selectattr('repository', 'equalto', repo.pulp_href) | sort(attribute='repository_version', reverse=True) }}"
32+
latest_pub: "{{ pulp_pubs_list.publications | selectattr('repository', 'equalto', repo.pulp_href) | stackhpc.pulp.sort_publications }}"
3333
# If another distribution is being promoted to this one:
3434
promoted_dist: "{{ pulp_dists_list.distributions | selectattr('name', 'equalto', item.distribution | default) }}"
3535
promoted_pub: "{{ pulp_pubs_list.publications | selectattr('pulp_href', 'equalto', (promoted_dist | first).publication | default) }}"

0 commit comments

Comments
 (0)