fixed saga installation checking

This commit is contained in:
Victor Olaya 2013-09-06 14:17:45 +02:00
parent 5482f14175
commit 6689964b47
2 changed files with 12 additions and 14 deletions

View File

@ -40,7 +40,6 @@ class SagaAlgorithmProvider(AlgorithmProvider):
def __init__(self): def __init__(self):
AlgorithmProvider.__init__(self) AlgorithmProvider.__init__(self)
self.activate = True self.activate = True
self.createAlgsList() #preloading algorithms to speed up
def initializeSettings(self): def initializeSettings(self):
AlgorithmProvider.initializeSettings(self) AlgorithmProvider.initializeSettings(self)
@ -68,34 +67,33 @@ class SagaAlgorithmProvider(AlgorithmProvider):
ProcessingConfig.removeSetting(SagaUtils.SAGA_RESAMPLING_REGION_CELLSIZE) ProcessingConfig.removeSetting(SagaUtils.SAGA_RESAMPLING_REGION_CELLSIZE)
ProcessingConfig.removeSetting(SagaUtils.SAGA_LOG_CONSOLE) ProcessingConfig.removeSetting(SagaUtils.SAGA_LOG_CONSOLE)
ProcessingConfig.removeSetting(SagaUtils.SAGA_LOG_COMMANDS) ProcessingConfig.removeSetting(SagaUtils.SAGA_LOG_COMMANDS)
def createAlgsList(self): def _loadAlgorithms(self):
self.preloadedAlgs = [] self.algs = []
saga208 = ProcessingConfig.getSetting(SagaUtils.SAGA_208) saga208 = ProcessingConfig.getSetting(SagaUtils.SAGA_208)
folder = SagaUtils.sagaDescriptionPath() folder = SagaUtils.sagaDescriptionPath()
for descriptionFile in os.listdir(folder): for descriptionFile in os.listdir(folder):
if descriptionFile.endswith("txt"): if descriptionFile.endswith("txt"):
if not saga208: if not saga208:
if descriptionFile.startswith("2.0.8"): if descriptionFile.startswith("2.0.8"):
continue continue
else: else:
if descriptionFile.startswith("2.1"): if descriptionFile.startswith("2.1"):
continue continue
try: try:
alg = SagaAlgorithm(os.path.join(folder, descriptionFile)) alg = SagaAlgorithm(os.path.join(folder, descriptionFile))
if alg.name.strip() != "": if alg.name.strip() != "":
self.preloadedAlgs.append(alg) self.algs.append(alg)
else: else:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, "Could not open SAGA algorithm: " + descriptionFile) ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, "Could not open SAGA algorithm: " + descriptionFile)
except Exception,e: except Exception,e:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, "Could not open SAGA algorithm: " + descriptionFile +"\n" + str(e)) ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, "Could not open SAGA algorithm: " + descriptionFile +"\n" + str(e))
self.preloadedAlgs.append(SplitRGBBands()) self.algs.append(SplitRGBBands())
def _loadAlgorithms(self):
self.algs = self.preloadedAlgs
def getDescription(self): def getDescription(self):
return "SAGA" saga208 = ProcessingConfig.getSetting(SagaUtils.SAGA_208)
return "SAGA (2.0.8)" if saga208 else "SAGA (2.1)"
def getName(self): def getName(self):
return "saga" return "saga"

View File

@ -27,7 +27,7 @@ import os
import stat import stat
import traceback import traceback
import subprocess import subprocess
from processing.tests.TestData import points from processing.tests.TestData import polygons
from processing.core.ProcessingUtils import ProcessingUtils from processing.core.ProcessingUtils import ProcessingUtils
from processing.core.ProcessingConfig import ProcessingConfig from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.ProcessingLog import ProcessingLog from processing.core.ProcessingLog import ProcessingLog
@ -149,7 +149,7 @@ class SagaUtils:
try: try:
from processing import runalg from processing import runalg
result = runalg("saga:polygoncentroids", points(), False, None) result = runalg("saga:polygoncentroids", polygons(), 0, None)
if result is None or not os.path.exists(result['CENTROIDS']): if result is None or not os.path.exists(result['CENTROIDS']):
return "It seems that SAGA is not correctly installed in your system.\nPlease install it before running SAGA algorithms." return "It seems that SAGA is not correctly installed in your system.\nPlease install it before running SAGA algorithms."
except: except: