42
42
from bzrlib import (
46
from bzrlib import plugins as _mod_plugins
49
from bzrlib.symbol_versioning import deprecated_function, zero_ninetyone
49
50
from bzrlib.trace import mutter, warning, log_exception_quietly
60
61
return DEFAULT_PLUGIN_PATH
64
@deprecated_function(zero_ninetyone)
64
66
"""Return a dictionary of the plugins."""
66
for name, plugin in plugins.__dict__.items():
67
if isinstance(plugin, types.ModuleType):
67
return dict((name, plugin.module) for name, plugin in plugins().items())
72
70
def disable_plugins():
90
88
# it tries to import modules.
91
89
path = map(_strip_trailing_sep, path)
92
90
# search the plugin path before the bzrlib installed dir
93
path.append(os.path.dirname(plugins.__file__))
94
plugins.__path__ = path
91
path.append(os.path.dirname(_mod_plugins.__file__))
92
_mod_plugins.__path__ = path
133
131
# this function, and since it sets plugins.__path__, it should set it to
134
132
# something that will be valid for Python to use (in case people try to
135
133
# run "import bzrlib.plugins.PLUGINNAME" after calling this function).
136
plugins.__path__ = map(_strip_trailing_sep, dirs)
134
_mod_plugins.__path__ = map(_strip_trailing_sep, dirs)
182
if getattr(plugins, f, None):
180
if getattr(_mod_plugins, f, None):
183
181
mutter('Plugin name %s already loaded', f)
185
183
# mutter('add plugin name %s', f)
264
262
if not plugin_name:
266
if getattr(plugins, plugin_name, None):
264
if getattr(_mod_plugins, plugin_name, None):
267
265
mutter('Plugin name %s already loaded', plugin_name)
279
277
log_exception_quietly()
281
"""Return a dictionary of the plugins.
283
Each item in the dictionary is a PlugIn object.
286
for name, plugin in _mod_plugins.__dict__.items():
287
if isinstance(plugin, types.ModuleType):
288
result[name] = PlugIn(name, plugin)
282
292
class PluginsHelpIndex(object):
283
293
"""A help index that returns help topics for plugins."""
345
355
def get_help_topic(self):
346
356
"""Return the modules help topic - its __name__ after bzrlib.plugins.."""
347
357
return self.module.__name__[len('bzrlib.plugins.'):]
360
class PlugIn(object):
361
"""The bzrlib representation of a plugin.
363
The PlugIn object provides a way to manipulate a given plugin module.
366
def __init__(self, name, module):
367
"""Construct a plugin for module."""
372
"""Get the path that this plugin was loaded from."""
373
if getattr(self.module, '__path__', None) is not None:
374
return os.path.abspath(self.module.__path__[0])
375
elif getattr(self.module, '__file__', None) is not None:
376
return os.path.abspath(self.module.__file__)
378
return repr(self.module)
381
return "<%s.%s object at %s, name=%s, module=%s>" % (
382
self.__class__.__module__, self.__class__.__name__, id(self),
383
self.name, self.module)
387
def test_suite(self):
388
"""Return the plugin's test suite."""
389
if getattr(self.module, 'test_suite', None) is not None:
390
return self.module.test_suite()
394
def version_info(self):
395
"""Return the plugin's version_tuple or None if unknown."""
396
version_info = getattr(self.module, 'version_info', None)
397
if version_info is not None and len(version_info) == 3:
398
version_info = tuple(version_info) + ('final', 0)
401
def _get__version__(self):
402
version_info = self.version_info()
403
if version_info is None:
405
if version_info[3] == 'final':
406
version_string = '%d.%d.%d' % version_info[:3]
408
version_string = '%d.%d.%d%s%d' % version_info
409
return version_string
411
__version__ = property(_get__version__)