/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: Vincent Ladeuil
  • Date: 2011-05-17 15:14:38 UTC
  • mfrom: (5050.73.3 2.2)
  • mto: (5609.39.5 2.3)
  • mto: This revision was merged to the branch mainline in revision 5885.
  • Revision ID: v.ladeuil+lp@free.fr-20110517151438-j75xuw2zm9alk9a5
Merge 2.2 into 2.3 resolving conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 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
81
81
    return path.rstrip("\\/")
82
82
 
83
83
 
 
84
def _get_specific_plugin_paths(paths):
 
85
    """Returns the plugin paths from a string describing the associations.
 
86
 
 
87
    :param paths: A string describing the paths associated with the plugins.
 
88
 
 
89
    :returns: A list of (plugin name, path) tuples.
 
90
 
 
91
    For example, if paths is my_plugin@/test/my-test:her_plugin@/production/her,
 
92
    [('my_plugin', '/test/my-test'), ('her_plugin', '/production/her')] 
 
93
    will be returned.
 
94
 
 
95
    Note that ':' in the example above depends on the os.
 
96
    """
 
97
    if not paths:
 
98
        return []
 
99
    specs = []
 
100
    for spec in paths.split(os.pathsep):
 
101
        try:
 
102
            name, path = spec.split('@')
 
103
        except ValueError:
 
104
            raise errors.BzrCommandError(
 
105
                '"%s" is not a valid <plugin_name>@<plugin_path> description '
 
106
                % spec)
 
107
        specs.append((name, path))
 
108
    return specs
 
109
 
 
110
 
84
111
def set_plugins_path(path=None):
85
112
    """Set the path for plugins to be loaded from.
86
113
 
98
125
        for name in disabled_plugins.split(os.pathsep):
99
126
            PluginImporter.blacklist.add('bzrlib.plugins.' + name)
100
127
    # 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('@')
 
128
    for plugin_name, plugin_path in _get_specific_plugin_paths(os.environ.get(
 
129
            'BZR_PLUGINS_AT', None)):
105
130
            PluginImporter.specific_paths[
106
131
                'bzrlib.plugins.%s' % plugin_name] = plugin_path
107
132
    return path
375
400
    return result
376
401
 
377
402
 
 
403
def format_concise_plugin_list():
 
404
    """Return a string holding a concise list of plugins and their version.
 
405
    """
 
406
    items = []
 
407
    for name, a_plugin in sorted(plugins().items()):
 
408
        items.append("%s[%s]" %
 
409
            (name, a_plugin.__version__))
 
410
    return ', '.join(items)
 
411
 
 
412
 
 
413
 
378
414
class PluginsHelpIndex(object):
379
415
    """A help index that returns help topics for plugins."""
380
416
 
562
598
        # We are called only for specific paths
563
599
        plugin_path = self.specific_paths[fullname]
564
600
        loading_path = None
565
 
        package = False
566
601
        if os.path.isdir(plugin_path):
567
602
            for suffix, mode, kind in imp.get_suffixes():
568
603
                if kind not in (imp.PY_SOURCE, imp.PY_COMPILED):
570
605
                    continue
571
606
                init_path = osutils.pathjoin(plugin_path, '__init__' + suffix)
572
607
                if os.path.isfile(init_path):
573
 
                    loading_path = init_path
574
 
                    package = True
 
608
                    # We've got a module here and load_module needs specific
 
609
                    # parameters.
 
610
                    loading_path = plugin_path
 
611
                    suffix = ''
 
612
                    mode = ''
 
613
                    kind = imp.PKG_DIRECTORY
575
614
                    break
576
615
        else:
577
616
            for suffix, mode, kind in imp.get_suffixes():
581
620
        if loading_path is None:
582
621
            raise ImportError('%s cannot be loaded from %s'
583
622
                              % (fullname, plugin_path))
584
 
        f = open(loading_path, mode)
 
623
        if kind is imp.PKG_DIRECTORY:
 
624
            f = None
 
625
        else:
 
626
            f = open(loading_path, mode)
585
627
        try:
586
628
            mod = imp.load_module(fullname, f, loading_path,
587
629
                                  (suffix, mode, kind))
588
 
            if package:
589
 
                # The plugin can contain modules, so be ready
590
 
                mod.__path__ = [plugin_path]
591
630
            mod.__package__ = fullname
592
631
            return mod
593
632
        finally:
594
 
            f.close()
 
633
            if f is not None:
 
634
                f.close()
595
635
 
596
636
 
597
637
# Install a dedicated importer for plugins requiring special handling