mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
[processing] better initialization of SAGA provider
This commit is contained in:
parent
cdf034a999
commit
77ca802522
@ -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)
|
||||
|
@ -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()]
|
||||
|
Loading…
x
Reference in New Issue
Block a user