~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugin.py

  • Committer: Andrew Bennetts
  • Date: 2008-02-18 08:30:38 UTC
  • mto: This revision was merged to the branch mainline in revision 3756.
  • Revision ID: andrew.bennetts@canonical.com-20080218083038-tts55zsx5xrz3l2e
Lots of assorted hackery to reduce the number of imports for common operations.  Improves 'rocks', 'st' and 'help' times by ~50ms on my laptop.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
from bzrlib import (
43
43
    config,
44
44
    osutils,
 
45
    trace,
45
46
    )
46
47
from bzrlib import plugins as _mod_plugins
47
48
""")
48
49
 
49
50
from bzrlib.symbol_versioning import deprecated_function, zero_ninetyone
50
 
from bzrlib.trace import mutter, warning, log_exception_quietly
51
51
 
52
52
 
53
53
DEFAULT_PLUGIN_PATH = None
151
151
    for d in dirs:
152
152
        if not d:
153
153
            continue
154
 
        mutter('looking for plugins in %s', d)
 
154
        trace.mutter('looking for plugins in %s', d)
155
155
        if os.path.isdir(d):
156
156
            load_from_dir(d)
157
157
        else:
193
193
            else:
194
194
                continue
195
195
        if getattr(_mod_plugins, f, None):
196
 
            mutter('Plugin name %s already loaded', f)
 
196
            trace.mutter('Plugin name %s already loaded', f)
197
197
        else:
198
 
            # mutter('add plugin name %s', f)
 
198
            # trace.mutter('add plugin name %s', f)
199
199
            plugin_names.add(f)
200
200
    
201
201
    for name in plugin_names:
207
207
            ## import pdb; pdb.set_trace()
208
208
            if re.search('\.|-| ', name):
209
209
                sanitised_name = re.sub('[-. ]', '_', name)
210
 
                warning("Unable to load %r in %r as a plugin because file path"
 
210
                trace.warning("Unable to load %r in %r as a plugin because file path"
211
211
                        " isn't a valid module name; try renaming it to %r."
212
212
                        % (name, d, sanitised_name))
213
213
            else:
214
 
                warning('Unable to load plugin %r from %r' % (name, d))
215
 
            log_exception_quietly()
 
214
                trace.warning('Unable to load plugin %r from %r' % (name, d))
 
215
            trace.log_exception_quietly()
216
216
 
217
217
 
218
218
def load_from_zip(zip_name):
227
227
    archive = zip_name[:index+4]
228
228
    prefix = zip_name[index+5:]
229
229
 
230
 
    mutter('Looking for plugins in %r', zip_name)
 
230
    trace.mutter('Looking for plugins in %r', zip_name)
231
231
 
232
232
    # use zipfile to get list of files/dirs inside zip
233
233
    try:
247
247
                    for name in namelist
248
248
                    if name.startswith(prefix)]
249
249
 
250
 
    mutter('Names in archive: %r', namelist)
 
250
    trace.mutter('Names in archive: %r', namelist)
251
251
    
252
252
    for name in namelist:
253
253
        if not name or name.endswith('/'):
279
279
        if not plugin_name:
280
280
            continue
281
281
        if getattr(_mod_plugins, plugin_name, None):
282
 
            mutter('Plugin name %s already loaded', plugin_name)
 
282
            trace.mutter('Plugin name %s already loaded', plugin_name)
283
283
            continue
284
284
    
285
285
        try:
286
286
            exec "import bzrlib.plugins.%s" % plugin_name in {}
287
 
            mutter('Load plugin %s from zip %r', plugin_name, zip_name)
 
287
            trace.mutter('Load plugin %s from zip %r', plugin_name, zip_name)
288
288
        except KeyboardInterrupt:
289
289
            raise
290
290
        except Exception, e:
291
291
            ## import pdb; pdb.set_trace()
292
 
            warning('Unable to load plugin %r from %r'
 
292
            trace.warning('Unable to load plugin %r from %r'
293
293
                    % (name, zip_name))
294
 
            log_exception_quietly()
 
294
            trace.log_exception_quietly()
295
295
 
296
296
 
297
297
def plugins():