Skip to content

Commit

Permalink
Added some checks for external apps configuration
Browse files Browse the repository at this point in the history
git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@100 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
volayaf@gmail.com committed Apr 16, 2012
1 parent 403cce2 commit 92b7dfd
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 14 deletions.
2 changes: 0 additions & 2 deletions src/sextante/SextantePlugin.py
Expand Up @@ -26,8 +26,6 @@ def __init__(self, iface):
QGisLayers.setInterface(iface)
Sextante.initialize()
Sextante.setInterface(iface)
SextanteExternalAppsConfigurer.autoConfigure()


def initGui(self):
self.toolbox = SextanteToolbox(self.iface)
Expand Down
2 changes: 1 addition & 1 deletion src/sextante/core/SextanteExternalAppsConfigurer.py
Expand Up @@ -3,7 +3,7 @@
class SextanteExternalAppsConfigurer():

@staticmethod
def autoConfigure():
def checkSettings():
IS_FIRST_USAGE = "IS_FIRST_USAGE"
settings = QtCore.QSettings()
if not settings.contains(IS_FIRST_USAGE):
Expand Down
2 changes: 1 addition & 1 deletion src/sextante/grass/GrassAlgorithmProvider.py
Expand Up @@ -18,7 +18,7 @@ def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
if SextanteUtils.isWindows():
SextanteConfig.addSetting(Setting("GRASS", GrassUtils.GRASS_FOLDER, "GRASS folder", GrassUtils.grassPath()))
SextanteConfig.addSetting(Setting("GRASS", GrassUtils.GRASS_WIN_SHELL, "Shell executable", GrassUtils.grassWinShell()))
SextanteConfig.addSetting(Setting("GRASS", GrassUtils.GRASS_WIN_SHELL, "Msys folder", GrassUtils.grassWinShell()))
SextanteConfig.addSetting(Setting("GRASS", GrassUtils.GRASS_AUTO_REGION, "Use min covering region", True))
SextanteConfig.addSetting(Setting("GRASS", GrassUtils.GRASS_LATLON, "Coordinates are lat/lon", False))
SextanteConfig.addSetting(Setting("GRASS", GrassUtils.GRASS_REGION_XMIN, "GRASS Region min x", 0))
Expand Down
19 changes: 14 additions & 5 deletions src/sextante/grass/GrassUtils.py
Expand Up @@ -5,6 +5,7 @@
from sextante.core.SextanteLog import SextanteLog
import stat
import shutil
import plugin_installer

class GrassUtils:

Expand Down Expand Up @@ -39,7 +40,13 @@ def grassScriptFilename():
def grassPath():
folder = SextanteConfig.getSetting(GrassUtils.GRASS_FOLDER)
if folder == None:
folder =""
folder = plugin_installer.__file__
idx = folder.find('qgis')
folder = folder[:idx] + "grass"
for subfolder in os.listdir(folder):
if subfolder.startswith("grass"):
folder = folder + os.sep + subfolder
break

return folder

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

@staticmethod
def grassWinShell():
shell = SextanteConfig.getSetting(GrassUtils.GRASS_WIN_SHELL)
if shell == None:
shell =""
folder = SextanteConfig.getSetting(GrassUtils.GRASS_WIN_SHELL)
if folder == None:
folder = plugin_installer.__file__
idx = folder.find('qgis')
folder = folder[:idx] + "msys"

return shell
return folder

@staticmethod
def grassDescriptionPath():
Expand Down
27 changes: 24 additions & 3 deletions src/sextante/r/RAlgorithm.py
@@ -1,3 +1,7 @@
import os
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import QtGui, QtCore
from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.parameters.ParameterRaster import ParameterRaster
from sextante.parameters.ParameterTable import ParameterTable
Expand All @@ -10,15 +14,14 @@
from sextante.parameters.ParameterString import ParameterString
from sextante.parameters.ParameterNumber import ParameterNumber
from sextante.parameters.ParameterBoolean import ParameterBoolean
import os
from sextante.parameters.ParameterSelection import ParameterSelection
from PyQt4 import QtGui
from sextante.parameters.ParameterTableField import ParameterTableField
from sextante.outputs.OutputHTML import OutputHTML
from sextante.r.RUtils import RUtils
from sextante.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from sextante.core.SextanteLog import SextanteLog
from sextante.core.SextanteUtils import SextanteUtils
import subprocess

class RAlgorithm(GeoAlgorithm):

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


def checkBeforeOpeningParametersDialog(self):
if SextanteUtils.isWindows():
path = RUtils.RFolder()
if path == "":
return "R folder is not configured.\nPlease configure it before running R scripts."
else:
R_INSTALLED = "R_INSTALLED"
settings = QSettings()
if settings.contains(R_INSTALLED):
return
command = ["R CMD BATCH"]
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE,stderr=subprocess.STDOUT, universal_newlines=True).stdout
for line in iter(proc.readline, ""):
if "no input file" in line:
settings.setValue(R_INSTALLED, True)
return
return "It seems that SAGA is not correctly installed in your system.\nPlease install it before running SAGA algorithms."

19 changes: 18 additions & 1 deletion src/sextante/saga/SagaAlgorithm.py
Expand Up @@ -23,6 +23,7 @@
from sextante.parameters.ParameterNumber import ParameterNumber
from sextante.parameters.ParameterSelection import ParameterSelection
from sextante.core.LayerExporter import LayerExporter
import subprocess

class SagaAlgorithm(GeoAlgorithm):

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



def checkBeforeOpeningParametersDialog(self):
if SextanteUtils.isWindows():
path = SagaUtils.sagaPath()
if path == "":
return "SAGA folder is not configured.\nPlease configure it before running SAGA algorithms."
else:
SAGA_INSTALLED = "SAGA_INSTALLED"
settings = QSettings()
if settings.contains(SAGA_INSTALLED):
return
command = ["saga_cmd"]
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE,stderr=subprocess.STDOUT, universal_newlines=True).stdout
for line in iter(proc.readline, ""):
if "-------------" in line:
settings.setValue(SAGA_INSTALLED, True)
return
return "It seems that SAGA is not correctly installed in your system.\nPlease install it before running SAGA algorithms."

2 changes: 1 addition & 1 deletion src/sextanteexampleprovider/ExampleAlgorithm.py
Expand Up @@ -38,7 +38,7 @@ def defineCharacteristics(self):
#we add the input vector layer. It can have any kind of geometry
#It is a mandatory (not optional) one, hence the False argument
self.addParameter(ParameterVector(self.INPUT_LAYER, "Input layer", ParameterVector.VECTOR_TYPE_ANY, False))

self.addParameter(ParameterExtent("EXTENT","EXTENT"))
# we add a vector layer as output
self.addOutput(OutputVector(self.OUTPUT_LAYER, "Output layer with selected features"))

Expand Down

0 comments on commit 92b7dfd

Please sign in to comment.