@@ -59,17 +59,18 @@ void QgsPythonUtilsImpl::initPython( QgisInterface* interface )
59
59
runString ( " import sys" ); // import sys module (for display / exception hooks)
60
60
runString ( " import os" ); // import os module (for user paths)
61
61
62
+ // construct a list of plugin paths
63
+ // plugin dirs passed in QGIS_PLUGINPATH env. variable have highest priority (usually empty)
64
+ // locally installed plugins have priority over the system plugins
65
+ QStringList pluginpaths = extraPluginsPaths ();
66
+ pluginpaths << homePluginsPath () << pluginsPath ();
67
+
62
68
// expect that bindings are installed locally, so add the path to modules
63
69
// also add path to plugins
64
- #ifdef Q_OS_WIN
65
- runString ( " oldhome=None\n " );
66
- runString ( " if os.environ.has_key('HOME'): oldhome=os.environ['HOME']\n " );
67
- runString ( " os.environ['HOME']=os.environ['USERPROFILE']" );
68
- #endif
69
- runString ( " sys.path = [\" " + pythonPath () + " \" , os.path.expanduser(\" ~/.qgis/python\" ), os.path.expanduser(\" ~/.qgis/python/plugins\" ), \" " + pluginsPath () + " \" ] + sys.path" );
70
- #ifdef Q_OS_WIN
71
- runString ( " if oldhome: os.environ['HOME']=oldhome\n " );
72
- #endif
70
+ QStringList newpaths;
71
+ newpaths << pythonPath () << homePythonPath ();
72
+ newpaths += pluginpaths;
73
+ runString ( " sys.path = [\" " + newpaths.join (" \" , \" " ) + " \" ] + sys.path" );
73
74
74
75
// import SIP
75
76
if ( !runString ( " from sip import wrapinstance, unwrapinstance" ,
@@ -103,6 +104,9 @@ void QgsPythonUtilsImpl::initPython( QgisInterface* interface )
103
104
return ;
104
105
}
105
106
107
+ // tell the utils script where to look for the plugins
108
+ runString ( " qgis.utils.plugin_paths = [\" " + pluginpaths.join ( " \" ,\" " ) + " \" ]" );
109
+
106
110
// initialize 'iface' object
107
111
runString ( " qgis.utils.initInterface(" + QString::number (( unsigned long ) interface ) + " )" );
108
112
}
@@ -390,14 +394,30 @@ QString QgsPythonUtilsImpl::pluginsPath()
390
394
391
395
QString QgsPythonUtilsImpl::homePythonPath ()
392
396
{
393
- return QgsApplication::qgisSettingsDirPath () + " / python" ;
397
+ return QgsApplication::qgisSettingsDirPath () + " python" ;
394
398
}
395
399
396
400
QString QgsPythonUtilsImpl::homePluginsPath ()
397
401
{
398
402
return homePythonPath () + " /plugins" ;
399
403
}
400
404
405
+ QStringList QgsPythonUtilsImpl::extraPluginsPaths ()
406
+ {
407
+ const char * cpaths = getenv ( " QGIS_PLUGINPATH" );
408
+ if (cpaths == NULL )
409
+ return QStringList ();
410
+
411
+ QString paths = QString::fromLocal8Bit ( cpaths );
412
+ if ( paths.contains ( ' ;' ) ) // keep windows users happy
413
+ return paths.split ( ' ;' );
414
+ else if ( paths.contains ( ' :' ) ) // keep unix users happy
415
+ return paths.split ( ' :' );
416
+ else
417
+ return QStringList ( paths ); // just one path
418
+ }
419
+
420
+
401
421
QStringList QgsPythonUtilsImpl::pluginList ()
402
422
{
403
423
runString ( " qgis.utils.updateAvailablePlugins()" );
0 commit comments