/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/plugin.py

  • Committer: Vincent Ladeuil
  • Date: 2011-07-06 09:22:00 UTC
  • mfrom: (6008 +trunk)
  • mto: (6012.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6013.
  • Revision ID: v.ladeuil+lp@free.fr-20110706092200-7iai2mwzc0sqdsvf
MergingĀ inĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
236
272
    """Load bzrlib plugins.
237
273
 
238
274
    The environment variable BZR_PLUGIN_PATH is considered a delimited
239
 
    set of paths to look through. Each entry is searched for *.py
 
275
    set of paths to look through. Each entry is searched for `*.py`
240
276
    files (and whatever other extensions are used in the platform,
241
 
    such as *.pyd).
 
277
    such as `*.pyd`).
242
278
 
243
279
    load_from_path() provides the underlying mechanism and is called with
244
280
    the default directory list to provide the normal behaviour.
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)