~abentley/bzrtools/bzrtools.dev

568 by Aaron Bentley
Don't check version when running non-bzrtools commands
1
import bzrlib
2
from bzrlib import commands
586 by Aaron Bentley
Fix ImportReplacer glitch when bzrtools is out of date
3
from bzrlib import option
568 by Aaron Bentley
Don't check version when running non-bzrtools commands
4
5
from version import *
6
7
8
class BzrToolsCommand(commands.Command):
9
10
    def run_argv_aliases(self, argv, alias_argv=None):
11
        result = check_bzrlib_version(version_info[:2])
12
        if result is not None:
13
            return result
14
        commands.Command.run_argv_aliases(self, argv, alias_argv)
15
16
17
def check_bzrlib_version(desired):
18
    """Check that bzrlib is compatible.
19
20
    If version is < bzrtools version, assume incompatible.
21
    If version == bzrtools version, assume completely compatible
22
    If version == bzrtools version + 1, assume compatible, with deprecations
23
    Otherwise, assume incompatible.
24
    """
25
    desired_plus = (desired[0], desired[1]+1)
26
    bzrlib_version = bzrlib.version_info[:2]
27
    if bzrlib_version == desired or (bzrlib_version == desired_plus and
28
                                     bzrlib.version_info[3] == 'dev'):
29
        return
586 by Aaron Bentley
Fix ImportReplacer glitch when bzrtools is out of date
30
    # force ImportReplacer to be evaluated
31
    commands.option._verbosity_level
568 by Aaron Bentley
Don't check version when running non-bzrtools commands
32
    try:
33
        from bzrlib.trace import warning
34
    except ImportError:
35
        # get the message out any way we can
36
        from warnings import warn as warning
37
    if bzrlib_version < desired:
38
        warning('Installed Bazaar version %s is too old to be used with'
39
                ' plugin \n'
40
                '"Bzrtools" %s.' % (
41
                bzrlib.__version__, '%s.%s.%s' % version_info))
42
        # Not using BzrNewError, because it may not exist.
43
        return 3
44
    else:
45
        warning('Plugin "Bzrtools" is not up to date with installed Bazaar'
46
                ' version %s.\n'
47
                'There should be a newer version of Bzrtools available, e.g.'
48
                ' %i.%i.'
49
                % (bzrlib.__version__, bzrlib_version[0], bzrlib_version[1]))
50
        if bzrlib_version != desired_plus:
51
            return 3