2 def __init__(self
, ver
, debian
=False):
4 # remove epoch and debian part
6 ver
= ver
.split(':', 1)[1]
8 ver
= ver
.split('-', 1)[0]
11 def __cmp__(self
, other
):
12 if other
is None or other
.ver
is None:
16 if other
.ver
== self
.ver
:
19 nb1
= map(int, self
.ver
.split('.'))
20 nb2
= map(int, other
.ver
.split('.'))
22 for i
, j
in zip(nb1
, nb2
):
28 if len(nb1
) < len(nb2
):
30 elif len(nb1
) > len(nb2
):
38 if __name__
== '__main__':
39 assert Version('1.0') < Version('2.0')
40 assert Version('1.0') < Version('2.0')
41 assert Version('1.0') != Version('2.0')
42 assert Version('1.0') == Version('1.0')
43 assert Version('1.1.0') < Version('2.0')
44 assert Version('1.1.2') < Version('1.1.3')
45 assert Version('1.3') < Version('1.3.1')
46 assert max(Version('1.0'), Version('1.5'), Version('1.5.2')) == Version('1.5.2')
47 assert max(Version('0.7.9'), Version('0.7.18')) == Version('0.7.18')
48 assert Version(None) < Version('1.3.1')
49 assert Version('1.4.1-3', debian
=True) == Version('1.4.1')