|
9 | 9 |
|
10 | 10 | import contextlib
|
11 | 11 | import datetime
|
| 12 | +from functools import total_ordering |
12 | 13 | import glob
|
13 | 14 | import imp
|
14 | 15 | import json
|
|
28 | 29 | except:
|
29 | 30 | pass
|
30 | 31 |
|
| 32 | +SEMANTIC_VERSION_PATTERN = r'^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$' |
| 33 | + |
31 | 34 |
|
32 | 35 | # To eliminate clashing with older archived builds on bleeding edge we add
|
33 | 36 | # a base number bigger the largest svn revision (this also gives us an easy
|
@@ -120,16 +123,88 @@ def GetMinidumpUtils(repo_path=DART_DIR):
|
120 | 123 | os.path.join(repo_path, 'tools', 'minidump.py'))
|
121 | 124 |
|
122 | 125 |
|
| 126 | +@total_ordering |
123 | 127 | class Version(object):
|
124 | 128 |
|
125 |
| - def __init__(self, channel, major, minor, patch, prerelease, |
126 |
| - prerelease_patch): |
| 129 | + def __init__(self, |
| 130 | + channel=None, |
| 131 | + major=None, |
| 132 | + minor=None, |
| 133 | + patch=None, |
| 134 | + prerelease=None, |
| 135 | + prerelease_patch=None, |
| 136 | + version=None): |
127 | 137 | self.channel = channel
|
128 | 138 | self.major = major
|
129 | 139 | self.minor = minor
|
130 | 140 | self.patch = patch
|
131 | 141 | self.prerelease = prerelease
|
132 | 142 | self.prerelease_patch = prerelease_patch
|
| 143 | + if version: |
| 144 | + self.set_version(version) |
| 145 | + |
| 146 | + def set_version(self, version): |
| 147 | + match = re.match(SEMANTIC_VERSION_PATTERN, version) |
| 148 | + assert match, '%s must be a valid version' % version |
| 149 | + self.channel = 'stable' |
| 150 | + self.major = match['major'] |
| 151 | + self.minor = match['minor'] |
| 152 | + self.patch = match['patch'] |
| 153 | + self.prerelease = '0' |
| 154 | + self.prerelease_patch = '0' |
| 155 | + if match['prerelease']: |
| 156 | + subversions = match['prerelease'].split('.') |
| 157 | + self.prerelease = subversions[0] |
| 158 | + self.prerelease_patch = subversions[1] |
| 159 | + self.channel = subversions[2] |
| 160 | + |
| 161 | + def __str__(self): |
| 162 | + result = '%s.%s.%s' % (self.major, self.minor, self.patch) |
| 163 | + if self.channel != 'stable': |
| 164 | + result += '-%s.%s.%s' % (self.prerelease, self.prerelease_patch, |
| 165 | + self.channel) |
| 166 | + return result |
| 167 | + |
| 168 | + def __eq__(self, other): |
| 169 | + return self.channel == other.channel and \ |
| 170 | + self.major == other.major and \ |
| 171 | + self.minor == other.minor and \ |
| 172 | + self.patch == other.patch and \ |
| 173 | + self.prerelease == other.prerelease and \ |
| 174 | + self.prerelease_patch == other.prerelease_patch |
| 175 | + |
| 176 | + def __lt__(self, other): |
| 177 | + if int(self.major) < int(other.major): |
| 178 | + return True |
| 179 | + if int(self.major) > int(other.major): |
| 180 | + return False |
| 181 | + if int(self.minor) < int(other.minor): |
| 182 | + return True |
| 183 | + if int(self.minor) > int(other.minor): |
| 184 | + return False |
| 185 | + if int(self.patch) < int(other.patch): |
| 186 | + return True |
| 187 | + if int(self.patch) > int(other.patch): |
| 188 | + return False |
| 189 | + # The stable channel is ahead of the other channels on the same triplet. |
| 190 | + if self.channel != 'stable' and other.channel == 'stable': |
| 191 | + return True |
| 192 | + if self.channel == 'stable' and other.channel != 'stable': |
| 193 | + return False |
| 194 | + # The be channel is ahead of the other channels on the same triplet. |
| 195 | + if self.channel != 'be' and other.channel == 'be': |
| 196 | + return True |
| 197 | + if self.channel == 'be' and other.channel != 'be': |
| 198 | + return False |
| 199 | + if int(self.prerelease_patch) < int(other.prerelease_patch): |
| 200 | + return True |
| 201 | + if int(self.prerelease_patch) > int(other.prerelease_patch): |
| 202 | + return False |
| 203 | + if int(self.prerelease) < int(other.prerelease): |
| 204 | + return True |
| 205 | + if int(self.prerelease) > int(other.prerelease): |
| 206 | + return False |
| 207 | + return False |
133 | 208 |
|
134 | 209 |
|
135 | 210 | # Try to guess the host operating system.
|
|
0 commit comments