Skip to content

Commit

Permalink
[processing] fix handling for stdout and file outputs in GRASS
Browse files Browse the repository at this point in the history
algorithms when temporary files are used

(cherry picked from commit b5d323c)
  • Loading branch information
alexbruy authored and nyalldawson committed Jun 19, 2020
1 parent 3e68ae9 commit 3e427b3
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions python/plugins/processing/algs/grass7/Grass7Algorithm.py
Expand Up @@ -116,6 +116,7 @@ def __init__(self, descriptionfile):
self.commands = []
self.outputCommands = []
self.exportedLayers = {}
self.fileOutputs = {}
self.descriptionFile = descriptionfile

# Default GRASS parameters
Expand Down Expand Up @@ -398,6 +399,7 @@ def processAlgorithm(self, original_parameters, context, feedback):
self.commands = []
self.outputCommands = []
self.exportedLayers = {}
self.fileOutputs = {}

# If GRASS session has been created outside of this algorithm then
# get the list of layers loaded in GRASS otherwise start a new
Expand Down Expand Up @@ -442,9 +444,12 @@ def processAlgorithm(self, original_parameters, context, feedback):
for out in self.outputDefinitions():
outName = out.name()
if outName in parameters:
outputs[outName] = parameters[outName]
if outName in self.fileOutputs:
outputs[outName] = self.fileOutputs[outName]
else:
outputs[outName] = parameters[outName]
if isinstance(out, QgsProcessingOutputHtml):
self.convertToHtml(parameters[outName])
self.convertToHtml(self.fileOutputs[outName])

return outputs

Expand Down Expand Up @@ -643,23 +648,18 @@ def processCommand(self, parameters, context, feedback, delOutputs=False):
# For File destination
if isinstance(out, QgsProcessingParameterFileDestination):
if outName in parameters and parameters[outName] is not None:
outPath = self.parameterAsFileOutput(parameters, outName, context)
self.fileOutputs[outName] = outPath
# for HTML reports, we need to redirect stdout
if out.defaultFileExtension().lower() == 'html':
if outName == 'html':
# for "fake" outputs redirect command stdout
command += ' > "{}"'.format(
self.parameterAsFileOutput(
parameters, outName, context)
)
command += ' > "{}"'.format(outPath)
else:
# for real outputs only output itself should be redirected
command += ' {}=- > "{}"'.format(
outName,
self.parameterAsFileOutput(parameters, outName, context))
command += ' {}=- > "{}"'.format(outName, outPath)
else:
command += ' {}="{}"'.format(
outName,
self.parameterAsFileOutput(parameters, outName, context))
command += ' {}="{}"'.format(outName, outPath)
# For folders destination
elif isinstance(out, QgsProcessingParameterFolderDestination):
# We need to add a unique temporary basename
Expand Down

0 comments on commit 3e427b3

Please sign in to comment.