Programmatically determining the Bazaar plugin directory
Is there a way to determine the Bazaar directory programmatically? If there is a bazaar comma开发者_运维百科nd to determine the plugin directory, this would be the best solution.
Bazaar plugins are searched for in the following directories:
* <pythonlib>/site-packages/bzrlib/plugins/
(where <pythonlib> is something like usr/lib/python2.4,
depending on your installation)
* $HOME/.bazaar/plugins/
You can set the bazaar plugins directory via BZR_PLUGIN_PATH
environement variable, also.
More on bazaar plugins: http://bazaar-vcs.org/BzrPlugins
According to the bazaar website,
user plugins are looked for in ~/.bazaar/plugins
by default, but may be overridden by the environment variable BZR_PLUGIN_PATH
.
So test if this variable is set, otherwise return the default. In python:
import os
user_plugin_path = os.environ.get('BZR_PLUGIN_PATH', '~/.bazaar/plugins')
Edit: this works for unix based systems, for windows the uses plugin path is $APPDATA/bazaar/2.0/plugins
.
The system wide plugin is in bzrlib/plugins
, see Installing a plugin down the page here. Use distutils
to get the prefix (e.g. /usr/lib/python2.4/site-packages/bzrlib/plugins/) :
from distutils.sysconfig import get_python_lib
global_plugin_path = os.path.join(get_python_lib(), 'bzrlib/plugins')
(Thanks to The MYYN for providing the other documentation page)
Have a look at the Bazaar configuration:
output of bzr version
. Also see function show_version
in bzrlib/version.py
.
For the configuration directory use:
from bzrlib import config
print config.config_dir()
Or, for the user plugin path (see bzrlib/plugin.py
):
from bzrlib import plugin
print plugin.get_user_plugin_path()
For a full list of plugin paths:
from bzrlib import plugin
print plugin.get_standard_plugins_path()
If you have bzr installed in your system you can use following Python snippet to get the list of directories where bzr looking for plugins:
>>> import os
>>> from bzrlib import plugin
>>> list_of_bzr_plugins_paths = [os.path.abspath(p)
for p in plugin.get_standard_plugins_path()]
精彩评论