Skip to content
Permalink
Browse files

use os.path.expand user for home directories for python (reintroduces…

… fixes from #2515)
  • Loading branch information
jef-n committed Jan 29, 2012
1 parent b44ae22 commit b60a63bbe9cacccff5c191a8cd3ac88b6dc7ea4a
Showing with 23 additions and 6 deletions.
  1. +23 −6 src/python/qgspythonutilsimpl.cpp
@@ -58,18 +58,31 @@ void QgsPythonUtilsImpl::initPython( QgisInterface* interface )
runString( "import sys" ); // import sys module (for display / exception hooks)
runString( "import os" ); // import os module (for user paths)

#ifdef Q_OS_WIN
runString( "oldhome=None" );
runString( "if os.environ.has_key('HOME'): oldhome=os.environ['HOME']" );
runString( "os.environ['HOME']=os.environ['USERPROFILE']" );
#endif

// 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();
// use os.path.expanduser to support usernames with special characters (see #2512)
QStringList pluginpaths;
foreach( QString p, extraPluginsPaths() )
{
pluginpaths << '"' + p + '"';
}
pluginpaths << "os.path.expanduser(\"~/.qgis/python/plugins\")";
pluginpaths << '"' + pluginsPath() + '"';

// expect that bindings are installed locally, so add the path to modules
// also add path to plugins
QStringList newpaths;
newpaths << pythonPath() << homePythonPath();
newpaths += pluginpaths;
runString( "sys.path = [\"" + newpaths.join( "\", \"" ) + "\"] + sys.path" );
newpaths << '"' + pythonPath() + '"';
newpaths << "os.path.expanduser(\"~/.qgis/python\")";
newpaths << pluginpaths;
runString( "sys.path = [" + newpaths.join( "," ) + "] + sys.path" );

// import SIP
if ( !runString( "from sip import wrapinstance, unwrapinstance",
@@ -104,7 +117,11 @@ void QgsPythonUtilsImpl::initPython( QgisInterface* interface )
}

// tell the utils script where to look for the plugins
runString( "qgis.utils.plugin_paths = [\"" + pluginpaths.join( "\",\"" ) + "\"]" );
runString( "qgis.utils.plugin_paths = [" + pluginpaths.join( "," ) + "]" );

#ifdef Q_OS_WIN
runString( "if oldhome: os.environ['HOME']=oldhome" );
#endif

// initialize 'iface' object
runString( "qgis.utils.initInterface(" + QString::number(( unsigned long ) interface ) + ")" );

0 comments on commit b60a63b

Please sign in to comment.
You can’t perform that action at this time.