~bzr/ubuntu/maverick/bzrtools/beta-ppa

« back to all changes in this revision

Viewing changes to command.py

  • Committer: Max Bowsher
  • Date: 2011-05-15 07:34:33 UTC
  • mfrom: (703.1.2 natty)
  • Revision ID: maxb@f2s.com-20110515073433-1jwljzxl3l0rrbs3
Tags: 2.4.0~bzr767-2~bazaar1~maverick1
MergeĀ 2.4.0~bzr767-2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007, 2009, 2010, 2011 Aaron Bentley.
 
2
# Copyright (C) 2009 Max Bowsher.
 
3
#
 
4
#    This program is free software; you can redistribute it and/or modify
 
5
#    it under the terms of the GNU General Public License as published by
 
6
#    the Free Software Foundation; either version 2 of the License, or
 
7
#    (at your option) any later version.
 
8
#
 
9
#    This program is distributed in the hope that it will be useful,
 
10
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
#    GNU General Public License for more details.
 
13
#
 
14
#    You should have received a copy of the GNU General Public License
 
15
#    along with this program; if not, write to the Free Software
 
16
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
 
 
18
 
1
19
import bzrlib
2
20
from bzrlib import commands
3
21
 
22
40
        commands.Command.run_argv_aliases(self, argv, alias_argv)
23
41
 
24
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
 
25
72
def check_bzrlib_version(desired):
26
73
    """Check that bzrlib is compatible.
27
74
 
33
80
    global _testing
34
81
    if _testing:
35
82
        return
36
 
    desired_plus = (desired[0], desired[1]+1)
37
 
    bzrlib_version = bzrlib.version_info[:2]
38
 
    if bzrlib_version == desired or (bzrlib_version == desired_plus and
39
 
                                     bzrlib.version_info[3] == 'dev'):
 
83
    compatibility = check_version_compatibility(bzrlib.version_info, desired,
 
84
                                                desired)
 
85
    if compatibility == COMPATIBLE:
40
86
        return
41
87
    try:
42
88
        from bzrlib.trace import warning
43
89
    except ImportError:
44
90
        # get the message out any way we can
45
91
        from warnings import warn as warning
46
 
    if bzrlib_version < desired:
47
 
        warning('Installed Bazaar version %s is too old to be used with'
48
 
                ' plugin \n'
49
 
                '"Bzrtools" %s.' % (
 
92
    if compatibility == TOO_OLD:
 
93
        warning('Bazaar version %s is too old to be used with'
 
94
                ' plugin "Bzrtools" %s.' % (
50
95
                bzrlib.__version__, __version__))
51
96
        # Not using BzrNewError, because it may not exist.
52
97
        return 3
55
100
                ' version %s.\n'
56
101
                'There should be a newer version of Bzrtools available, e.g.'
57
102
                ' %i.%i.'
58
 
                % (bzrlib.__version__, bzrlib_version[0], bzrlib_version[1]))
59
 
        if bzrlib_version != desired_plus:
 
103
                % (bzrlib.__version__, bzrlib.version_info[0],
 
104
                   bzrlib.version_info[1]))
 
105
        if compatibility == TOO_NEW:
60
106
            return 3