Skip to content
Snippets Groups Projects
Commit 6b60a307 authored by Marco Clemencic's avatar Marco Clemencic
Browse files

LBCORE-1001: Unsorted lb-dev version list

Fixed sorting of listed versions.
parent 03c3f649
No related branches found
No related tags found
1 merge request!8Fixed sorting of listed versions in lb-dev/lb-run
......@@ -11,11 +11,12 @@
__author__ = 'Marco Clemencic <marco.clemencic@cern.ch>'
import os
import re
import logging
# FIXME: when we drop Python 2.4, this should become 'from . import path'
from LbConfiguration.SP2 import path, Error
from LbConfiguration.SP2.version import DEFAULT_VERSION, expandVersionAlias
from LbConfiguration.SP2.version import DEFAULT_VERSION, versionKey
log = logging.getLogger(__name__)
......@@ -121,7 +122,7 @@ def listVersions(name, platform):
for filename in files
if filename.startswith(prefix) and
isValidVersion(name, filename[prefixlen:])],
reverse=True):
reverse=True, key=versionKey):
version, fullpath = entry
if (version not in found_versions and
os.path.isdir(os.path.join(fullpath, bindir))):
......@@ -136,7 +137,7 @@ def listVersions(name, platform):
if filename.startswith(prefix_u) and
isValidVersion(name,
filename[prefixlen:])],
reverse=True):
reverse=True, key=versionKey):
version, fullpath = entry
if (version not in found_versions and
os.path.isdir(os.path.join(fullpath, bindir))):
......@@ -173,8 +174,7 @@ def findDataPackage(name, version):
if not versions:
raise MissingDataPackageError(name, version, path)
# sort the versions found
versions.sort(key=lambda x: tuple(map(int, findall(r'\d+', x[0]))),
reverse=True)
versions.sort(key=versionKey, reverse=True)
v, p = versions[0]
return os.path.join(p, v)
......
......@@ -36,3 +36,20 @@ def expandVersionAlias(project, version, platform):
pass
log.debug('using %r', result)
return result
def versionKey(v):
'''
For a version string with numbers alternated by alphanumeric separators,
return a tuple containing the separators and the numbers.
For example:
>>> versionKey('1.2.3')
(1, '.', 2, '.', 3)
>>> versionKey('v10r0')
('v', 10, 'r', 0)
>>> versionKey('1.2-a')
(1, '.', 2, '-a')
'''
v = re.findall(r'[-a-zA-Z_.]+|\d+', v)
return tuple([int(x) if x.isdigit() else x for x in v])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment