/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2550.2.2 by Robert Collins
Add helpers to get api versions from objects.
1
# Copyright (C) 2007 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Library API versioning support."""
18
19
import bzrlib
20
from bzrlib.lazy_import import lazy_import
21
lazy_import(globals(), """
22
from bzrlib.errors import IncompatibleAPI
23
""")
24
25
26
def get_current_api_version(object_with_api):
27
    """Return the API version tuple for object_with_api.
28
29
    :param object_with_api: An object to look for an API version on. If the
30
        object has a api_current_version attribute, that is used. Otherwise if
31
        there is a version_info attribute, its first three elements are used.
32
        Finally if there was no version_info attribute, the current api version
33
        of bzrlib itself is used.
34
    """
35
    try:
36
        return object_with_api.api_current_version
37
    except AttributeError:
38
        try:
39
            return object_with_api.version_info[0:3]
40
        except AttributeError:
41
            return get_current_api_version(bzrlib)
42
43
44
def get_minimum_api_version(object_with_api):
45
    """Return the minimum API version supported by object_with_api.
46
47
    :param object_with_api: An object to look for an API version on. If the
48
        object has a api_minimum_version attribute, that is used. Otherwise the
49
        minimum api version of bzrlib itself is used.
50
    """
51
    try:
52
        return object_with_api.api_minimum_version
53
    except AttributeError:
54
        return get_minimum_api_version(bzrlib)