diff options
author | Kamran Khan <kamran.khan@mongodb.com> | 2014-04-14 12:33:13 -0400 |
---|---|---|
committer | Dan Pasette <dan@mongodb.com> | 2014-05-24 20:08:32 -0400 |
commit | 03f395347f137afb843e3fcc362181ee7adc884a (patch) | |
tree | 243e393db55710e566701c9d3c7209f9746f415b | |
parent | 93dda51140446d51c5be01aafd2cc8fecb7eff31 (diff) | |
download | mongo-03f395347f137afb843e3fcc362181ee7adc884a.tar.gz |
SERVER-13494 Use numeric sorting for versions in the multi-version script
Signed-off-by: Matt Kangas <matt.kangas@mongodb.com>
(cherry picked from commit 8cc8ec7cd412292a8a54d2765984e8fa1319ba61)
-rw-r--r-- | buildscripts/setup_multiversion_mongodb.py | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/buildscripts/setup_multiversion_mongodb.py b/buildscripts/setup_multiversion_mongodb.py index 8ecf0524456..dcf65f77a76 100644 --- a/buildscripts/setup_multiversion_mongodb.py +++ b/buildscripts/setup_multiversion_mongodb.py @@ -17,6 +17,28 @@ import gzip # Only really tested/works on Linux. # +def version_tuple(version): + """Returns a version tuple that can be used for numeric sorting + of version strings such as '2.6.0-rc1' and '2.4.0'""" + + RC_OFFSET = -100 + version_parts = re.split(r'\.|-', version[0]) + + if version_parts[-1].startswith("rc"): + rc_part = version_parts.pop() + rc_part = rc_part.split('rc')[1] + + # RC versions are weighted down to allow future RCs and general + # releases to be sorted in ascending order (e.g., 2.6.0-rc1, + # 2.6.0-rc2, 2.6.0). + version_parts.append(int(rc_part) + RC_OFFSET) + else: + # Non-RC releases have an extra 0 appended so version tuples like + # (2, 6, 0, -100) and (2, 6, 0, 0) sort in ascending order. + version_parts.append(0) + + return tuple(map(int, version_parts)) + class MultiVersionDownloader : def __init__(self, install_dir, link_dir, platform): @@ -25,7 +47,13 @@ class MultiVersionDownloader : match = re.compile("(.*)\/(.*)").match(platform) self.platform = match.group(1) self.arch = match.group(2) - self.links = self.download_links() + self._links = None + + @property + def links(self): + if self._links is None: + self._links = self.download_links() + return self._links def download_links(self): href = "http://dl.mongodb.org/dl/%s/%s" \ @@ -70,7 +98,7 @@ class MultiVersionDownloader : raise Exception("Cannot find a link for version %s, versions %s found." \ % (version, self.links)) - urls.sort() + urls.sort(key=version_tuple) full_version = urls[-1][0] url = urls[-1][1] extract_dir = url.split("/")[-1][:-4] |