/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: Martin Pool
  • Date: 2011-01-18 00:41:29 UTC
  • mto: This revision was merged to the branch mainline in revision 5630.
  • Revision ID: mbp@canonical.com-20110118004129-ujkx7azmh1uk7ftz
Put plugin warnings into both the apport and plain crash report

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
_plugins_disabled = False
64
64
 
65
65
 
 
66
plugin_warnings = {}
 
67
# Map from plugin name, to list of string warnings about eg plugin
 
68
# dependencies.
 
69
 
 
70
 
66
71
def are_plugins_disabled():
67
72
    return _plugins_disabled
68
73
 
81
86
    return path.rstrip("\\/")
82
87
 
83
88
 
 
89
def _get_specific_plugin_paths(paths):
 
90
    """Returns the plugin paths from a string describing the associations.
 
91
 
 
92
    :param paths: A string describing the paths associated with the plugins.
 
93
 
 
94
    :returns: A list of (plugin name, path) tuples.
 
95
 
 
96
    For example, if paths is my_plugin@/test/my-test:her_plugin@/production/her,
 
97
    [('my_plugin', '/test/my-test'), ('her_plugin', '/production/her')] 
 
98
    will be returned.
 
99
 
 
100
    Note that ':' in the example above depends on the os.
 
101
    """
 
102
    if not paths:
 
103
        return []
 
104
    specs = []
 
105
    for spec in paths.split(os.pathsep):
 
106
        try:
 
107
            name, path = spec.split('@')
 
108
        except ValueError:
 
109
            raise errors.BzrCommandError(
 
110
                '"%s" is not a valid <plugin_name>@<plugin_path> description '
 
111
                % spec)
 
112
        specs.append((name, path))
 
113
    return specs
 
114
 
 
115
 
84
116
def set_plugins_path(path=None):
85
117
    """Set the path for plugins to be loaded from.
86
118
 
98
130
        for name in disabled_plugins.split(os.pathsep):
99
131
            PluginImporter.blacklist.add('bzrlib.plugins.' + name)
100
132
    # Set up a the specific paths for plugins
101
 
    specific_plugins = os.environ.get('BZR_PLUGINS_AT', None)
102
 
    if specific_plugins is not None:
103
 
        for spec in specific_plugins.split(os.pathsep):
104
 
            plugin_name, plugin_path = spec.split('@')
 
133
    for plugin_name, plugin_path in _get_specific_plugin_paths(os.environ.get(
 
134
            'BZR_PLUGINS_AT', None)):
105
135
            PluginImporter.specific_paths[
106
136
                'bzrlib.plugins.%s' % plugin_name] = plugin_path
107
137
    return path
315
345
    except KeyboardInterrupt:
316
346
        raise
317
347
    except errors.IncompatibleAPI, e:
318
 
        trace.warning("Unable to load plugin %r. It requested API version "
 
348
        warning_message = (
 
349
            "Unable to load plugin %r. It requested API version "
319
350
            "%s of module %s but the minimum exported version is %s, and "
320
351
            "the maximum is %s" %
321
352
            (name, e.wanted, e.api, e.minimum, e.current))
 
353
        trace.mutter(warning_message)
 
354
        plugin_warnings.setdefault(name, []).append(warning_message)
322
355
    except Exception, e:
323
356
        trace.warning("%s" % e)
324
357
        if re.search('\.|-| ', name):
562
595
        # We are called only for specific paths
563
596
        plugin_path = self.specific_paths[fullname]
564
597
        loading_path = None
565
 
        package = False
566
598
        if os.path.isdir(plugin_path):
567
599
            for suffix, mode, kind in imp.get_suffixes():
568
600
                if kind not in (imp.PY_SOURCE, imp.PY_COMPILED):
570
602
                    continue
571
603
                init_path = osutils.pathjoin(plugin_path, '__init__' + suffix)
572
604
                if os.path.isfile(init_path):
573
 
                    loading_path = init_path
574
 
                    package = True
 
605
                    # We've got a module here and load_module needs specific
 
606
                    # parameters.
 
607
                    loading_path = plugin_path
 
608
                    suffix = ''
 
609
                    mode = ''
 
610
                    kind = imp.PKG_DIRECTORY
575
611
                    break
576
612
        else:
577
613
            for suffix, mode, kind in imp.get_suffixes():
581
617
        if loading_path is None:
582
618
            raise ImportError('%s cannot be loaded from %s'
583
619
                              % (fullname, plugin_path))
584
 
        f = open(loading_path, mode)
 
620
        if kind is imp.PKG_DIRECTORY:
 
621
            f = None
 
622
        else:
 
623
            f = open(loading_path, mode)
585
624
        try:
586
625
            mod = imp.load_module(fullname, f, loading_path,
587
626
                                  (suffix, mode, kind))
588
 
            if package:
589
 
                # The plugin can contain modules, so be ready
590
 
                mod.__path__ = [plugin_path]
591
627
            mod.__package__ = fullname
592
628
            return mod
593
629
        finally:
594
 
            f.close()
 
630
            if f is not None:
 
631
                f.close()
595
632
 
596
633
 
597
634
# Install a dedicated importer for plugins requiring special handling