/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: Andrew Bennetts
  • Date: 2008-10-27 06:14:45 UTC
  • mfrom: (3793 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3795.
  • Revision ID: andrew.bennetts@canonical.com-20081027061445-eqt9lz6uw1mbvq4g
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
from bzrlib import (
44
44
    config,
45
45
    debug,
 
46
    errors,
46
47
    osutils,
47
48
    trace,
48
49
    )
50
51
""")
51
52
 
52
53
from bzrlib.symbol_versioning import deprecated_function, one_three
53
 
from bzrlib.trace import mutter, warning, log_exception_quietly
54
54
 
55
55
 
56
56
DEFAULT_PLUGIN_PATH = None
162
162
    for d in dirs:
163
163
        if not d:
164
164
            continue
165
 
        mutter('looking for plugins in %s', d)
 
165
        trace.mutter('looking for plugins in %s', d)
166
166
        if os.path.isdir(d):
167
167
            load_from_dir(d)
168
168
 
173
173
 
174
174
 
175
175
def load_from_dir(d):
176
 
    """Load the plugins in directory d."""
 
176
    """Load the plugins in directory d.
 
177
    
 
178
    d must be in the plugins module path already.
 
179
    """
177
180
    # Get the list of valid python suffixes for __init__.py?
178
181
    # this includes .py, .pyc, and .pyo (depending on if we are running -O)
179
182
    # but it doesn't include compiled modules (.so, .dll, etc)
201
204
            else:
202
205
                continue
203
206
        if getattr(_mod_plugins, f, None):
204
 
            mutter('Plugin name %s already loaded', f)
 
207
            trace.mutter('Plugin name %s already loaded', f)
205
208
        else:
206
 
            # mutter('add plugin name %s', f)
 
209
            # trace.mutter('add plugin name %s', f)
207
210
            plugin_names.add(f)
208
211
    
209
212
    for name in plugin_names:
211
214
            exec "import bzrlib.plugins.%s" % name in {}
212
215
        except KeyboardInterrupt:
213
216
            raise
 
217
        except errors.IncompatibleAPI, e:
 
218
            trace.warning("Unable to load plugin %r. It requested API version "
 
219
                "%s of module %s but the minimum exported version is %s, and "
 
220
                "the maximum is %s" %
 
221
                (name, e.wanted, e.api, e.minimum, e.current))
214
222
        except Exception, e:
 
223
            trace.warning("%s" % e)
215
224
            ## import pdb; pdb.set_trace()
216
225
            if re.search('\.|-| ', name):
217
226
                sanitised_name = re.sub('[-. ]', '_', name)
218
227
                if sanitised_name.startswith('bzr_'):
219
228
                    sanitised_name = sanitised_name[len('bzr_'):]
220
 
                warning("Unable to load %r in %r as a plugin because the "
 
229
                trace.warning("Unable to load %r in %r as a plugin because the "
221
230
                        "file path isn't a valid module name; try renaming "
222
231
                        "it to %r." % (name, d, sanitised_name))
223
232
            else:
224
 
                warning('Unable to load plugin %r from %r' % (name, d))
225
 
            log_exception_quietly()
 
233
                trace.warning('Unable to load plugin %r from %r' % (name, d))
 
234
            trace.log_exception_quietly()
226
235
            if 'error' in debug.debug_flags:
227
236
                trace.print_exception(sys.exc_info(), sys.stderr)
228
237
 
239
248
    archive = zip_name[:index+4]
240
249
    prefix = zip_name[index+5:]
241
250
 
242
 
    mutter('Looking for plugins in %r', zip_name)
 
251
    trace.mutter('Looking for plugins in %r', zip_name)
243
252
 
244
253
    # use zipfile to get list of files/dirs inside zip
245
254
    try:
259
268
                    for name in namelist
260
269
                    if name.startswith(prefix)]
261
270
 
262
 
    mutter('Names in archive: %r', namelist)
 
271
    trace.mutter('Names in archive: %r', namelist)
263
272
    
264
273
    for name in namelist:
265
274
        if not name or name.endswith('/'):
291
300
        if not plugin_name:
292
301
            continue
293
302
        if getattr(_mod_plugins, plugin_name, None):
294
 
            mutter('Plugin name %s already loaded', plugin_name)
 
303
            trace.mutter('Plugin name %s already loaded', plugin_name)
295
304
            continue
296
305
    
297
306
        try:
298
307
            exec "import bzrlib.plugins.%s" % plugin_name in {}
299
 
            mutter('Load plugin %s from zip %r', plugin_name, zip_name)
 
308
            trace.mutter('Load plugin %s from zip %r', plugin_name, zip_name)
300
309
        except KeyboardInterrupt:
301
310
            raise
302
311
        except Exception, e:
303
312
            ## import pdb; pdb.set_trace()
304
 
            warning('Unable to load plugin %r from %r'
 
313
            trace.warning('Unable to load plugin %r from %r'
305
314
                    % (name, zip_name))
306
 
            log_exception_quietly()
 
315
            trace.log_exception_quietly()
307
316
            if 'error' in debug.debug_flags:
308
317
                trace.print_exception(sys.exc_info(), sys.stderr)
309
318