Skip to content

Commit

Permalink
use os.path.expand user for home directories for python (reintroduces…
Browse files Browse the repository at this point in the history
… fixes from #2515)
  • Loading branch information
jef-n committed Jan 29, 2012
1 parent b44ae22 commit b60a63b
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/python/qgspythonutilsimpl.cpp
Expand Up @@ -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",
Expand Down Expand Up @@ -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 ) + ")" );
Expand Down

0 comments on commit b60a63b

Please sign in to comment.