~ubuntu-branches/ubuntu/trusty/bzrtools/trusty

« back to all changes in this revision

Viewing changes to command.py

  • Committer: Package Import Robot
  • Author(s): Jelmer Vernooij
  • Date: 2012-04-13 12:06:17 UTC
  • mfrom: (659.15.18) (0.22.16 sid)
  • Revision ID: package-import@ubuntu.com-20120413120617-qa3qms2fybl2jivc
Tags: 2.5+bzr786-2
* Use rsvg-convert rather than rsvg. Closes: #666472, LP: #971190
* Disable version check to allow use with bzr 2.6.
* Remove Arnaud Fontaine and Gustavo Franco from uploaders.
* Fix Vcs-Bzr URL.
* Add 03_testing: fix test suite run with newer versions of bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
18
 
19
 
import bzrlib
20
 
from bzrlib import commands
21
 
 
22
 
from version import version_info, __version__
23
 
 
24
 
 
25
 
_testing = False
26
 
# True if we are currently testing commands via the test suite.
27
 
 
28
 
def _stop_testing():
29
 
    """Set the _testing flag to indicate we are no longer testing."""
30
 
    global _testing
31
 
    _testing = False
32
 
 
33
 
 
34
 
class BzrToolsCommand(commands.Command):
35
 
 
36
 
    def run_argv_aliases(self, argv, alias_argv=None):
37
 
        result = check_bzrlib_version(version_info[:2])
38
 
        if result is not None:
39
 
            return result
40
 
        commands.Command.run_argv_aliases(self, argv, alias_argv)
41
 
 
42
 
 
43
 
TOO_OLD = 'too_old'
44
 
COMPATIBLE = 'compatible'
45
 
MAYBE_TOO_NEW = 'maybe_too_new'
46
 
TOO_NEW = 'too_new'
47
 
 
48
 
 
49
 
def check_version_compatibility(bzrlib_version, min_version, max_version):
50
 
    """Check whether a bzrlib version is compatible with desired version.
51
 
 
52
 
    If the bzrlib_version is not less than min_version and not greater than
53
 
    max_version, it is considered COMPATIBLE.  If the version exceeds
54
 
    max_version by 1 and is not a 'candidate' or 'final' version, it is
55
 
    considered MAYBE_TOO_NEW.  Other values greater than max_version are
56
 
    considered TOO_NEW, and values lower than min_version are considered
57
 
    TOO_OLD.
58
 
    """
59
 
    bzrlib_version = bzrlib.version_info[:2]
60
 
    if bzrlib_version < min_version:
61
 
        return TOO_OLD
62
 
    if bzrlib_version <= max_version:
63
 
        return COMPATIBLE
64
 
    max_plus = (max_version[0], max_version[1] + 1)
65
 
    if bzrlib_version == max_plus:
66
 
        if bzrlib.version_info[3] not in ('final', 'candidate'):
67
 
            return COMPATIBLE
68
 
        return MAYBE_TOO_NEW
69
 
    return TOO_NEW
70
 
 
71
 
 
72
 
def check_bzrlib_version(desired):
73
 
    """Check that bzrlib is compatible.
74
 
 
75
 
    If version is < bzrtools version, assume incompatible.
76
 
    If version == bzrtools version, assume completely compatible
77
 
    If version == bzrtools version + 1, assume compatible, with deprecations
78
 
    Otherwise, assume incompatible.
79
 
    """
80
 
    global _testing
81
 
    if _testing:
82
 
        return
83
 
    compatibility = check_version_compatibility(bzrlib.version_info, desired,
84
 
                                                desired)
85
 
    if compatibility == COMPATIBLE:
86
 
        return
87
 
    try:
88
 
        from bzrlib.trace import warning
89
 
    except ImportError:
90
 
        # get the message out any way we can
91
 
        from warnings import warn as warning
92
 
    if compatibility == TOO_OLD:
93
 
        warning('Bazaar version %s is too old to be used with'
94
 
                ' plugin "Bzrtools" %s.' % (
95
 
                bzrlib.__version__, __version__))
96
 
        # Not using BzrNewError, because it may not exist.
97
 
        return 3
98
 
    else:
99
 
        warning('Plugin "Bzrtools" is not up to date with installed Bazaar'
100
 
                ' version %s.\n'
101
 
                'There should be a newer version of Bzrtools available, e.g.'
102
 
                ' %i.%i.'
103
 
                % (bzrlib.__version__, bzrlib.version_info[0],
104
 
                   bzrlib.version_info[1]))
105
 
        if compatibility == TOO_NEW:
106
 
            return 3
 
19
from bzrlib.commands import Command as BzrToolsCommand