diff options
author | Andy Doan <andy.doan@linaro.org> | 2016-11-22 11:02:59 -0600 |
---|---|---|
committer | Andy Doan <andy.doan@linaro.org> | 2016-11-22 19:30:22 +0000 |
commit | 4758205cab715271b7aea386121bb2cdd180e9c8 (patch) | |
tree | 35e459f47245f401a40cc7c0d03bfb34807eb371 /license_protected_downloads | |
parent | 90dde941550db5f1a9947d3c3d8c63fe788bec8b (diff) |
change sorting logic
We should list the most recent builds before the older builds to help
reduce scrolling.
Change-Id: Iae7e22d049a5e1f3b6d5f1c075039a0773f119eb
Reviewed-on: https://review.linaro.org/15748
Reviewed-by: Andy Doan <andy.doan@linaro.org>
Diffstat (limited to 'license_protected_downloads')
-rw-r--r-- | license_protected_downloads/common.py | 6 | ||||
-rw-r--r-- | license_protected_downloads/tests/test_common.py | 4 |
2 files changed, 7 insertions, 3 deletions
diff --git a/license_protected_downloads/common.py b/license_protected_downloads/common.py index 0fe948a..7a9aaff 100644 --- a/license_protected_downloads/common.py +++ b/license_protected_downloads/common.py @@ -144,14 +144,18 @@ def _sort_artifacts(a, b): a = a.file_name b = b.file_name try: - return cmp(int(a), int(b)) + # we want listings of build numbers (integers) and releases (floats eg + # "16.12" to listed in reverse order so they show newest to oldest + return cmp(float(b), float(a)) except: pass + # always give preference to make "latest" show first if a == 'latest': return -1 elif b == 'latest': return 1 + # just do a normal string sort return cmp(a, b) diff --git a/license_protected_downloads/tests/test_common.py b/license_protected_downloads/tests/test_common.py index 4465c3b..d040999 100644 --- a/license_protected_downloads/tests/test_common.py +++ b/license_protected_downloads/tests/test_common.py @@ -21,8 +21,8 @@ class CommonTests(unittest.TestCase): def test_sort_artifacts(self): patterns = [ (['b', 'a', 'latest', 'c'], ['latest', 'a', 'b', 'c']), - (['10', '1', '100', 'latest'], ['latest', '1', '10', '100']), - (['10', 'foo', '100', 'latest'], ['latest', '10', '100', 'foo']), + (['10', '1', '100', 'latest'], ['latest', '100', '10', '1']), + (['10', 'foo', '100', 'latest'], ['latest', '100', '10', 'foo']), ] for files, expected in patterns: artifacts = [LocalArtifact(None, '', x, True, '') |