Skip to content

Commit 552e67d

Browse files
author
jef
committed
don't add PATH to PYTHONPATH
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13068 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent ded6ef7 commit 552e67d

File tree

1 file changed

+78
-72
lines changed

1 file changed

+78
-72
lines changed

src/providers/grass/qgsgrass.cpp

+78-72
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ QString GRASS_EXPORT QgsGrass::shortPath( const QString &path )
5656

5757
QString res = QString::fromUtf8( buf );
5858
// GRASS wxpyton GUI fails on paths with backslash, Windows do support forward slashesin paths
59-
res.replace ("\\", "/");
59+
res.replace( "\\", "/" );
6060
return res;
6161
}
6262
#endif
@@ -188,7 +188,7 @@ void GRASS_EXPORT QgsGrass::init( void )
188188
}
189189

190190
QgsDebugMsg( QString( "Valid GRASS gisBase is: %1" ).arg( gisBase ) );
191-
putEnv ( "GISBASE", gisBase );
191+
putEnv( "GISBASE", gisBase );
192192

193193
// Add path to GRASS modules
194194
#ifdef WIN32
@@ -219,14 +219,14 @@ void GRASS_EXPORT QgsGrass::init( void )
219219
path.append( sep + p );
220220

221221
QgsDebugMsg( QString( "set PATH: %1" ).arg( path ) );
222-
putEnv ( "PATH", path );
222+
putEnv( "PATH", path );
223223

224224
// Set PYTHONPATH
225225
QString pythonpath = gisBase + "/etc/python";
226-
QString pp = getenv( "PATH" );
226+
QString pp = getenv( "PYTHONPATH" );
227227
pythonpath.append( sep + pp );
228228
QgsDebugMsg( QString( "set PYTHONPATH: %1" ).arg( pythonpath ) );
229-
putEnv ( "PYTHONPATH", pythonpath );
229+
putEnv( "PYTHONPATH", pythonpath );
230230

231231
// Set GRASS_PAGER if not set, it is necessary for some
232232
// modules printing to terminal, e.g. g.list
@@ -265,7 +265,7 @@ void GRASS_EXPORT QgsGrass::init( void )
265265

266266
if ( pager.length() > 0 )
267267
{
268-
putEnv ( "GRASS_PAGER", pager );
268+
putEnv( "GRASS_PAGER", pager );
269269
}
270270
}
271271

@@ -385,7 +385,7 @@ int QgsGrass::error_routine( char *msg, int fatal )
385385

386386
int QgsGrass::error_routine( const char *msg, int fatal )
387387
{
388-
// Unfortunately the exceptions thrown here can only be caught if GRASS libraries are compiled
388+
// Unfortunately the exceptions thrown here can only be caught if GRASS libraries are compiled
389389
// with -fexception option on Linux (works on Windows)
390390
// GRASS developers are reluctant to add -fexception by default
391391
// https://trac.osgeo.org/grass/ticket/869
@@ -543,7 +543,8 @@ QString GRASS_EXPORT QgsGrass::openMapset( QString gisdbase, QString location, Q
543543
stream << line;
544544
line = "MAPSET: " + mapset + "\n";
545545
stream << line;
546-
if ( !guiSet ) {
546+
if ( !guiSet )
547+
{
547548
stream << "GRASS_GUI: wxpython\n";
548549
}
549550

@@ -552,7 +553,7 @@ QString GRASS_EXPORT QgsGrass::openMapset( QString gisdbase, QString location, Q
552553
// Set GISRC environment variable
553554

554555
/* _Correct_ putenv() implementation is not making copy! */
555-
putEnv ( "GISRC", mGisrc );
556+
putEnv( "GISRC", mGisrc );
556557

557558
// Reinitialize GRASS
558559
G__setenv(( char * ) "GISRC", mGisrc.toUtf8().data() );
@@ -1025,8 +1026,8 @@ bool GRASS_EXPORT QgsGrass::mapRegion( int type, QString gisbase,
10251026
return true;
10261027
}
10271028

1028-
QByteArray GRASS_EXPORT QgsGrass::runModule( QString gisdbase, QString location,
1029-
QString module, QStringList arguments )
1029+
QByteArray GRASS_EXPORT QgsGrass::runModule( QString gisdbase, QString location,
1030+
QString module, QStringList arguments )
10301031
{
10311032
QgsDebugMsg( QString( "gisdbase = %1 location = %2" ).arg( gisdbase ).arg( location ) );
10321033

@@ -1036,142 +1037,147 @@ QByteArray GRASS_EXPORT QgsGrass::runModule( QString gisdbase, QString location
10361037

10371038
// We have to set GISRC file, uff
10381039
QTemporaryFile gisrcFile;
1039-
if ( !gisrcFile.open() )
1040+
if ( !gisrcFile.open() )
10401041
{
10411042
// TODO Exception
10421043
return QByteArray();
10431044
}
1044-
1045-
QTextStream out(&gisrcFile);
1045+
1046+
QTextStream out( &gisrcFile );
10461047
out << "GISDBASE: " << gisdbase << "\n";
10471048
out << "LOCATION_NAME: " << location << "\n";
10481049
out << "MAPSET: PERMANENT\n";
1049-
out.flush ();
1050+
out.flush();
10501051
QgsDebugMsg( gisrcFile.fileName() );
10511052

10521053
QStringList environment = QProcess::systemEnvironment();
1053-
environment.append("GISRC=" + gisrcFile.fileName() );
1054+
environment.append( "GISRC=" + gisrcFile.fileName() );
10541055

10551056
QProcess process;
10561057
process.setEnvironment( environment );
10571058

1058-
QgsDebugMsg( module + " " + arguments.join (" ") );
1059+
QgsDebugMsg( module + " " + arguments.join( " " ) );
10591060
process.start( module, arguments );
10601061
if ( !process.waitForFinished()
10611062
|| ( process.exitCode() != 0 && process.exitCode() != 255 ) )
10621063
{
10631064
QgsDebugMsg( "process.exitCode() = " + QString::number( process.exitCode() ) );
1064-
/*
1065-
QMessageBox::warning( 0, QObject::tr( "Warning" ),
1066-
QObject::tr( "Cannot start module" )
1067-
+ QObject::tr( "<br>command: %1 %2<br>%3<br>%4" )
1068-
.arg( module ).arg( arguments.join( " " ) )
1069-
.arg( process.readAllStandardOutput().constData() )
1070-
.arg( process.readAllStandardError().constData() ) );
1071-
*/
1065+
/*
1066+
QMessageBox::warning( 0, QObject::tr( "Warning" ),
1067+
QObject::tr( "Cannot start module" )
1068+
+ QObject::tr( "<br>command: %1 %2<br>%3<br>%4" )
1069+
.arg( module ).arg( arguments.join( " " ) )
1070+
.arg( process.readAllStandardOutput().constData() )
1071+
.arg( process.readAllStandardError().constData() ) );
1072+
*/
10721073
throw QgsGrass::Exception( QObject::tr( "Cannot start module" ) + "\n"
1073-
+ QObject::tr( "command: %1 %2<br>%3<br>%4" )
1074-
.arg( module ).arg( arguments.join( " " ) )
1075-
.arg( process.readAllStandardOutput().constData() )
1076-
.arg( process.readAllStandardError().constData() ) );
1074+
+ QObject::tr( "command: %1 %2<br>%3<br>%4" )
1075+
.arg( module ).arg( arguments.join( " " ) )
1076+
.arg( process.readAllStandardOutput().constData() )
1077+
.arg( process.readAllStandardError().constData() ) );
10771078
}
10781079
QByteArray data = process.readAllStandardOutput();
10791080

10801081
return data;
10811082
}
10821083

1083-
QString GRASS_EXPORT QgsGrass::getInfo( QString info, QString gisdbase, QString location,
1084-
QString mapset, QString map, MapType type, double x, double y)
1084+
QString GRASS_EXPORT QgsGrass::getInfo( QString info, QString gisdbase, QString location,
1085+
QString mapset, QString map, MapType type, double x, double y )
10851086
{
10861087
QgsDebugMsg( QString( "gisdbase = %1 location = %2" ).arg( gisdbase ).arg( location ) );
10871088

1088-
QStringList arguments;
1089+
QStringList arguments;
10891090

10901091
QString cmd = QgsApplication::pkgDataPath() + "/grass/modules/qgis.g.info";
1091-
1092+
10921093
arguments.append( "info=" + info );
1093-
if ( !map.isNull() )
1094-
{
1095-
QString opt;
1096-
switch (type)
1097-
{
1098-
case Raster:
1099-
opt = "rast";
1100-
break;
1101-
case Vector:
1102-
opt = "vect";
1103-
break;
1104-
}
1105-
arguments.append( opt + "=" + map + "@" + mapset );
1094+
if ( !map.isNull() )
1095+
{
1096+
QString opt;
1097+
switch ( type )
1098+
{
1099+
case Raster:
1100+
opt = "rast";
1101+
break;
1102+
case Vector:
1103+
opt = "vect";
1104+
break;
1105+
default:
1106+
QgsDebugMsg( "unexpected type:" + type );
1107+
return "";
1108+
}
1109+
arguments.append( opt + "=" + map + "@" + mapset );
11061110
}
1107-
if ( info == "query" )
1111+
if ( info == "query" )
11081112
{
1109-
arguments.append( QString("coor=%1,%2").arg(x).arg(y) );
1113+
arguments.append( QString( "coor=%1,%2" ).arg( x ).arg( y ) );
11101114
}
1111-
1112-
QByteArray data = QgsGrass::runModule ( gisdbase, location, cmd, arguments );
1115+
1116+
QByteArray data = QgsGrass::runModule( gisdbase, location, cmd, arguments );
11131117
QgsDebugMsg( data );
11141118
return QString( data );
11151119
}
11161120

1117-
QgsCoordinateReferenceSystem GRASS_EXPORT QgsGrass::crs( QString gisdbase, QString location )
1121+
QgsCoordinateReferenceSystem GRASS_EXPORT QgsGrass::crs( QString gisdbase, QString location )
11181122
{
11191123
QgsDebugMsg( QString( "gisdbase = %1 location = %2" ).arg( gisdbase ).arg( location ) );
11201124
QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem();
1121-
try
1125+
try
11221126
{
1123-
QString wkt = QgsGrass::getInfo ( "proj", gisdbase, location );
1127+
QString wkt = QgsGrass::getInfo( "proj", gisdbase, location );
11241128
crs.createFromWkt( wkt );
11251129

1126-
}
1130+
}
11271131
catch ( QgsException &e )
11281132
{
1129-
QMessageBox::warning( 0, QObject::tr( "Warning" ),
1130-
QObject::tr( "Cannot get projection " ) + "\n"+ e.what() );
1133+
QMessageBox::warning( 0, QObject::tr( "Warning" ),
1134+
QObject::tr( "Cannot get projection " ) + "\n" + e.what() );
11311135
}
11321136

11331137
return crs;
11341138
}
11351139

1136-
QgsRectangle GRASS_EXPORT QgsGrass::extent( QString gisdbase, QString location, QString mapset, QString map, MapType type )
1140+
QgsRectangle GRASS_EXPORT QgsGrass::extent( QString gisdbase, QString location, QString mapset, QString map, MapType type )
11371141
{
11381142
QgsDebugMsg( QString( "gisdbase = %1 location = %2" ).arg( gisdbase ).arg( location ) );
11391143

1140-
try
1144+
try
11411145
{
1142-
QString str = QgsGrass::getInfo ( "window", gisdbase, location, mapset, map, type );
1143-
QStringList list = str.split(",");
1144-
if ( list.size() != 4 ) {
1146+
QString str = QgsGrass::getInfo( "window", gisdbase, location, mapset, map, type );
1147+
QStringList list = str.split( "," );
1148+
if ( list.size() != 4 )
1149+
{
11451150
throw QgsGrass::Exception( "Cannot parse GRASS map extent: " + str );
11461151
}
1147-
return QgsRectangle ( list[0].toDouble(), list[1].toDouble(), list[2].toDouble(), list[3].toDouble() ) ;
1152+
return QgsRectangle( list[0].toDouble(), list[1].toDouble(), list[2].toDouble(), list[3].toDouble() ) ;
11481153
}
11491154
catch ( QgsException &e )
11501155
{
1151-
QMessageBox::warning( 0, QObject::tr( "Warning" ),
1152-
QObject::tr( "Cannot get raster extent" ) + "\n"+ e.what() );
1156+
QMessageBox::warning( 0, QObject::tr( "Warning" ),
1157+
QObject::tr( "Cannot get raster extent" ) + "\n" + e.what() );
11531158
}
11541159
return QgsRectangle( 0, 0, 0, 0 );
11551160
}
11561161

1157-
QMap<QString, QString> GRASS_EXPORT QgsGrass::query ( QString gisdbase, QString location, QString mapset, QString map, MapType type, double x, double y )
1162+
QMap<QString, QString> GRASS_EXPORT QgsGrass::query( QString gisdbase, QString location, QString mapset, QString map, MapType type, double x, double y )
11581163
{
11591164
QgsDebugMsg( QString( "gisdbase = %1 location = %2" ).arg( gisdbase ).arg( location ) );
11601165

11611166
QMap<QString, QString> result;
11621167
// TODO: multiple values (more rows)
1163-
try
1168+
try
11641169
{
1165-
QString str = QgsGrass::getInfo ( "query", gisdbase, location, mapset, map, type, x, y );
1166-
QStringList list = str.trimmed().split(":");
1167-
if ( list.size() == 2 ) {
1170+
QString str = QgsGrass::getInfo( "query", gisdbase, location, mapset, map, type, x, y );
1171+
QStringList list = str.trimmed().split( ":" );
1172+
if ( list.size() == 2 )
1173+
{
11681174
result[list[0]] = list[1];
11691175
}
11701176
}
11711177
catch ( QgsException &e )
11721178
{
1173-
QMessageBox::warning( 0, QObject::tr( "Warning" ),
1174-
QObject::tr( "Cannot query raster " ) + "\n"+ e.what() );
1179+
QMessageBox::warning( 0, QObject::tr( "Warning" ),
1180+
QObject::tr( "Cannot query raster " ) + "\n" + e.what() );
11751181
}
11761182
return result;
11771183
}
@@ -1243,7 +1249,7 @@ QString GRASS_EXPORT QgsGrass::gisrcFilePath()
12431249
// Started from GRASS shell
12441250
if ( getenv( "GISRC" ) )
12451251
{
1246-
return QString ( getenv( "GISRC" ) );
1252+
return QString( getenv( "GISRC" ) );
12471253
}
12481254
}
12491255
return mGisrc;

0 commit comments

Comments
 (0)