mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-09 06:40:03 -07:00
* Add version_sort filter to properly sort list of versions
* Fix all comments from Felix
- add changelog fragment
- fix test by removing runme.sh/yml and renaming to filter_version_sort
- use fully qualified name of filter in test case
* Remove wrong plugin.test changelog fragment
Ups...
* Properly name the file version_sort.py
* Update changelogs/fragments/1916-add-version-sort-filter.yml
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Eric L <ewl+git@lavar.de>
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 4a8d6cf7cc
)
Co-authored-by: Eric L <ericzolf@users.noreply.github.com>
This commit is contained in:
parent
87377dd23f
commit
68baf56ea6
4 changed files with 36 additions and 0 deletions
21
plugins/filter/version_sort.py
Normal file
21
plugins/filter/version_sort.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Copyright (C) 2021 Eric Lavarde <elavarde@redhat.com>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from distutils.version import LooseVersion
|
||||
|
||||
|
||||
def version_sort(value, reverse=False):
|
||||
'''Sort a list according to loose versions so that e.g. 2.9 is smaller than 2.10'''
|
||||
return sorted(value, key=LooseVersion, reverse=reverse)
|
||||
|
||||
|
||||
class FilterModule(object):
|
||||
''' Version sort filter '''
|
||||
|
||||
def filters(self):
|
||||
return {
|
||||
'version_sort': version_sort
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue