1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 """Utilities for handling compatibility with multiple versions."""
20
21 __all__ = ['status', 'BazaarCommandVersion']
22
23
27
29 class_name = self.__class__.__name__
30 return '%s.status.%s' % (__name__, self.__name)
31
34
37
39 return self is not rhs
40
41
43
45 raise AssertionError('Tried to instanciate enum class')
46
47
48 OK = _Enum('OK')
49
50
51 BAZ_TOO_NEW = _Enum('BAZ_TOO_NEW')
52
53
54 UNSUPPORTED = _Enum('UNSUPPORTED')
55
56
57
58 COTM = _Enum('COTM')
59
60
78
79
80
82
83 """Parsing and comparison of Bazaar version strings."""
84
86 """Parse a Bazaar version string.
87
88 :param version_line: line of the form
89 ``'baz Bazaar version MAJOR.MINOR[.POINT][[-]~COTM]'``
90 :type version_line: str
91 """
92 self._version_line = version_line
93 vstr, vtuple, cotm = self._parse(version_line)
94 self._string = vstr
95 self._release_tuple = vtuple
96 self._cotm = cotm
97
99 class_name = self.__class__.__name__
100 return '%s.%s(%r)' % (__name__, class_name, self._version_line)
101
103 """Actual version string parsing method.
104
105 Extracted as a static method for unit testing.
106 """
107 words = line.split(' ')
108 assert words[:3] == ['baz', 'Bazaar', 'version']
109 full_version_str = words[3]
110 version_cotm = full_version_str.split('~')
111 if len(version_cotm) == 1:
112 version_str = version_cotm[0]
113 cotm = None
114 elif len(version_cotm) == 2:
115 version_str, cotm = version_cotm
116 cotm = long(cotm)
117 else:
118 raise AssertionError('Version string seems to have multiple'
119 ' COTM qualifiers: ' + full_version_str)
120 version_str = version_str.rstrip('-')
121 version = map(int, version_str.split('.'))
122 if len(version) == 2:
123 version.append(0)
124 else:
125 assert len(version) == 3
126 return full_version_str, tuple(version), cotm
127
128 _parse = staticmethod(_parse)
129
132
133 string = property(_get_string, doc="""
134 Unparsed version string, without the "baz Bazaar version" prefix.
135 Use this attribute in user-visible messages.
136 """)
137
139 return self._release_tuple
140
141 release = property(_get_release, doc="""
142 Tuple of integers representing the Bazaar release version.""")
143
146
147 cotm = property(_get_cotm, doc="""
148 Long integer identifying the Crack Of The Minute build.
149 None if the version is a release.
150 """)
151
152 _end_of_times = (10 ** (4 + 2 + 2 + 2 + 2)) - 1
153
161
163 if not isinstance(rhs, BazaarCommandVersion):
164 msg = 'Tried to compare BazaarCommandVersion with %r' % rhs
165 raise TypeError(msg)
166 a = self._comparable()
167 b = rhs._comparable()
168 return cmp(a, b)
169