Skip to content

Commit a122c31

Browse files
author
rblazek
committed
partial fix for scripts on Windows; parser works and GUI is generated but run fails
git-svn-id: http://svn.osgeo.org/qgis/trunk@5121 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 4e7215b commit a122c31

File tree

2 files changed

+84
-10
lines changed

2 files changed

+84
-10
lines changed

src/plugins/grass/qgsgrassmodule.cpp

+78-9
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,12 @@ extern "C" {
9999
bool QgsGrassModule::mExecPathInited = 0;
100100
QStringList QgsGrassModule::mExecPath;
101101

102-
bool QgsGrassModule::inExecPath ( QString file )
102+
QString QgsGrassModule::findExec ( QString file )
103103
{
104104
#ifdef QGISDEBUG
105-
std::cerr << "QgsGrassModule::inExecPath()" << std::endl;
105+
std::cerr << "QgsGrassModule::findExec()" << std::endl;
106106
#endif
107+
107108
// Init mExecPath
108109
// Windows searches first in current directory
109110
if ( !mExecPathInited )
@@ -115,17 +116,40 @@ bool QgsGrassModule::inExecPath ( QString file )
115116
mExecPath.prepend ( QgsApplication::applicationDirPath() );
116117
mExecPathInited = true;
117118
}
119+
120+
if ( QFile::exists ( file ) ) return file; // full path
118121

119122
// Search for module
120123
for ( QStringList::iterator it = mExecPath.begin();
121124
it != mExecPath.end(); ++it )
122125
{
123-
if ( QFile::exists ( *it + "/" + file ) )
126+
QString full = *it + "/" + file;
127+
if ( QFile::exists ( full ) )
124128
{
125-
return true;
129+
return full;
126130
}
127131
}
128-
return false;
132+
133+
// Not found try with .exe
134+
#ifdef WIN32
135+
for ( QStringList::iterator it = mExecPath.begin();
136+
it != mExecPath.end(); ++it )
137+
{
138+
QString full = *it + "/" + file + ".exe";
139+
if ( QFile::exists ( full ) )
140+
{
141+
return full;
142+
}
143+
}
144+
#endif
145+
146+
return QString();
147+
}
148+
149+
bool QgsGrassModule::inExecPath ( QString file )
150+
{
151+
if ( findExec(file).isNull() ) return false;
152+
return true;
129153
}
130154

131155
QgsGrassModule::QgsGrassModule ( QgsGrassTools *tools, QgisApp *qgisApp, QgisIface *iface,
@@ -182,15 +206,15 @@ QgsGrassModule::QgsGrassModule ( QgsGrassTools *tools, QgisApp *qgisApp, QgisIfa
182206
// => test if the module is in path and if it is not
183207
// add .exe and test again
184208
#ifdef WIN32
185-
if ( inExecPath ( xName ) )
209+
if ( inExecPath ( xName ) )
186210
{
187211
mXName = xName;
188212
}
189213
else if ( inExecPath ( xName + ".exe" ) )
190214
{
191215
mXName = xName + ".exe";
192216
}
193-
else
217+
else
194218
{
195219
std::cerr << "Module " << xName.ascii() << " not found" << std::endl;
196220
QMessageBox::warning( 0, "Warning", "Module " + xName + " not found" );
@@ -291,19 +315,64 @@ QgsGrassModuleStandardOptions::QgsGrassModuleStandardOptions (
291315
std::cerr << "PATH = " << getenv ("PATH") << std::endl;
292316
#endif
293317

318+
// Attention!: sh.exe (MSYS) sets $0 in scripts to file name
319+
// without full path. Strange because when run from msys.bat
320+
// $0 is set to full path. GRASS scripts call
321+
// exec g.parser "$0" "$@"
322+
// and it fails -> find and run with full path
323+
294324
mXName = xname;
295325
mParent = parent;
326+
327+
QString exe;
328+
329+
#if defined(WIN32)
330+
exe = QgsGrassModule::findExec ( xname );
331+
if ( exe.isNull() )
332+
{
333+
QMessageBox::warning( 0, "Warning", "Cannot find module "
334+
+ xname );
335+
return;
336+
}
337+
#else
338+
exe = mXName;
339+
#endif
340+
341+
QString cmd;
342+
QStringList arguments;
343+
344+
#if defined(WIN32)
345+
QFileInfo fi ( exe );
346+
if ( fi.isExecutable() )
347+
{
348+
cmd = exe;
349+
}
350+
else // script
351+
{
352+
cmd = QgsApplication::applicationDirPath() + "/msys/bin/sh";
353+
354+
// Important! Otherwise it does not find DLL even if it is in PATH
355+
arguments.append ( "--login" );
356+
arguments.append ( exe );
357+
}
358+
#else
359+
cmd = exe;
360+
#endif
361+
arguments.append ( "--interface-description" );
296362

297363
QProcess process( this );
298-
process.start ( mXName, QStringList ( "--interface-description") );
364+
process.start ( cmd, arguments );
299365

300366
// ? Does binary on Win need .exe extention ?
301367
// Return code 255 (-1) was correct in GRASS < 6.1.0
302368
if ( !process.waitForFinished()
303369
|| (process.exitCode() != 0 && process.exitCode() != 255) )
304370
{
305371
std::cerr << "process.exitCode() = " << process.exitCode() << std::endl;
306-
QMessageBox::warning( 0, "Warning", "Cannot start module " + mXName );
372+
QMessageBox::warning( 0, "Warning", "Cannot start module " + mXName + "<br>"
373+
+ cmd + " " + arguments.join(" ") + "<br>"
374+
+ QString(process.readAllStandardOutput()) + "<br>"
375+
+ QString(process.readAllStandardError()) );
307376
return;
308377
}
309378
QByteArray gDescArray = process.readAllStandardOutput();

src/plugins/grass/qgsgrassmodule.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,13 @@ class QgsGrassModule: public QDialog, private Ui::QgsGrassModuleBase
9494
static QStringList mExecPath;
9595
static bool mExecPathInited;
9696

97+
// ! Find in exec path
98+
// returns full path or null string
99+
// appends automaticaly .exe on Windows
100+
static QString findExec ( QString file );
101+
97102
// ! Check if file is in mExecPath
98-
bool inExecPath ( QString file );
103+
static bool inExecPath ( QString file );
99104

100105
public slots:
101106
//! Run the module with current options

0 commit comments

Comments
 (0)