1 |
bh |
2011 |
# Copyright (C) 2003 by Intevation GmbH |
2 |
|
|
# Authors: |
3 |
|
|
# Bernhard Herzog <[email protected]> |
4 |
|
|
# |
5 |
|
|
# This program is free software under the GPL (>=v2) |
6 |
|
|
# Read the file COPYING coming with the software for details. |
7 |
|
|
|
8 |
|
|
"""Version number handling""" |
9 |
|
|
|
10 |
|
|
__version__ = "$Revision$" |
11 |
|
|
# $Source$ |
12 |
|
|
# $Id$ |
13 |
|
|
|
14 |
|
|
|
15 |
|
|
import re |
16 |
|
|
|
17 |
|
|
rx_version = re.compile("[0-9]+(\\.[0-9]+)*") |
18 |
|
|
|
19 |
|
|
def make_tuple(s): |
20 |
|
|
"""Return a tuple version of the version number string s |
21 |
|
|
|
22 |
|
|
The version string must start with a sequence of decimal integers |
23 |
|
|
separated by dots. The return value is a tuple of up to three |
24 |
|
|
integers, one for each number at the beginnin of the version string. |
25 |
|
|
|
26 |
|
|
If the string does not start with a number return None |
27 |
|
|
|
28 |
|
|
Examples: |
29 |
|
|
>>> import version |
30 |
|
|
>>> version.make_tuple('1.2') |
31 |
|
|
(1, 2) |
32 |
|
|
>>> version.make_tuple('2.4.0.7') |
33 |
|
|
(2, 4, 0) |
34 |
|
|
>>> version.make_tuple('1.2+cvs.20031111') |
35 |
|
|
(1, 2) |
36 |
|
|
>>> version.make_tuple('foo') |
37 |
|
|
>>> |
38 |
|
|
""" |
39 |
|
|
match = rx_version.match(s) |
40 |
|
|
if match: |
41 |
|
|
return tuple(map(int, match.group(0).split(".")[:3])) |
42 |
|
|
|