19
19
When load_plugins() is invoked, any python module in any directory in
20
20
$BRZ_PLUGIN_PATH will be imported. The module will be imported as
21
'brzlib.plugins.$BASENAME(PLUGIN)'. In the plugin's main body, it should
22
update any brzlib registries it wants to extend.
21
'breezy.plugins.$BASENAME(PLUGIN)'. In the plugin's main body, it should
22
update any breezy registries it wants to extend.
24
24
See the plugin-api developer documentation for information about writing
27
27
BRZ_PLUGIN_PATH is also honoured for any plugins imported via
28
'import brzlib.plugins.PLUGINNAME', as long as set_plugins_path has been
28
'import breezy.plugins.PLUGINNAME', as long as set_plugins_path has been
37
from brzlib import osutils
37
from breezy import osutils
39
from brzlib.lazy_import import lazy_import
39
from breezy.lazy_import import lazy_import
40
40
lazy_import(globals(), """
46
46
_format_version_tuple,
52
from brzlib.i18n import gettext
53
from brzlib import plugins as _mod_plugins
52
from breezy.i18n import gettext
53
from breezy import plugins as _mod_plugins
161
161
disabled_plugins = os.environ.get('BRZ_DISABLE_PLUGINS', None)
162
162
if disabled_plugins is not None:
163
163
for name in disabled_plugins.split(os.pathsep):
164
PluginImporter.blacklist.add('brzlib.plugins.' + name)
164
PluginImporter.blacklist.add('breezy.plugins.' + name)
165
165
# Set up a the specific paths for plugins
166
166
for plugin_name, plugin_path in _get_specific_plugin_paths(os.environ.get(
167
167
'BRZ_PLUGINS_AT', None)):
168
168
PluginImporter.specific_paths[
169
'brzlib.plugins.%s' % plugin_name] = plugin_path
169
'breezy.plugins.%s' % plugin_name] = plugin_path
182
182
bzr_exe = bool(getattr(sys, 'frozen', None))
183
183
if bzr_exe: # expand path for bzr.exe
184
184
# We need to use relative path to system-wide plugin
185
# directory because brzlib from standalone bzr.exe
185
# directory because breezy from standalone bzr.exe
186
186
# could be imported by another standalone program
187
187
# (e.g. bzr-config; or TortoiseBzr/Olive if/when they
188
188
# will become standalone exe). [bialix 20071123]
189
189
# __file__ typically is
190
# C:\Program Files\Bazaar\lib\library.zip\brzlib\plugin.pyc
190
# C:\Program Files\Bazaar\lib\library.zip\breezy\plugin.pyc
191
191
# then plugins directory is
192
192
# C:\Program Files\Bazaar\plugins
193
193
# so relative path is ../../../plugins
194
194
core_path = osutils.abspath(osutils.pathjoin(
195
195
osutils.dirname(__file__), '../../../plugins'))
196
196
else: # don't look inside library.zip
197
# search the plugin path before the brzlib installed dir
197
# search the plugin path before the breezy installed dir
198
198
core_path = os.path.dirname(_mod_plugins.__file__)
212
212
# If distutuils is not available, we just don't know where they are
215
site_path = osutils.pathjoin(get_python_lib(), 'brzlib', 'plugins')
215
site_path = osutils.pathjoin(get_python_lib(), 'breezy', 'plugins')
298
298
def load_from_path(dirs):
299
"""Load brzlib plugins found in each dir in dirs.
299
"""Load breezy plugins found in each dir in dirs.
301
301
Loading a plugin means importing it into the python interpreter.
302
302
The plugin is expected to make calls to register commands when
303
303
it's loaded (or perhaps access other hooks in future.)
305
Plugins are loaded into brzlib.plugins.NAME, and can be found there
305
Plugins are loaded into breezy.plugins.NAME, and can be found there
306
306
for future reference.
308
The python module path for brzlib.plugins will be modified to be 'dirs'.
308
The python module path for breezy.plugins will be modified to be 'dirs'.
310
310
# Explicitly load the plugins with a specific path
311
311
for fullname, path in PluginImporter.specific_paths.iteritems():
312
name = fullname[len('brzlib.plugins.'):]
312
name = fullname[len('breezy.plugins.'):]
313
313
_load_plugin_module(name, path)
315
315
# We need to strip the trailing separators here as well as in the
316
316
# set_plugins_path function because calling code can pass anything in to
317
317
# this function, and since it sets plugins.__path__, it should set it to
318
318
# something that will be valid for Python to use (in case people try to
319
# run "import brzlib.plugins.PLUGINNAME" after calling this function).
319
# run "import breezy.plugins.PLUGINNAME" after calling this function).
320
320
_mod_plugins.__path__ = map(_strip_trailing_sep, dirs)
373
373
def _load_plugin_module(name, dir):
374
374
"""Load plugin name from dir.
376
:param name: The plugin name in the brzlib.plugins namespace.
376
:param name: The plugin name in the breezy.plugins namespace.
377
377
:param dir: The directory the plugin is loaded from for error messages.
379
if ('brzlib.plugins.%s' % name) in PluginImporter.blacklist:
379
if ('breezy.plugins.%s' % name) in PluginImporter.blacklist:
382
exec "import brzlib.plugins.%s" % name in {}
382
exec "import breezy.plugins.%s" % name in {}
383
383
except KeyboardInterrupt:
385
385
except errors.IncompatibleAPI, e:
419
419
if name is not None:
420
420
if name == '__init__':
421
421
# We do nothing with the __init__.py file in directories from
422
# the brzlib.plugins module path, we may want to, one day
422
# the breezy.plugins module path, we may want to, one day
423
423
# -- vila 20100316.
424
424
continue # We don't load __init__.py in the plugins dirs
425
425
elif getattr(_mod_plugins, name, None) is not None:
478
478
if topic.startswith(self.prefix):
479
479
topic = topic[len(self.prefix):]
480
plugin_module_name = 'brzlib.plugins.%s' % topic
480
plugin_module_name = 'breezy.plugins.%s' % topic
482
482
module = sys.modules[plugin_module_name]
508
508
result = self.module.__doc__
509
509
if result[-1] != '\n':
511
from brzlib import help_topics
511
from breezy import help_topics
512
512
result += help_topics._format_see_also(additional_see_also)
515
515
def get_help_topic(self):
516
516
"""Return the module help topic: its basename."""
517
return self.module.__name__[len('brzlib.plugins.'):]
517
return self.module.__name__[len('breezy.plugins.'):]
520
520
class PlugIn(object):
521
"""The brzlib representation of a plugin.
521
"""The breezy representation of a plugin.
523
523
The PlugIn object provides a way to manipulate a given plugin module.
623
623
:return: None if the plugin doesn't need special handling, self
626
if not fullname.startswith('brzlib.plugins.'):
626
if not fullname.startswith('breezy.plugins.'):
628
628
if fullname in self.blacklist:
629
629
raise ImportError('%s is disabled' % fullname)