Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[sextante] added checking to GRASS algorithms
  • Loading branch information
volaya committed Apr 1, 2013
1 parent 4a560bb commit b5d667c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
13 changes: 13 additions & 0 deletions python/plugins/sextante/grass/GrassAlgorithmProvider.py
Expand Up @@ -84,6 +84,19 @@ def getName(self):

def getIcon(self):
return QIcon(os.path.dirname(__file__) + "/../images/grass.png")

def getPostProcessingErrorMessage(self, wrongLayers):
html = AlgorithmProvider.getPostProcessingErrorMessage(self, wrongLayers)
msg = GrassUtils.checkGrassIsInstalled(True)
html += ("<p>This algorithm requires GRASS to be run. A test to check if GRASS is correctly installed "
"and configured in your system has been performed, with the following result:</p><ul><i>")
if msg is None:
html += "GRASS seems to be correctly installed and configured</li></ul>"
else:
html += msg + "</i></li></ul>"
html += '<p><a href= "http://docs.qgis.org/html/en/docs/user_manual/sextante/3rdParty.html">Click here</a> to know more about how to install and configure GRASS to be used with SEXTANTE</p>'

return html

def getSupportedOutputVectorLayerExtensions(self):
return ["shp"]
Expand Down
30 changes: 30 additions & 0 deletions python/plugins/sextante/grass/GrassUtils.py
Expand Up @@ -16,6 +16,8 @@
* *
***************************************************************************
"""
from sextante.tests.TestData import points
import traceback

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
Expand Down Expand Up @@ -323,6 +325,34 @@ def getSessionLayers():
def addSessionLayers(exportedLayers):
GrassUtils.sessionLayers = dict(GrassUtils.sessionLayers.items() + exportedLayers.items())

@staticmethod
def checkGrassIsInstalled(ignoreRegistrySettings=False):
if SextanteUtils.isWindows():
path = GrassUtils.grassPath()
if path == "":
return "GRASS folder is not configured.\nPlease configure it before running SAGA algorithms."
cmdpath = os.path.join(path, "bin\r.out.exe")
if not os.path.exists(cmdpath):
return ("The specified GRASS folder does not contain a valid set of GRASS modules.\n"
+ "Please, go to the SEXTANTE settings dialog, and check that the GRASS\n"
+ "folder is correctly configured")

if not ignoreRegistrySettings:
GRASS_INSTALLED = "/SextanteQGIS/GrassInstalled"
settings = QSettings()
if settings.contains(GRASS_INSTALLED):
return

try:
from sextante.core.Sextante import runalg
result = runalg("grass:v.voronoi", points(),False,False,"270778.60198,270855.745301,4458921.97814,4458983.8488",-1,0.0001,None)
if not os.path.exists(result['output']):
return "It seems that GRASS is not correctly installed and configured in your system.\nPlease install it before running GRASS algorithms."
except:
s = traceback.format_exc()
return "Error while checking GRASS installation. GRASS might not be correctly configured.\n" + s;

settings.setValue(GRASS_INSTALLED, True)



Expand Down

0 comments on commit b5d667c

Please sign in to comment.