-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix legacy role view version sorting and validation (#1953)
* Always sort the versions at serialization time until we have real models with sortable querysets. * Need to allow role versions with -any- numerical component. No-Issue Signed-off-by: James Tanner <tanner.jc@gmail.com>
- Loading branch information
Showing
3 changed files
with
26 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import semantic_version | ||
from ansible.module_utils.compat.version import LooseVersion | ||
|
||
|
||
def parse_version_tag(value): | ||
value = str(value) | ||
if not value: | ||
raise ValueError('Empty version value') | ||
if value[0].lower() == 'v': | ||
value = value[1:] | ||
return semantic_version.Version(value) | ||
|
||
|
||
def sort_versions(versions): | ||
""" | ||
Use ansible-core's LooseVersion util to sort the version dicts by the tag key. | ||
""" | ||
sorted_versions = sorted(versions, key=lambda x: LooseVersion(x['tag'].lower())) | ||
return sorted_versions |