[QGIS Commit] r13943 - in trunk/qgis: python src/python
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Tue Jul 20 09:06:49 EDT 2010
Author: wonder
Date: 2010-07-20 13:06:49 +0000 (Tue, 20 Jul 2010)
New Revision: 13943
Modified:
trunk/qgis/python/utils.py
trunk/qgis/src/python/qgspythonutilsimpl.cpp
trunk/qgis/src/python/qgspythonutilsimpl.h
Log:
Better handling of python path and plugins paths.
Additionally, plugin paths in QGIS_PLUGINPATH can be separated by either semicolon or colon.
Modified: trunk/qgis/python/utils.py
===================================================================
--- trunk/qgis/python/utils.py 2010-07-20 12:21:53 UTC (rev 13942)
+++ trunk/qgis/python/utils.py 2010-07-20 13:06:49 UTC (rev 13943)
@@ -60,6 +60,9 @@
#######################
# PLUGINS
+# list of plugin paths. it gets filled in by the QGIS python library
+plugin_paths = []
+
# dictionary of plugins
plugins = {}
@@ -77,33 +80,18 @@
return plugins
def updateAvailablePlugins():
- from qgis.core import QgsApplication
- plugindirs = [
- unicode(QgsApplication.pkgDataPath()) + "/python/plugins",
- unicode(QgsApplication.qgisSettingsDirPath()) + "/python/plugins"
- ]
- env = os.environ.get("QGIS_PLUGINPATH")
- if env:
- plugindirs.extend(env.split(";"))
-
+ """ go thrgouh the plugin_paths list and find out what plugins are available """
# merge the lists
plugins = []
- for pluginpath in plugindirs:
- newplugins = findPlugins(pluginpath)
- if len(newplugins) > 0:
- if pluginpath not in sys.path:
- sys.path.append(pluginpath)
- for p in newplugins:
- if p not in plugins:
- plugins.append(p)
+ for pluginpath in plugin_paths:
+ for p in findPlugins(pluginpath):
+ if p not in plugins:
+ plugins.append(p)
global available_plugins
available_plugins = plugins
-# update list on start
-updateAvailablePlugins()
-
def pluginMetadata(packageName, fct):
""" fetch metadata from a plugin """
try:
Modified: trunk/qgis/src/python/qgspythonutilsimpl.cpp
===================================================================
--- trunk/qgis/src/python/qgspythonutilsimpl.cpp 2010-07-20 12:21:53 UTC (rev 13942)
+++ trunk/qgis/src/python/qgspythonutilsimpl.cpp 2010-07-20 13:06:49 UTC (rev 13943)
@@ -59,17 +59,18 @@
runString( "import sys" ); // import sys module (for display / exception hooks)
runString( "import os" ); // import os module (for user paths)
+ // construct a list of plugin paths
+ // plugin dirs passed in QGIS_PLUGINPATH env. variable have highest priority (usually empty)
+ // locally installed plugins have priority over the system plugins
+ QStringList pluginpaths = extraPluginsPaths();
+ pluginpaths << homePluginsPath() << pluginsPath();
+
// expect that bindings are installed locally, so add the path to modules
// also add path to plugins
-#ifdef Q_OS_WIN
- runString( "oldhome=None\n" );
- runString( "if os.environ.has_key('HOME'): oldhome=os.environ['HOME']\n" );
- runString( "os.environ['HOME']=os.environ['USERPROFILE']" );
-#endif
- runString( "sys.path = [\"" + pythonPath() + "\", os.path.expanduser(\"~/.qgis/python\"), os.path.expanduser(\"~/.qgis/python/plugins\"), \"" + pluginsPath() + "\" ] + sys.path" );
-#ifdef Q_OS_WIN
- runString( "if oldhome: os.environ['HOME']=oldhome\n" );
-#endif
+ QStringList newpaths;
+ newpaths << pythonPath() << homePythonPath();
+ newpaths += pluginpaths;
+ runString( "sys.path = [\"" + newpaths.join("\", \"") + "\"] + sys.path" );
// import SIP
if ( !runString( "from sip import wrapinstance, unwrapinstance",
@@ -103,6 +104,9 @@
return;
}
+ // tell the utils script where to look for the plugins
+ runString( "qgis.utils.plugin_paths = [\"" + pluginpaths.join( "\",\"" ) + "\"]" );
+
// initialize 'iface' object
runString( "qgis.utils.initInterface(" + QString::number(( unsigned long ) interface ) + ")" );
}
@@ -390,7 +394,7 @@
QString QgsPythonUtilsImpl::homePythonPath()
{
- return QgsApplication::qgisSettingsDirPath() + "/python";
+ return QgsApplication::qgisSettingsDirPath() + "python";
}
QString QgsPythonUtilsImpl::homePluginsPath()
@@ -398,6 +402,22 @@
return homePythonPath() + "/plugins";
}
+QStringList QgsPythonUtilsImpl::extraPluginsPaths()
+{
+ const char* cpaths = getenv( "QGIS_PLUGINPATH" );
+ if (cpaths == NULL)
+ return QStringList();
+
+ QString paths = QString::fromLocal8Bit( cpaths );
+ if ( paths.contains( ';' ) ) // keep windows users happy
+ return paths.split( ';' );
+ else if ( paths.contains( ':' ) ) // keep unix users happy
+ return paths.split( ':' );
+ else
+ return QStringList( paths ); // just one path
+}
+
+
QStringList QgsPythonUtilsImpl::pluginList()
{
runString( "qgis.utils.updateAvailablePlugins()" );
Modified: trunk/qgis/src/python/qgspythonutilsimpl.h
===================================================================
--- trunk/qgis/src/python/qgspythonutilsimpl.h 2010-07-20 12:21:53 UTC (rev 13942)
+++ trunk/qgis/src/python/qgspythonutilsimpl.h 2010-07-20 13:06:49 UTC (rev 13943)
@@ -79,6 +79,9 @@
//! return current path for home directory python plugins
QString homePluginsPath();
+ //! return a list of extra plugins paths passed with QGIS_PLUGINPATH environment variable
+ QStringList extraPluginsPaths();
+
//! return list of all available python plugins
QStringList pluginList();
More information about the QGIS-commit
mailing list