[processing] better initialization of SAGA provider

This commit is contained in:
volaya 2015-06-23 12:01:21 +02:00
parent cdf034a999
commit 77ca802522
2 changed files with 25 additions and 16 deletions

View File

@ -54,7 +54,6 @@ class SagaAlgorithmProvider(AlgorithmProvider):
self.activate = True
def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
if isWindows() or isMac():
ProcessingConfig.addSetting(Setting("SAGA",
SagaUtils.SAGA_FOLDER, self.tr('SAGA folder'), ''))
@ -92,7 +91,7 @@ class SagaAlgorithmProvider(AlgorithmProvider):
return
folder = SagaUtils.sagaDescriptionPath()
folder = os.path.join(folder, self.supportedVersions[SagaUtils.getSagaInstalledVersion()][0])
folder = os.path.join(folder, self.supportedVersions[version][0])
for descriptionFile in os.listdir(folder):
if descriptionFile.endswith('txt'):
f = os.path.join(folder, descriptionFile)

View File

@ -106,16 +106,21 @@ def getSagaInstalledVersion(runSaga=False):
global _installedVersion
global _installedVersionFound
if not _installedVersionFound or runSaga:
if isWindows():
commands = [os.path.join(sagaPath(), "saga_cmd.exe"), "-v"]
elif isMac():
commands = [os.path.join(sagaPath(), "saga_cmd"), "-v"]
else:
# for Linux use just one string instead of separated parameters as the list
# does not work well together with shell=True option
# (python docs advices to use subprocess32 instead of python2.7's subprocess)
commands = ["saga_cmd -v"]
maxRetries = 5
retries = 0
if _installedVersionFound or not runSaga:
return _installedVersion
if isWindows():
commands = [os.path.join(sagaPath(), "saga_cmd.exe"), "-v"]
elif isMac():
commands = [os.path.join(sagaPath(), "saga_cmd -v")]
else:
# for Linux use just one string instead of separated parameters as the list
# does not work well together with shell=True option
# (python docs advices to use subprocess32 instead of python2.7's subprocess)
commands = ["saga_cmd -v"]
while retries < maxRetries:
proc = subprocess.Popen(
commands,
shell=True,
@ -126,14 +131,19 @@ def getSagaInstalledVersion(runSaga=False):
).stdout
try:
lines = proc.readlines()
for line in lines:
if line.startswith("SAGA Version:"):
_installedVersion = line[len("SAGA Version:"):].strip().split(" ")[0]
_installedVersionFound = True
return _installedVersion
except IOError:
retries += 1
except:
return None
for line in lines:
if line.startswith("SAGA Version:"):
_installedVersion = line[len("SAGA Version:"):].strip().split(" ")[0]
_installedVersionFound = True
return _installedVersion
def executeSaga(progress):
if isWindows():
command = ['cmd.exe', '/C ', sagaBatchJobFilename()]