~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugin.py

  • Committer: Martin Pool
  • Date: 2005-06-24 04:48:14 UTC
  • Revision ID: mbp@sourcefrog.net-20050624044814-1db5090ffeaa95d9
- Patch from Torsten Marek to take commit messages through an 
  editor.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
# plugin_cmds variable.
24
24
 
25
25
 
26
 
import os
27
 
from bzrlib.osutils import config_dir
28
 
DEFAULT_PLUGIN_PATH = os.path.join(config_dir(), 'plugins')
 
26
DEFAULT_PLUGIN_PATH = '~/.bzr.conf/plugins'
29
27
 
30
28
all_plugins = []
31
 
_loaded = False
32
29
 
33
30
 
34
31
def load_plugins():
48
45
    such as *.pyd).
49
46
    """
50
47
 
51
 
    global all_plugins, _loaded
52
 
    if _loaded:
53
 
        # People can make sure plugins are loaded, they just won't be twice
54
 
        return
55
 
        #raise BzrError("plugins already initialized")
56
 
    _loaded = True
57
 
 
58
48
    import sys, os, imp
59
 
    
 
49
    try:
 
50
        set
 
51
    except NameError:
 
52
        from sets import Set as set         # python2.3
 
53
 
60
54
    from bzrlib.trace import log_error, mutter, log_exception
61
55
    from bzrlib.errors import BzrError
62
 
    from bzrlib import plugins
63
 
 
64
 
    dirs = os.environ.get('BZR_PLUGIN_PATH', DEFAULT_PLUGIN_PATH).split(":")
65
 
    dirs.insert(0, os.path.dirname(plugins.__file__))
 
56
 
 
57
    bzrpath = os.environ.get('BZR_PLUGIN_PATH')
 
58
    if not bzrpath:
 
59
        bzrpath = os.path.expanduser(DEFAULT_PLUGIN_PATH)
 
60
 
 
61
    global all_plugins
 
62
    if all_plugins:
 
63
        raise BzrError("plugins already initialized")
66
64
 
67
65
    # The problem with imp.get_suffixes() is that it doesn't include
68
66
    # .pyo which is technically valid
72
70
    suffixes = imp.get_suffixes()
73
71
    suffixes.append(('.pyo', 'rb', imp.PY_COMPILED))
74
72
    package_entries = ['__init__.py', '__init__.pyc', '__init__.pyo']
75
 
    for d in dirs:
 
73
    for d in bzrpath.split(os.pathsep):
76
74
        # going through them one by one allows different plugins with the same
77
75
        # filename in different directories in the path
78
76
        mutter('looking for plugins in %s' % d)
112
110
                try:
113
111
                    plugin = imp.load_module('bzrlib.plugin.' + name,
114
112
                                             *plugin_info)
115
 
                    all_plugins.append(plugin)
 
113
                    all_plugins.append(plugin_info)
116
114
                finally:
117
115
                    if plugin_info[0] is not None:
118
116
                        plugin_info[0].close()