detecting version match/mismatch between core/plugins
Aaron Bentley
aaron.bentley at utoronto.ca
Tue Aug 15 15:11:59 BST 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Wichmann, Mats D wrote:
>>>It would be easy enough to have a version number in the plugin and
>>>fail to load it if it's too low or high, it would just
>>>require someone to write the code :)
>>
>>I think its up to the plugin to do that... keeps them more like regular
>>python files.
>
>
> Haven't followed up to last few comments, but I
> think I agree that it's the plugin that needs to
> have most of the "smarts".
Here's what I'm considering adding to bzrtools:
import bzrlib
__version__ = '0.9'
def check_bzrlib_version(desired_str):
"""Check that bzrlib is compatible.
If version is < bzrtools version, assume incompatible.
If version == bzrtools version, assume completely compatible
If version == bzrtools version + 1, assume compatible, with deprecations
Otherwise, assume incompatible.
"""
desired = tuple([int(num) for num in desired_str.split('.')])
desired_plus = (desired[0], desired[1]+1)
bzrlib_version = [int(num) for num in bzrlib.__version__.split('.')[:2]]
bzrlib_version = tuple(bzrlib_version)
if bzrlib_version == desired:
return
try:
from bzrlib.trace import warning
except ImportError:
# get the message out any way we can
from warnings import warn as warning
if bzrlib_version < desired:
warning('Installed bzr version %s is too old to be used with
bzrtools'
' %s.' % (bzrlib.__version__, __version__))
# Not using BzrNewError, because it may not exist.
raise Exception, 'Version mismatch'
else:
warning('Bzrtools is not up to date with installed bzr version'
' %s. Please upgrade to bzrtools %i.%i.'
% (bzrlib.__version__, bzrlib_version[0],
bzrlib_version[1]))
if bzrlib_version != desired_plus:
raise Exception, 'Version mismatch'
check_bzrlib_version(__version__)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFE4dYv0F+nu1YWqI0RAuVCAJ42F1y8A4Vv8qZq9O9jVg+2Mvr3EACeNfuQ
p3FiiAyuqRPuM08lRrZ4jRI=
=TXgQ
-----END PGP SIGNATURE-----
More information about the bazaar
mailing list