~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugin.py

  • Committer: Aaron Bentley
  • Date: 2008-02-24 16:42:13 UTC
  • mfrom: (3234 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3235.
  • Revision ID: aaron@aaronbentley.com-20080224164213-eza1lzru5bwuwmmj
Merge with bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
from bzrlib import plugins as _mod_plugins
47
47
""")
48
48
 
49
 
from bzrlib.symbol_versioning import deprecated_function, zero_ninetyone
 
49
from bzrlib.symbol_versioning import deprecated_function, one_three
50
50
from bzrlib.trace import mutter, warning, log_exception_quietly
51
51
 
52
52
 
57
57
    """Get the DEFAULT_PLUGIN_PATH"""
58
58
    global DEFAULT_PLUGIN_PATH
59
59
    if DEFAULT_PLUGIN_PATH is None:
60
 
        path = [osutils.pathjoin(config.config_dir(), 'plugins')]
61
 
        if getattr(sys, 'frozen', None):    # bzr.exe
62
 
            # We need to use relative path to system-wide plugin
63
 
            # directory because bzrlib from standalone bzr.exe
64
 
            # could be imported by another standalone program
65
 
            # (e.g. bzr-config; or TortoiseBzr/Olive if/when they
66
 
            # will become standalone exe). [bialix 20071123]
67
 
            # __file__ typically is
68
 
            # C:\Program Files\Bazaar\lib\library.zip\bzrlib\plugin.pyc
69
 
            # then plugins directory is
70
 
            # C:\Program Files\Bazaar\plugins
71
 
            # so relative path is ../../../plugins
72
 
            path.append(osutils.abspath(osutils.pathjoin(
73
 
                osutils.dirname(__file__), '../../../plugins')))
74
 
        DEFAULT_PLUGIN_PATH = os.pathsep.join(path)
 
60
        DEFAULT_PLUGIN_PATH = osutils.pathjoin(config.config_dir(), 'plugins')
75
61
    return DEFAULT_PLUGIN_PATH
76
62
 
77
63
 
78
 
@deprecated_function(zero_ninetyone)
79
 
def all_plugins():
80
 
    """Return a dictionary of the plugins."""
81
 
    return dict((name, plugin.module) for name, plugin in plugins().items())
82
 
 
83
 
 
84
64
def disable_plugins():
85
65
    """Disable loading plugins.
86
66
 
100
80
    """Set the path for plugins to be loaded from."""
101
81
    path = os.environ.get('BZR_PLUGIN_PATH',
102
82
                          get_default_plugin_path()).split(os.pathsep)
 
83
    bzr_exe = bool(getattr(sys, 'frozen', None))
 
84
    if bzr_exe:    # expand path for bzr.exe
 
85
        # We need to use relative path to system-wide plugin
 
86
        # directory because bzrlib from standalone bzr.exe
 
87
        # could be imported by another standalone program
 
88
        # (e.g. bzr-config; or TortoiseBzr/Olive if/when they
 
89
        # will become standalone exe). [bialix 20071123]
 
90
        # __file__ typically is
 
91
        # C:\Program Files\Bazaar\lib\library.zip\bzrlib\plugin.pyc
 
92
        # then plugins directory is
 
93
        # C:\Program Files\Bazaar\plugins
 
94
        # so relative path is ../../../plugins
 
95
        path.append(osutils.abspath(osutils.pathjoin(
 
96
            osutils.dirname(__file__), '../../../plugins')))
103
97
    # Get rid of trailing slashes, since Python can't handle them when
104
98
    # it tries to import modules.
105
99
    path = map(_strip_trailing_sep, path)
106
 
    # search the plugin path before the bzrlib installed dir
107
 
    path.append(os.path.dirname(_mod_plugins.__file__))
 
100
    if not bzr_exe:     # don't look inside library.zip
 
101
        # search the plugin path before the bzrlib installed dir
 
102
        path.append(os.path.dirname(_mod_plugins.__file__))
108
103
    _mod_plugins.__path__ = path
109
104
    return path
110
105
 
154
149
        mutter('looking for plugins in %s', d)
155
150
        if os.path.isdir(d):
156
151
            load_from_dir(d)
157
 
        else:
158
 
            # it might be a zip: try loading from the zip.
159
 
            load_from_zip(d)
160
152
 
161
153
 
162
154
# backwards compatability: load_from_dirs was the old name
215
207
            log_exception_quietly()
216
208
 
217
209
 
 
210
@deprecated_function(one_three)
218
211
def load_from_zip(zip_name):
219
212
    """Load all the plugins in a zip."""
220
213
    valid_suffixes = ('.py', '.pyc', '.pyo')    # only python modules/packages
221
214
                                                # is allowed
222
 
 
223
215
    try:
224
216
        index = zip_name.rindex('.zip')
225
217
    except ValueError:
390
382
        if getattr(self.module, '__path__', None) is not None:
391
383
            return os.path.abspath(self.module.__path__[0])
392
384
        elif getattr(self.module, '__file__', None) is not None:
393
 
            return os.path.abspath(self.module.__file__)
 
385
            path = os.path.abspath(self.module.__file__)
 
386
            if path[-4:] in ('.pyc', '.pyo'):
 
387
                pypath = path[:-4] + '.py'
 
388
                if os.path.isfile(pypath):
 
389
                    path = pypath
 
390
            return path
394
391
        else:
395
392
            return repr(self.module)
396
393