Skip to content
Permalink
Browse files

[processing] better initialization of SAGA provider

  • Loading branch information
volaya committed Jun 23, 2015
1 parent cdf034a commit 77ca802522df1bcaa1c1db560dd649a5ca53419b
@@ -54,7 +54,6 @@ def __init__(self):
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 @@ def _loadAlgorithms(self):
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)
@@ -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()]

0 comments on commit 77ca802

Please sign in to comment.
You can’t perform that action at this time.