~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to command.py

  • Committer: Aaron Bentley
  • Date: 2011-04-15 01:10:13 UTC
  • mto: This revision was merged to the branch mainline in revision 760.
  • Revision ID: aaron@aaronbentley.com-20110415011013-vxxgatx2kh4j0qtz
refactor version-checking code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
        commands.Command.run_argv_aliases(self, argv, alias_argv)
41
41
 
42
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, desired):
 
50
    bzrlib_version = bzrlib.version_info[:2]
 
51
    desired_plus = (desired[0], desired[1]+1)
 
52
    if bzrlib_version == desired:
 
53
        return COMPATIBLE
 
54
    if (bzrlib_version == desired_plus and
 
55
        bzrlib.version_info[3] not in ('final', 'candidate')):
 
56
        return COMPATIBLE
 
57
    if bzrlib_version < desired:
 
58
        return TOO_OLD
 
59
    elif bzrlib_version == desired_plus:
 
60
        return MAYBE_TOO_NEW
 
61
    else:
 
62
        return TOO_NEW
 
63
 
 
64
 
43
65
def check_bzrlib_version(desired):
44
66
    """Check that bzrlib is compatible.
45
67
 
51
73
    global _testing
52
74
    if _testing:
53
75
        return
54
 
    desired_plus = (desired[0], desired[1]+1)
55
 
    bzrlib_version = bzrlib.version_info[:2]
56
 
    if bzrlib_version == desired:
57
 
        return
58
 
    if (bzrlib_version == desired_plus and
59
 
        bzrlib.version_info[3] not in ('final', 'candidate')):
 
76
    compatibility = check_version_compatibility(bzrlib.version_info, desired)
 
77
    if compatibility == COMPATIBLE:
60
78
        return
61
79
    try:
62
80
        from bzrlib.trace import warning
63
81
    except ImportError:
64
82
        # get the message out any way we can
65
83
        from warnings import warn as warning
66
 
    if bzrlib_version < desired:
67
 
        warning('Installed Bazaar version %s is too old to be used with'
68
 
                ' plugin \n'
69
 
                '"Bzrtools" %s.' % (
 
84
    if compatibility == TOO_OLD:
 
85
        warning('Bazaar version %s is too old to be used with'
 
86
                ' plugin "Bzrtools" %s.' % (
70
87
                bzrlib.__version__, __version__))
71
88
        # Not using BzrNewError, because it may not exist.
72
89
        return 3
75
92
                ' version %s.\n'
76
93
                'There should be a newer version of Bzrtools available, e.g.'
77
94
                ' %i.%i.'
78
 
                % (bzrlib.__version__, bzrlib_version[0], bzrlib_version[1]))
79
 
        if bzrlib_version != desired_plus:
 
95
                % (bzrlib.__version__, bzrlib.version_info[0],
 
96
                   bzrlib.version_info[1]))
 
97
        if compatibility == TOO_NEW:
80
98
            return 3