Skip to content

Commit 77ca802

Browse files
committedJun 23, 2015
[processing] better initialization of SAGA provider
1 parent cdf034a commit 77ca802

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed
 

‎python/plugins/processing/algs/saga/SagaAlgorithmProvider.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ def __init__(self):
5454
self.activate = True
5555

5656
def initializeSettings(self):
57-
AlgorithmProvider.initializeSettings(self)
5857
if isWindows() or isMac():
5958
ProcessingConfig.addSetting(Setting("SAGA",
6059
SagaUtils.SAGA_FOLDER, self.tr('SAGA folder'), ''))
@@ -92,7 +91,7 @@ def _loadAlgorithms(self):
9291
return
9392

9493
folder = SagaUtils.sagaDescriptionPath()
95-
folder = os.path.join(folder, self.supportedVersions[SagaUtils.getSagaInstalledVersion()][0])
94+
folder = os.path.join(folder, self.supportedVersions[version][0])
9695
for descriptionFile in os.listdir(folder):
9796
if descriptionFile.endswith('txt'):
9897
f = os.path.join(folder, descriptionFile)

‎python/plugins/processing/algs/saga/SagaUtils.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,21 @@ def getSagaInstalledVersion(runSaga=False):
106106
global _installedVersion
107107
global _installedVersionFound
108108

109-
if not _installedVersionFound or runSaga:
110-
if isWindows():
111-
commands = [os.path.join(sagaPath(), "saga_cmd.exe"), "-v"]
112-
elif isMac():
113-
commands = [os.path.join(sagaPath(), "saga_cmd"), "-v"]
114-
else:
115-
# for Linux use just one string instead of separated parameters as the list
116-
# does not work well together with shell=True option
117-
# (python docs advices to use subprocess32 instead of python2.7's subprocess)
118-
commands = ["saga_cmd -v"]
109+
maxRetries = 5
110+
retries = 0
111+
if _installedVersionFound or not runSaga:
112+
return _installedVersion
113+
114+
if isWindows():
115+
commands = [os.path.join(sagaPath(), "saga_cmd.exe"), "-v"]
116+
elif isMac():
117+
commands = [os.path.join(sagaPath(), "saga_cmd -v")]
118+
else:
119+
# for Linux use just one string instead of separated parameters as the list
120+
# does not work well together with shell=True option
121+
# (python docs advices to use subprocess32 instead of python2.7's subprocess)
122+
commands = ["saga_cmd -v"]
123+
while retries < maxRetries:
119124
proc = subprocess.Popen(
120125
commands,
121126
shell=True,
@@ -126,14 +131,19 @@ def getSagaInstalledVersion(runSaga=False):
126131
).stdout
127132
try:
128133
lines = proc.readlines()
134+
for line in lines:
135+
if line.startswith("SAGA Version:"):
136+
_installedVersion = line[len("SAGA Version:"):].strip().split(" ")[0]
137+
_installedVersionFound = True
138+
return _installedVersion
139+
except IOError:
140+
retries += 1
129141
except:
130142
return None
131-
for line in lines:
132-
if line.startswith("SAGA Version:"):
133-
_installedVersion = line[len("SAGA Version:"):].strip().split(" ")[0]
134-
_installedVersionFound = True
143+
135144
return _installedVersion
136145

146+
137147
def executeSaga(progress):
138148
if isWindows():
139149
command = ['cmd.exe', '/C ', sagaBatchJobFilename()]

0 commit comments

Comments
 (0)
Please sign in to comment.