/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: Jelmer Vernooij
  • Date: 2010-03-21 21:39:33 UTC
  • mfrom: (5102 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5143.
  • Revision ID: jelmer@samba.org-20100321213933-fexeh9zcoz8oaju2
merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005, 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2005-2010 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
60
60
 
61
61
DEFAULT_PLUGIN_PATH = None
62
62
_loaded = False
63
 
 
64
 
@deprecated_function(deprecated_in((2, 0, 0)))
65
 
def get_default_plugin_path():
66
 
    """Get the DEFAULT_PLUGIN_PATH"""
67
 
    global DEFAULT_PLUGIN_PATH
68
 
    if DEFAULT_PLUGIN_PATH is None:
69
 
        DEFAULT_PLUGIN_PATH = osutils.pathjoin(config.config_dir(), 'plugins')
70
 
    return DEFAULT_PLUGIN_PATH
 
63
_plugins_disabled = False
 
64
 
 
65
 
 
66
def are_plugins_disabled():
 
67
    return _plugins_disabled
71
68
 
72
69
 
73
70
def disable_plugins():
75
72
 
76
73
    Future calls to load_plugins() will be ignored.
77
74
    """
 
75
    global _plugins_disabled
 
76
    _plugins_disabled = True
78
77
    load_plugins([])
79
78
 
80
79
 
92
91
    if path is None:
93
92
        path = get_standard_plugins_path()
94
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
95
100
    return path
96
101
 
97
102
 
180
185
    paths = []
181
186
    for p in env_paths + defaults:
182
187
        if p.startswith('+'):
183
 
            # Resolve reference if they are known
 
188
            # Resolve references if they are known
184
189
            try:
185
190
                p = refs[p[1:]]
186
191
            except KeyError:
187
 
                # Leave them untouched otherwise, user may have paths starting
188
 
                # with '+'...
 
192
                # Leave them untouched so user can still use paths starting
 
193
                # with '+'
189
194
                pass
190
195
        _append_new_path(paths, p)
191
196
 
203
208
    files (and whatever other extensions are used in the platform,
204
209
    such as *.pyd).
205
210
 
206
 
    load_from_dirs() provides the underlying mechanism and is called with
 
211
    load_from_path() provides the underlying mechanism and is called with
207
212
    the default directory list to provide the normal behaviour.
208
213
 
209
214
    :param path: The list of paths to search for plugins.  By default,
291
296
            plugin_names.add(f)
292
297
 
293
298
    for name in plugin_names:
 
299
        if ('bzrlib.plugins.%s' % name) in PluginBlackListImporter.blacklist:
 
300
            continue
294
301
        try:
295
302
            exec "import bzrlib.plugins.%s" % name in {}
296
303
        except KeyboardInterrupt:
477
484
        return version_string
478
485
 
479
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