~abentley/bzrtools/bzrtools.dev

731 by Aaron Bentley
Update version number to 2.1b1
1
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
2
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Aaron Bentley
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
18
19
def _format_version_tuple(version_info):
20
    """Turn a version number 2, 3 or 5-tuple into a short string.
21
22
    This format matches <http://docs.python.org/dist/meta-data.html>
23
    and the typical presentation used in Python output.
24
25
    This also checks that the version is reasonable: the sub-release must be
26
    zero for final releases.
27
28
    >>> print _format_version_tuple((1, 0, 0, 'final', 0))
29
    1.0.0
30
    >>> print _format_version_tuple((1, 2, 0, 'dev', 0))
31
    1.2.0dev
32
    >>> print bzrlib._format_version_tuple((1, 2, 0, 'dev', 1))
33
    1.2.0dev1
34
    >>> print _format_version_tuple((1, 1, 1, 'candidate', 2))
35
    1.1.1rc2
36
    >>> print bzrlib._format_version_tuple((2, 1, 0, 'beta', 1))
37
    2.1.0b1
38
    >>> print _format_version_tuple((1, 4, 0))
39
    1.4.0
40
    >>> print _format_version_tuple((1, 4))
41
    1.4
42
    >>> print bzrlib._format_version_tuple((2, 1, 0, 'final', 1))
43
    Traceback (most recent call last):
44
    ...
45
    ValueError: version_info (2, 1, 0, 'final', 1) not valid
46
    >>> print _format_version_tuple((1, 4, 0, 'wibble', 0))
47
    Traceback (most recent call last):
48
    ...
49
    ValueError: version_info (1, 4, 0, 'wibble', 0) not valid
50
    """
51
    if len(version_info) == 2:
52
        main_version = '%d.%d' % version_info[:2]
53
    else:
54
        main_version = '%d.%d.%d' % version_info[:3]
55
    if len(version_info) <= 3:
56
        return main_version
57
58
    release_type = version_info[3]
59
    sub = version_info[4]
60
61
    # check they're consistent
62
    if release_type == 'final' and sub == 0:
63
        sub_string = ''
64
    elif release_type == 'dev' and sub == 0:
65
        sub_string = 'dev'
66
    elif release_type == 'dev':
67
        sub_string = 'dev' + str(sub)
68
    elif release_type in ('alpha', 'beta'):
69
        sub_string = release_type[0] + str(sub)
70
    elif release_type == 'candidate':
71
        sub_string = 'rc' + str(sub)
72
    else:
73
        raise ValueError("version_info %r not valid" % (version_info,))
74
75
    return main_version + sub_string
76
77
787 by Aaron Bentley
Fix zap command for 2.6/7
78
version_info = (2, 6, 0)
731 by Aaron Bentley
Update version number to 2.1b1
79
__version__ = _format_version_tuple(version_info)