~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/api.py

  • Committer: Andrew Bennetts
  • Date: 2008-07-03 07:56:02 UTC
  • mto: This revision was merged to the branch mainline in revision 3520.
  • Revision ID: andrew.bennetts@canonical.com-20080703075602-8n055qsfkjijcz6i
Better tests for {pre,post}_change_branch_tip hooks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2008, 2009, 2011 Canonical Ltd
 
1
# Copyright (C) 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Library API versioning support.
18
18
 
22
22
"""
23
23
 
24
24
import bzrlib
 
25
from bzrlib.lazy_import import lazy_import
 
26
lazy_import(globals(), """
25
27
from bzrlib.errors import IncompatibleAPI
 
28
""")
26
29
 
27
30
 
28
31
def get_current_api_version(object_with_api):
67
70
        version. See get_minimum_api_version and get_current_api_version for
68
71
        details.
69
72
    :param wanted_api: The API version for which support is required.
70
 
    :return: None
 
73
    :return None:
71
74
    :raises IncompatibleAPI: When the wanted_api is not supported by
72
75
        object_with_api.
73
76
 
77
80
    minimum = get_minimum_api_version(object_with_api)
78
81
    if wanted_api < minimum or wanted_api > current:
79
82
        raise IncompatibleAPI(object_with_api, wanted_api, minimum, current)
80
 
 
81
 
 
82
 
def require_any_api(object_with_api, wanted_api_list):
83
 
    """Check if object_with_api supports the api version wanted_api.
84
 
 
85
 
    :param object_with_api: An object which exports an API minimum and current
86
 
        version. See get_minimum_api_version and get_current_api_version for
87
 
        details.
88
 
    :param wanted_api: A list of API versions, any of which being available is
89
 
        sufficent.
90
 
    :return: None
91
 
    :raises IncompatibleAPI: When the wanted_api is not supported by
92
 
        object_with_api.
93
 
 
94
 
    Added in bzrlib 1.9.
95
 
    """
96
 
    for api in wanted_api_list[:-1]:
97
 
        try:
98
 
            return require_api(object_with_api, api)
99
 
        except IncompatibleAPI:
100
 
            pass
101
 
    require_api(object_with_api, wanted_api_list[-1])