46
46
from bzrlib import plugins as _mod_plugins
49
from bzrlib.symbol_versioning import deprecated_function, zero_ninetyone
49
from bzrlib.symbol_versioning import deprecated_function, one_three
50
50
from bzrlib.trace import mutter, warning, log_exception_quietly
57
57
"""Get the DEFAULT_PLUGIN_PATH"""
58
58
global DEFAULT_PLUGIN_PATH
59
59
if DEFAULT_PLUGIN_PATH is None:
60
path = [osutils.pathjoin(config.config_dir(), 'plugins')]
61
if getattr(sys, 'frozen', None): # bzr.exe
62
# We need to use relative path to system-wide plugin
63
# directory because bzrlib from standalone bzr.exe
64
# could be imported by another standalone program
65
# (e.g. bzr-config; or TortoiseBzr/Olive if/when they
66
# will become standalone exe). [bialix 20071123]
67
# __file__ typically is
68
# C:\Program Files\Bazaar\lib\library.zip\bzrlib\plugin.pyc
69
# then plugins directory is
70
# C:\Program Files\Bazaar\plugins
71
# so relative path is ../../../plugins
72
path.append(osutils.abspath(osutils.pathjoin(
73
osutils.dirname(__file__), '../../../plugins')))
74
DEFAULT_PLUGIN_PATH = os.pathsep.join(path)
60
DEFAULT_PLUGIN_PATH = osutils.pathjoin(config.config_dir(), 'plugins')
75
61
return DEFAULT_PLUGIN_PATH
78
@deprecated_function(zero_ninetyone)
80
"""Return a dictionary of the plugins."""
81
return dict((name, plugin.module) for name, plugin in plugins().items())
84
64
def disable_plugins():
85
65
"""Disable loading plugins.
100
80
"""Set the path for plugins to be loaded from."""
101
81
path = os.environ.get('BZR_PLUGIN_PATH',
102
82
get_default_plugin_path()).split(os.pathsep)
83
bzr_exe = bool(getattr(sys, 'frozen', None))
84
if bzr_exe: # expand path for bzr.exe
85
# We need to use relative path to system-wide plugin
86
# directory because bzrlib from standalone bzr.exe
87
# could be imported by another standalone program
88
# (e.g. bzr-config; or TortoiseBzr/Olive if/when they
89
# will become standalone exe). [bialix 20071123]
90
# __file__ typically is
91
# C:\Program Files\Bazaar\lib\library.zip\bzrlib\plugin.pyc
92
# then plugins directory is
93
# C:\Program Files\Bazaar\plugins
94
# so relative path is ../../../plugins
95
path.append(osutils.abspath(osutils.pathjoin(
96
osutils.dirname(__file__), '../../../plugins')))
103
97
# Get rid of trailing slashes, since Python can't handle them when
104
98
# it tries to import modules.
105
99
path = map(_strip_trailing_sep, path)
106
# search the plugin path before the bzrlib installed dir
107
path.append(os.path.dirname(_mod_plugins.__file__))
100
if not bzr_exe: # don't look inside library.zip
101
# search the plugin path before the bzrlib installed dir
102
path.append(os.path.dirname(_mod_plugins.__file__))
108
103
_mod_plugins.__path__ = path
207
199
## import pdb; pdb.set_trace()
208
200
if re.search('\.|-| ', name):
209
201
sanitised_name = re.sub('[-. ]', '_', name)
210
warning("Unable to load %r in %r as a plugin because file path"
211
" isn't a valid module name; try renaming it to %r."
212
% (name, d, sanitised_name))
202
if sanitised_name.startswith('bzr_'):
203
sanitised_name = sanitised_name[len('bzr_'):]
204
warning("Unable to load %r in %r as a plugin because the "
205
"file path isn't a valid module name; try renaming "
206
"it to %r." % (name, d, sanitised_name))
214
208
warning('Unable to load plugin %r from %r' % (name, d))
215
209
log_exception_quietly()
212
@deprecated_function(one_three)
218
213
def load_from_zip(zip_name):
219
214
"""Load all the plugins in a zip."""
220
215
valid_suffixes = ('.py', '.pyc', '.pyo') # only python modules/packages
224
218
index = zip_name.rindex('.zip')
225
219
except ValueError:
390
384
if getattr(self.module, '__path__', None) is not None:
391
385
return os.path.abspath(self.module.__path__[0])
392
386
elif getattr(self.module, '__file__', None) is not None:
393
return os.path.abspath(self.module.__file__)
387
path = os.path.abspath(self.module.__file__)
388
if path[-4:] in ('.pyc', '.pyo'):
389
pypath = path[:-4] + '.py'
390
if os.path.isfile(pypath):
395
394
return repr(self.module)