~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/api.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-08-17 18:13:57 UTC
  • mfrom: (5268.7.29 transport-segments)
  • Revision ID: pqm@pqm.ubuntu.com-20110817181357-y5q5eth1hk8bl3om
(jelmer) Allow specifying the colocated branch to use in the branch URL,
 and retrieving the branch name using ControlDir._get_selected_branch.
 (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
 
1
# Copyright (C) 2007, 2008, 2009, 2011 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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(), """
27
25
from bzrlib.errors import IncompatibleAPI
28
 
""")
29
26
 
30
27
 
31
28
def get_current_api_version(object_with_api):
70
67
        version. See get_minimum_api_version and get_current_api_version for
71
68
        details.
72
69
    :param wanted_api: The API version for which support is required.
73
 
    :return None:
 
70
    :return: None
74
71
    :raises IncompatibleAPI: When the wanted_api is not supported by
75
72
        object_with_api.
76
73
 
80
77
    minimum = get_minimum_api_version(object_with_api)
81
78
    if wanted_api < minimum or wanted_api > current:
82
79
        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])