Skip to content

Commit

Permalink
[processing] better initialization of SAGA provider
Browse files Browse the repository at this point in the history
  • Loading branch information
volaya committed Jun 23, 2015
1 parent cdf034a commit 77ca802
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
3 changes: 1 addition & 2 deletions python/plugins/processing/algs/saga/SagaAlgorithmProvider.py
Expand Up @@ -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'), ''))
Expand Down Expand Up @@ -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)
Expand Down
38 changes: 24 additions & 14 deletions python/plugins/processing/algs/saga/SagaUtils.py
Expand Up @@ -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,
Expand All @@ -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()]
Expand Down

0 comments on commit 77ca802

Please sign in to comment.