~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugin.py

  • Committer: Martin
  • Date: 2011-04-15 21:22:57 UTC
  • mto: This revision was merged to the branch mainline in revision 5797.
  • Revision ID: gzlist@googlemail.com-20110415212257-jgtovwwp4be7egd9
Add release notes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
36
36
from bzrlib import osutils
37
37
 
38
38
from bzrlib.lazy_import import lazy_import
39
 
 
40
39
lazy_import(globals(), """
41
40
import imp
42
41
import re
52
51
from bzrlib import plugins as _mod_plugins
53
52
""")
54
53
 
55
 
from bzrlib.symbol_versioning import (
56
 
    deprecated_function,
57
 
    deprecated_in,
58
 
    )
59
 
 
60
54
 
61
55
DEFAULT_PLUGIN_PATH = None
62
56
_loaded = False
63
57
_plugins_disabled = False
64
58
 
65
59
 
 
60
plugin_warnings = {}
 
61
# Map from plugin name, to list of string warnings about eg plugin
 
62
# dependencies.
 
63
 
 
64
 
66
65
def are_plugins_disabled():
67
66
    return _plugins_disabled
68
67
 
77
76
    load_plugins([])
78
77
 
79
78
 
 
79
def describe_plugins(show_paths=False):
 
80
    """Generate text description of plugins.
 
81
 
 
82
    Includes both those that have loaded, and those that failed to 
 
83
    load.
 
84
 
 
85
    :param show_paths: If true,
 
86
    :returns: Iterator of text lines (including newlines.)
 
87
    """
 
88
    from inspect import getdoc
 
89
    loaded_plugins = plugins()
 
90
    all_names = sorted(list(set(
 
91
        loaded_plugins.keys() + plugin_warnings.keys())))
 
92
    for name in all_names:
 
93
        if name in loaded_plugins:
 
94
            plugin = loaded_plugins[name]
 
95
            version = plugin.__version__
 
96
            if version == 'unknown':
 
97
                version = ''
 
98
            yield '%s %s\n' % (name, version)
 
99
            d = getdoc(plugin.module)
 
100
            if d:
 
101
                doc = d.split('\n')[0]
 
102
            else:
 
103
                doc = '(no description)'
 
104
            yield ("  %s\n" % doc)
 
105
            if show_paths:
 
106
                yield ("   %s\n" % plugin.path())
 
107
            del plugin
 
108
        else:
 
109
            yield "%s (failed to load)\n" % name
 
110
        if name in plugin_warnings:
 
111
            for line in plugin_warnings[name]:
 
112
                yield "  ** " + line + '\n'
 
113
        yield '\n'
 
114
 
 
115
 
80
116
def _strip_trailing_sep(path):
81
117
    return path.rstrip("\\/")
82
118
 
327
363
    return None, None, (None, None, None)
328
364
 
329
365
 
 
366
def record_plugin_warning(plugin_name, warning_message):
 
367
    trace.mutter(warning_message)
 
368
    plugin_warnings.setdefault(plugin_name, []).append(warning_message)
 
369
 
 
370
 
330
371
def _load_plugin_module(name, dir):
331
372
    """Load plugin name from dir.
332
373
 
340
381
    except KeyboardInterrupt:
341
382
        raise
342
383
    except errors.IncompatibleAPI, e:
343
 
        trace.warning("Unable to load plugin %r. It requested API version "
 
384
        warning_message = (
 
385
            "Unable to load plugin %r. It requested API version "
344
386
            "%s of module %s but the minimum exported version is %s, and "
345
387
            "the maximum is %s" %
346
388
            (name, e.wanted, e.api, e.minimum, e.current))
 
389
        record_plugin_warning(name, warning_message)
347
390
    except Exception, e:
348
391
        trace.warning("%s" % e)
349
392
        if re.search('\.|-| ', name):
354
397
                    "file path isn't a valid module name; try renaming "
355
398
                    "it to %r." % (name, dir, sanitised_name))
356
399
        else:
357
 
            trace.warning('Unable to load plugin %r from %r' % (name, dir))
 
400
            record_plugin_warning(
 
401
                name,
 
402
                'Unable to load plugin %r from %r' % (name, dir))
358
403
        trace.log_exception_quietly()
359
404
        if 'error' in debug.debug_flags:
360
405
            trace.print_exception(sys.exc_info(), sys.stderr)
400
445
    return result
401
446
 
402
447
 
 
448
def format_concise_plugin_list():
 
449
    """Return a string holding a concise list of plugins and their version.
 
450
    """
 
451
    items = []
 
452
    for name, a_plugin in sorted(plugins().items()):
 
453
        items.append("%s[%s]" %
 
454
            (name, a_plugin.__version__))
 
455
    return ', '.join(items)
 
456
 
 
457
 
 
458
 
403
459
class PluginsHelpIndex(object):
404
460
    """A help index that returns help topics for plugins."""
405
461