/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: 2009-08-19 17:01:06 UTC
  • mto: (4672.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4673.
  • Revision ID: v.ladeuil+lp@free.fr-20090819170106-v652tu3p0mqnqs09
Start introducing accessors for plugin paths.

* bzrlib/tests/test_plugins.py:
(clear_plugins): Deleted (or rather turned into a proper setUp).
(TestLoadFromPath): Use a proper setUp.
(TestLoadPlugins): Merged into TestLoadFromPath.
(TestEnvPluginPath): Start simple tests for path composition.

* bzrlib/plugin.py:
(_append_new_path): New helper.
(get_core_plugin_path, get_site_plugin_path,
get_user_plugin_path): New accessors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
91
91
    return path
92
92
 
93
93
 
 
94
def _append_new_path(paths, new_path):
 
95
    """Append a new path if it set and not already known."""
 
96
    if new_path is not None and new_path not in paths:
 
97
        paths.append(new_path)
 
98
    return paths
 
99
 
 
100
 
 
101
def get_core_plugin_path():
 
102
    core_path = None
 
103
    bzr_exe = bool(getattr(sys, 'frozen', None))
 
104
    if bzr_exe:    # expand path for bzr.exe
 
105
        # We need to use relative path to system-wide plugin
 
106
        # directory because bzrlib from standalone bzr.exe
 
107
        # could be imported by another standalone program
 
108
        # (e.g. bzr-config; or TortoiseBzr/Olive if/when they
 
109
        # will become standalone exe). [bialix 20071123]
 
110
        # __file__ typically is
 
111
        # C:\Program Files\Bazaar\lib\library.zip\bzrlib\plugin.pyc
 
112
        # then plugins directory is
 
113
        # C:\Program Files\Bazaar\plugins
 
114
        # so relative path is ../../../plugins
 
115
        core_path = osutils.abspath(osutils.pathjoin(
 
116
                osutils.dirname(__file__), '../../../plugins'))
 
117
    else:     # don't look inside library.zip
 
118
        # search the plugin path before the bzrlib installed dir
 
119
        core_path = os.path.dirname(_mod_plugins.__file__)
 
120
    return core_path
 
121
 
 
122
 
 
123
def get_site_plugin_path():
 
124
    """Returns the path for the site installed plugins."""
 
125
    site_path = None
 
126
    try:
 
127
        from distutils.sysconfig import get_python_lib
 
128
    except ImportError:
 
129
        # If distutuils is not available, we just don't know where they are
 
130
        pass
 
131
    else:
 
132
        site_path = osutils.pathjoin(get_python_lib(), 'bzrlib', 'plugins')
 
133
    return site_path
 
134
 
 
135
 
 
136
def get_user_plugin_path():
 
137
    return osutils.pathjoin(config.config_dir(), 'plugins')
 
138
 
 
139
 
94
140
def get_standard_plugins_path():
95
141
    """Determine a plugin path suitable for general use."""
96
142
    path = os.environ.get('BZR_PLUGIN_PATH',