/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/api.py

  • Committer: Robert Collins
  • Date: 2010-05-06 11:08:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506110810-h3j07fh5gmw54s25
Cleaner matcher matching revised unlocking protocol.

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
16
16
 
17
17
"""Library API versioning support.
18
18
 
19
 
Added in breezy 0.18 this allows export of compatibility information about
20
 
breezy. Please see doc/developers/api-versioning.txt for design details and
 
19
Added in bzrlib 0.18 this allows export of compatibility information about
 
20
bzrlib. Please see doc/developers/api-versioning.txt for design details and
21
21
examples.
22
22
"""
23
23
 
24
 
from __future__ import absolute_import
25
 
 
26
 
import breezy
27
 
from .errors import IncompatibleAPI
 
24
import bzrlib
 
25
from bzrlib.lazy_import import lazy_import
 
26
lazy_import(globals(), """
 
27
from bzrlib.errors import IncompatibleAPI
 
28
""")
28
29
 
29
30
 
30
31
def get_current_api_version(object_with_api):
34
35
        object has a api_current_version attribute, that is used. Otherwise if
35
36
        there is a version_info attribute, its first three elements are used.
36
37
        Finally if there was no version_info attribute, the current api version
37
 
        of breezy itself is used.
 
38
        of bzrlib itself is used.
38
39
 
39
 
    Added in breezy 0.18.
 
40
    Added in bzrlib 0.18.
40
41
    """
41
42
    try:
42
43
        return object_with_api.api_current_version
44
45
        try:
45
46
            return object_with_api.version_info[0:3]
46
47
        except AttributeError:
47
 
            return get_current_api_version(breezy)
 
48
            return get_current_api_version(bzrlib)
48
49
 
49
50
 
50
51
def get_minimum_api_version(object_with_api):
52
53
 
53
54
    :param object_with_api: An object to look for an API version on. If the
54
55
        object has a api_minimum_version attribute, that is used. Otherwise the
55
 
        minimum api version of breezy itself is used.
 
56
        minimum api version of bzrlib itself is used.
56
57
 
57
 
    Added in breezy 0.18.
 
58
    Added in bzrlib 0.18.
58
59
    """
59
60
    try:
60
61
        return object_with_api.api_minimum_version
61
62
    except AttributeError:
62
 
        return get_minimum_api_version(breezy)
 
63
        return get_minimum_api_version(bzrlib)
63
64
 
64
65
 
65
66
def require_api(object_with_api, wanted_api):
73
74
    :raises IncompatibleAPI: When the wanted_api is not supported by
74
75
        object_with_api.
75
76
 
76
 
    Added in breezy 0.18.
 
77
    Added in bzrlib 0.18.
77
78
    """
78
79
    current = get_current_api_version(object_with_api)
79
80
    minimum = get_minimum_api_version(object_with_api)
93
94
    :raises IncompatibleAPI: When the wanted_api is not supported by
94
95
        object_with_api.
95
96
 
96
 
    Added in breezy 1.9.
 
97
    Added in bzrlib 1.9.
97
98
    """
98
99
    for api in wanted_api_list[:-1]:
99
100
        try: