/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/plugin.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-03-19 12:44:48 UTC
  • mfrom: (5100.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20100319124448-8xooaqwyiwqhrq49
(vila) Allow plugins to be disabled via BZR_DISABLE_PLUGINS

Show diffs side-by-side

added added

removed removed

Lines of Context:
91
91
    if path is None:
92
92
        path = get_standard_plugins_path()
93
93
    _mod_plugins.__path__ = path
 
94
    # Set up a blacklist for disabled plugins if any
 
95
    PluginBlackListImporter.blacklist = {}
 
96
    disabled_plugins = os.environ.get('BZR_DISABLE_PLUGINS', None)
 
97
    if disabled_plugins is not None:
 
98
        for name in disabled_plugins.split(os.pathsep):
 
99
            PluginBlackListImporter.blacklist['bzrlib.plugins.' + name] = True
94
100
    return path
95
101
 
96
102
 
183
189
            try:
184
190
                p = refs[p[1:]]
185
191
            except KeyError:
186
 
                # Leave them untouched otherwise, user may have paths starting
187
 
                # with '+'...
 
192
                # Leave them untouched so user can still use paths starting
 
193
                # with '+'
188
194
                pass
189
195
        _append_new_path(paths, p)
190
196
 
202
208
    files (and whatever other extensions are used in the platform,
203
209
    such as *.pyd).
204
210
 
205
 
    load_from_dirs() provides the underlying mechanism and is called with
 
211
    load_from_path() provides the underlying mechanism and is called with
206
212
    the default directory list to provide the normal behaviour.
207
213
 
208
214
    :param path: The list of paths to search for plugins.  By default,
290
296
            plugin_names.add(f)
291
297
 
292
298
    for name in plugin_names:
 
299
        if ('bzrlib.plugins.%s' % name) in PluginBlackListImporter.blacklist:
 
300
            continue
293
301
        try:
294
302
            exec "import bzrlib.plugins.%s" % name in {}
295
303
        except KeyboardInterrupt:
476
484
        return version_string
477
485
 
478
486
    __version__ = property(_get__version__)
 
487
 
 
488
 
 
489
class _PluginBlackListImporter(object):
 
490
 
 
491
    def __init__(self):
 
492
        self.blacklist = {}
 
493
 
 
494
    def find_module(self, fullname, parent_path=None):
 
495
        if fullname in self.blacklist:
 
496
            raise ImportError('%s is disabled' % fullname)
 
497
        return None
 
498
 
 
499
PluginBlackListImporter = _PluginBlackListImporter()
 
500
sys.meta_path.append(PluginBlackListImporter)
 
501
 
 
502