| 27 | |
| 28 | |
| 29 | class Version(object): |
| 30 | def __init__(self, major, minor, bugfix, prerelease): |
| 31 | self.major = major |
| 32 | self.minor = minor |
| 33 | self.bugfix = bugfix |
| 34 | self.prerelease = prerelease |
| 35 | self.previous_dot_matcher = self.make_previous_matcher() |
| 36 | self.dot = '%d.%d.%d' % (self.major, self.minor, self.bugfix) |
| 37 | self.constant = 'LUCENE_%d_%d_%d' % (self.major, self.minor, self.bugfix) |
| 38 | |
| 39 | @classmethod |
| 40 | def parse(cls, value): |
| 41 | match = re.search(r'(\d+)\.(\d+).(\d+)(.1|.2)?', value) |
| 42 | if match is None: |
| 43 | raise argparse.ArgumentTypeError('Version argument must be of format x.y.z(.1|.2)?') |
| 44 | parts = [int(v) for v in match.groups()[:-1]] |
| 45 | parts.append({ None: 0, '.1': 1, '.2': 2 }[match.groups()[-1]]) |
| 46 | return Version(*parts) |
| 47 | |
| 48 | def __str__(self): |
| 49 | return self.dot |
| 50 | |
| 51 | def make_previous_matcher(self, prefix='', suffix='', sep='\\.'): |
| 52 | if self.is_bugfix_release(): |
| 53 | pattern = '%s%s%s%s%d' % (self.major, sep, self.minor, sep, self.bugfix - 1) |
| 54 | elif self.is_minor_release(): |
| 55 | pattern = '%s%s%d%s\\d+' % (self.major, sep, self.minor - 1, sep) |
| 56 | else: |
| 57 | pattern = '%d%s\\d+%s\\d+' % (self.major - 1, sep, sep) |
| 58 | |
| 59 | return re.compile(prefix + '(' + pattern + ')' + suffix) |
| 60 | |
| 61 | def is_bugfix_release(self): |
| 62 | return self.bugfix != 0 |
| 63 | |
| 64 | def is_minor_release(self): |
| 65 | return self.bugfix == 0 and self.minor != 0 |
| 66 | |
| 67 | def is_major_release(self): |
| 68 | return self.bugfix == 0 and self.minor == 0 |
| 69 | |
| 70 | def on_or_after(self, other): |
| 71 | return (self.major > other.major or self.major == other.major and |
| 72 | (self.minor > other.minor or self.minor == other.minor and |
| 73 | (self.bugfix > other.bugfix or self.bugfix == other.bugfix and |
| 74 | self.prerelease >= other.prerelease))) |
| 75 | |
| 76 | def gt(self, other): |
| 77 | return (self.major > other.major or |
| 78 | (self.major == other.major and self.minor > other.minor) or |
| 79 | (self.major == other.major and self.minor == other.minor and self.bugfix > other.bugfix)) |
| 80 | |
| 81 | def is_back_compat_with(self, other): |
| 82 | if not self.on_or_after(other): |
| 83 | raise Exception('Back compat check disallowed for newer version: %s < %s' % (self, other)) |
| 84 | return other.major + 1 >= self.major |
| 85 | |
| 86 |
no outgoing calls
no test coverage detected
searching dependent graphs…