~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugin.py

  • Committer: John Arbash Meinel
  • Date: 2006-08-14 16:16:53 UTC
  • mto: (1946.2.6 reduce-knit-churn)
  • mto: This revision was merged to the branch mainline in revision 1919.
  • Revision ID: john@arbash-meinel.com-20060814161653-54cdcdadcd4e9003
Remove bogus entry from BRANCH.TODO

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005 Canonical Ltd
 
1
# Copyright (C) 2004, 2005 by Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
39
39
# That could be either a separate Python interpreter or perhaps a new
40
40
# namespace inside this interpreter.
41
41
 
 
42
import imp
42
43
import os
43
44
import sys
44
 
 
45
 
from bzrlib.lazy_import import lazy_import
46
 
lazy_import(globals(), """
47
 
import imp
48
45
import types
49
46
 
50
 
from bzrlib import (
51
 
    config,
52
 
    osutils,
53
 
    plugins,
54
 
    )
55
 
""")
56
 
 
57
 
from bzrlib.trace import mutter, warning, log_exception_quietly
58
 
 
59
 
 
60
 
DEFAULT_PLUGIN_PATH = None
61
 
 
62
 
 
63
 
def get_default_plugin_path():
64
 
    """Get the DEFAULT_PLUGIN_PATH"""
65
 
    global DEFAULT_PLUGIN_PATH
66
 
    if DEFAULT_PLUGIN_PATH is None:
67
 
        DEFAULT_PLUGIN_PATH = osutils.pathjoin(config.config_dir(), 'plugins')
68
 
    return DEFAULT_PLUGIN_PATH
69
 
 
 
47
import bzrlib
 
48
from bzrlib.config import config_dir
 
49
from bzrlib.trace import log_error, mutter, warning, \
 
50
        log_exception_quietly
 
51
from bzrlib.errors import BzrError
 
52
from bzrlib import plugins
 
53
from bzrlib.osutils import pathjoin
 
54
 
 
55
DEFAULT_PLUGIN_PATH = pathjoin(config_dir(), 'plugins')
70
56
 
71
57
_loaded = False
72
58
 
74
60
def all_plugins():
75
61
    """Return a dictionary of the plugins."""
76
62
    result = {}
77
 
    for name, plugin in plugins.__dict__.items():
 
63
    for name, plugin in bzrlib.plugins.__dict__.items():
78
64
        if isinstance(plugin, types.ModuleType):
79
65
            result[name] = plugin
80
66
    return result
106
92
    if _loaded:
107
93
        # People can make sure plugins are loaded, they just won't be twice
108
94
        return
 
95
        #raise BzrError("plugins already initialized")
109
96
    _loaded = True
110
97
 
111
 
    dirs = os.environ.get('BZR_PLUGIN_PATH',
112
 
                          get_default_plugin_path()).split(os.pathsep)
 
98
    dirs = os.environ.get('BZR_PLUGIN_PATH', DEFAULT_PLUGIN_PATH).split(os.pathsep)
113
99
    dirs.insert(0, os.path.dirname(plugins.__file__))
114
100
 
115
101
    load_from_dirs(dirs)
139
125
        if not os.path.isdir(d):
140
126
            continue
141
127
        for f in os.listdir(d):
142
 
            path = osutils.pathjoin(d, f)
 
128
            path = pathjoin(d, f)
143
129
            if os.path.isdir(path):
144
130
                for entry in package_entries:
145
131
                    # This directory should be a package, and thus added to
146
132
                    # the list
147
 
                    if os.path.isfile(osutils.pathjoin(path, entry)):
 
133
                    if os.path.isfile(pathjoin(path, entry)):
148
134
                        break
149
135
                else: # This directory is not a package
150
136
                    continue
157
143
                        break
158
144
                else:
159
145
                    continue
160
 
            if getattr(plugins, f, None):
 
146
            if getattr(bzrlib.plugins, f, None):
161
147
                mutter('Plugin name %s already loaded', f)
162
148
            else:
163
149
                mutter('add plugin name %s', f)
172
158
                try:
173
159
                    plugin = imp.load_module('bzrlib.plugins.' + name,
174
160
                                             *plugin_info)
175
 
                    setattr(plugins, name, plugin)
 
161
                    setattr(bzrlib.plugins, name, plugin)
176
162
                finally:
177
163
                    if plugin_info[0] is not None:
178
164
                        plugin_info[0].close()