Skip to content

Commit 92b7dfd

Browse files
author
volayaf@gmail.com
committedApr 16, 2012
Added some checks for external apps configuration
git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@100 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
1 parent 403cce2 commit 92b7dfd

File tree

7 files changed

+59
-14
lines changed

7 files changed

+59
-14
lines changed
 

‎src/sextante/SextantePlugin.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ def __init__(self, iface):
2626
QGisLayers.setInterface(iface)
2727
Sextante.initialize()
2828
Sextante.setInterface(iface)
29-
SextanteExternalAppsConfigurer.autoConfigure()
30-
3129

3230
def initGui(self):
3331
self.toolbox = SextanteToolbox(self.iface)

‎src/sextante/core/SextanteExternalAppsConfigurer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class SextanteExternalAppsConfigurer():
44

55
@staticmethod
6-
def autoConfigure():
6+
def checkSettings():
77
IS_FIRST_USAGE = "IS_FIRST_USAGE"
88
settings = QtCore.QSettings()
99
if not settings.contains(IS_FIRST_USAGE):

‎src/sextante/grass/GrassAlgorithmProvider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def initializeSettings(self):
1818
AlgorithmProvider.initializeSettings(self)
1919
if SextanteUtils.isWindows():
2020
SextanteConfig.addSetting(Setting("GRASS", GrassUtils.GRASS_FOLDER, "GRASS folder", GrassUtils.grassPath()))
21-
SextanteConfig.addSetting(Setting("GRASS", GrassUtils.GRASS_WIN_SHELL, "Shell executable", GrassUtils.grassWinShell()))
21+
SextanteConfig.addSetting(Setting("GRASS", GrassUtils.GRASS_WIN_SHELL, "Msys folder", GrassUtils.grassWinShell()))
2222
SextanteConfig.addSetting(Setting("GRASS", GrassUtils.GRASS_AUTO_REGION, "Use min covering region", True))
2323
SextanteConfig.addSetting(Setting("GRASS", GrassUtils.GRASS_LATLON, "Coordinates are lat/lon", False))
2424
SextanteConfig.addSetting(Setting("GRASS", GrassUtils.GRASS_REGION_XMIN, "GRASS Region min x", 0))

‎src/sextante/grass/GrassUtils.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from sextante.core.SextanteLog import SextanteLog
66
import stat
77
import shutil
8+
import plugin_installer
89

910
class GrassUtils:
1011

@@ -39,7 +40,13 @@ def grassScriptFilename():
3940
def grassPath():
4041
folder = SextanteConfig.getSetting(GrassUtils.GRASS_FOLDER)
4142
if folder == None:
42-
folder =""
43+
folder = plugin_installer.__file__
44+
idx = folder.find('qgis')
45+
folder = folder[:idx] + "grass"
46+
for subfolder in os.listdir(folder):
47+
if subfolder.startswith("grass"):
48+
folder = folder + os.sep + subfolder
49+
break
4350

4451
return folder
4552

@@ -53,11 +60,13 @@ def grassHelpPath():
5360

5461
@staticmethod
5562
def grassWinShell():
56-
shell = SextanteConfig.getSetting(GrassUtils.GRASS_WIN_SHELL)
57-
if shell == None:
58-
shell =""
63+
folder = SextanteConfig.getSetting(GrassUtils.GRASS_WIN_SHELL)
64+
if folder == None:
65+
folder = plugin_installer.__file__
66+
idx = folder.find('qgis')
67+
folder = folder[:idx] + "msys"
5968

60-
return shell
69+
return folder
6170

6271
@staticmethod
6372
def grassDescriptionPath():

‎src/sextante/r/RAlgorithm.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import os
2+
from PyQt4.QtCore import *
3+
from PyQt4.QtGui import *
4+
from PyQt4 import QtGui, QtCore
15
from sextante.core.GeoAlgorithm import GeoAlgorithm
26
from sextante.parameters.ParameterRaster import ParameterRaster
37
from sextante.parameters.ParameterTable import ParameterTable
@@ -10,15 +14,14 @@
1014
from sextante.parameters.ParameterString import ParameterString
1115
from sextante.parameters.ParameterNumber import ParameterNumber
1216
from sextante.parameters.ParameterBoolean import ParameterBoolean
13-
import os
1417
from sextante.parameters.ParameterSelection import ParameterSelection
15-
from PyQt4 import QtGui
1618
from sextante.parameters.ParameterTableField import ParameterTableField
1719
from sextante.outputs.OutputHTML import OutputHTML
1820
from sextante.r.RUtils import RUtils
1921
from sextante.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
2022
from sextante.core.SextanteLog import SextanteLog
2123
from sextante.core.SextanteUtils import SextanteUtils
24+
import subprocess
2225

2326
class RAlgorithm(GeoAlgorithm):
2427

@@ -148,7 +151,7 @@ def processAlgorithm(self, progress):
148151
if SextanteUtils.isWindows():
149152
path = RUtils.RFolder()
150153
if path == "":
151-
raise GeoAlgorithmExecutionException("R folder is not configured.\nPlease configure it before running R script.")
154+
raise GeoAlgorithmExecutionException("R folder is not configured.\nPlease configure it before running R scripts.")
152155
loglines = []
153156
loglines.append("R execution commands")
154157
loglines += self.getFullSetOfRCommands()
@@ -272,3 +275,21 @@ def getRCommands(self):
272275
return self.commands
273276

274277

278+
def checkBeforeOpeningParametersDialog(self):
279+
if SextanteUtils.isWindows():
280+
path = RUtils.RFolder()
281+
if path == "":
282+
return "R folder is not configured.\nPlease configure it before running R scripts."
283+
else:
284+
R_INSTALLED = "R_INSTALLED"
285+
settings = QSettings()
286+
if settings.contains(R_INSTALLED):
287+
return
288+
command = ["R CMD BATCH"]
289+
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE,stderr=subprocess.STDOUT, universal_newlines=True).stdout
290+
for line in iter(proc.readline, ""):
291+
if "no input file" in line:
292+
settings.setValue(R_INSTALLED, True)
293+
return
294+
return "It seems that SAGA is not correctly installed in your system.\nPlease install it before running SAGA algorithms."
295+

‎src/sextante/saga/SagaAlgorithm.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from sextante.parameters.ParameterNumber import ParameterNumber
2424
from sextante.parameters.ParameterSelection import ParameterSelection
2525
from sextante.core.LayerExporter import LayerExporter
26+
import subprocess
2627

2728
class SagaAlgorithm(GeoAlgorithm):
2829

@@ -275,5 +276,21 @@ def exportRasterLayer(self, layer):
275276
return "libio_gdal 0 -GRIDS \"" + destFilename + "\" -FILES \"" + layer + "\""
276277

277278

278-
279+
def checkBeforeOpeningParametersDialog(self):
280+
if SextanteUtils.isWindows():
281+
path = SagaUtils.sagaPath()
282+
if path == "":
283+
return "SAGA folder is not configured.\nPlease configure it before running SAGA algorithms."
284+
else:
285+
SAGA_INSTALLED = "SAGA_INSTALLED"
286+
settings = QSettings()
287+
if settings.contains(SAGA_INSTALLED):
288+
return
289+
command = ["saga_cmd"]
290+
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE,stderr=subprocess.STDOUT, universal_newlines=True).stdout
291+
for line in iter(proc.readline, ""):
292+
if "-------------" in line:
293+
settings.setValue(SAGA_INSTALLED, True)
294+
return
295+
return "It seems that SAGA is not correctly installed in your system.\nPlease install it before running SAGA algorithms."
279296

‎src/sextanteexampleprovider/ExampleAlgorithm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def defineCharacteristics(self):
3838
#we add the input vector layer. It can have any kind of geometry
3939
#It is a mandatory (not optional) one, hence the False argument
4040
self.addParameter(ParameterVector(self.INPUT_LAYER, "Input layer", ParameterVector.VECTOR_TYPE_ANY, False))
41-
41+
self.addParameter(ParameterExtent("EXTENT","EXTENT"))
4242
# we add a vector layer as output
4343
self.addOutput(OutputVector(self.OUTPUT_LAYER, "Output layer with selected features"))
4444

0 commit comments

Comments
 (0)
Please sign in to comment.