~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugin.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-11-03 21:16:53 UTC
  • mfrom: (3777.6.7 bzr.plugins)
  • Revision ID: pqm@pqm.ubuntu.com-20081103211653-vyode1g8p1lfsuzy
(Marius Kruger) Give a reasonable version string for plugins with
        invalid version_info values.

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
import zipfile
45
45
 
46
46
from bzrlib import (
 
47
    _format_version_tuple,
47
48
    config,
48
49
    debug,
49
50
    errors,
455
456
    def version_info(self):
456
457
        """Return the plugin's version_tuple or None if unknown."""
457
458
        version_info = getattr(self.module, 'version_info', None)
458
 
        if version_info is not None and len(version_info) == 3:
459
 
            version_info = tuple(version_info) + ('final', 0)
 
459
        if version_info is not None:
 
460
            try:
 
461
                if isinstance(version_info, types.StringType):
 
462
                    version_info = version_info.split('.')
 
463
                elif len(version_info) == 3:
 
464
                    version_info = tuple(version_info) + ('final', 0)
 
465
            except TypeError, e:
 
466
                # The given version_info isn't even iteratible
 
467
                trace.log_exception_quietly()
 
468
                version_info = (version_info,)
460
469
        return version_info
461
470
 
462
471
    def _get__version__(self):
463
472
        version_info = self.version_info()
464
 
        if version_info is None:
 
473
        if version_info is None or len(version_info) == 0:
465
474
            return "unknown"
466
 
        if version_info[3] == 'final':
467
 
            version_string = '%d.%d.%d' % version_info[:3]
468
 
        else:
469
 
            version_string = '%d.%d.%d%s%d' % version_info
 
475
        try:
 
476
            version_string = _format_version_tuple(version_info)
 
477
        except (ValueError, TypeError, IndexError), e:
 
478
            trace.log_exception_quietly()
 
479
            # try to return something usefull for bad plugins, in stead of
 
480
            # stack tracing.
 
481
            version_string = '.'.join(map(str, version_info))
470
482
        return version_string
471
483
 
472
484
    __version__ = property(_get__version__)