~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugin.py

  • Committer: Jelmer Vernooij
  • Date: 2010-04-30 11:03:59 UTC
  • mto: This revision was merged to the branch mainline in revision 5197.
  • Revision ID: jelmer@samba.org-20100430110359-ow3e3grh7sxy93pa
Remove more unused imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
303
303
 
304
304
 
305
305
def _load_plugin_module(name, dir):
306
 
    """Load plugin name from dir.
 
306
    """Load plugine name from dir.
307
307
 
308
308
    :param name: The plugin name in the bzrlib.plugins namespace.
309
309
    :param dir: The directory the plugin is loaded from for error messages.
560
560
    def load_module(self, fullname):
561
561
        """Load a plugin from a specific directory."""
562
562
        # We are called only for specific paths
563
 
        plugin_path = self.specific_paths[fullname]
564
 
        loading_path = None
565
 
        package = False
566
 
        if os.path.isdir(plugin_path):
567
 
            for suffix, mode, kind in imp.get_suffixes():
568
 
                if kind not in (imp.PY_SOURCE, imp.PY_COMPILED):
569
 
                    # We don't recognize compiled modules (.so, .dll, etc)
570
 
                    continue
571
 
                init_path = osutils.pathjoin(plugin_path, '__init__' + suffix)
572
 
                if os.path.isfile(init_path):
573
 
                    loading_path = init_path
574
 
                    package = True
575
 
                    break
576
 
        else:
577
 
            for suffix, mode, kind in imp.get_suffixes():
578
 
                if plugin_path.endswith(suffix):
579
 
                    loading_path = plugin_path
580
 
                    break
581
 
        if loading_path is None:
 
563
        plugin_dir = self.specific_paths[fullname]
 
564
        candidate = None
 
565
        maybe_package = False
 
566
        for p in os.listdir(plugin_dir):
 
567
            if os.path.isdir(osutils.pathjoin(plugin_dir, p)):
 
568
                # We're searching for files only and don't want submodules to
 
569
                # be recognized as plugins (they are submodules inside the
 
570
                # plugin).
 
571
                continue
 
572
            name, path, (
 
573
                suffix, mode, kind) = _find_plugin_module(plugin_dir, p)
 
574
            if name is not None:
 
575
                candidate = (name, path, suffix, mode, kind)
 
576
                if kind == imp.PY_SOURCE:
 
577
                    # We favour imp.PY_SOURCE (which will use the compiled
 
578
                    # version if available) over imp.PY_COMPILED (which is used
 
579
                    # only if the source is not available)
 
580
                    break
 
581
        if candidate is None:
582
582
            raise ImportError('%s cannot be loaded from %s'
583
 
                              % (fullname, plugin_path))
584
 
        f = open(loading_path, mode)
 
583
                              % (fullname, plugin_dir))
 
584
        f = open(path, mode)
585
585
        try:
586
 
            mod = imp.load_module(fullname, f, loading_path,
587
 
                                  (suffix, mode, kind))
588
 
            if package:
589
 
                # The plugin can contain modules, so be ready
590
 
                mod.__path__ = [plugin_path]
 
586
            mod = imp.load_module(fullname, f, path, (suffix, mode, kind))
 
587
            # The plugin can contain modules, so be ready
 
588
            mod.__path__ = [plugin_dir]
591
589
            mod.__package__ = fullname
592
590
            return mod
593
591
        finally: