From b5d323c583a9878041bf2ea2082164094a90f605 Mon Sep 17 00:00:00 2001 From: Alexander Bruy Date: Thu, 21 May 2020 12:23:27 +0300 Subject: [PATCH 1/2] [processing] fix handling for stdout and file outputs in GRASS algorithms when temporary files are used --- .../processing/algs/grass7/Grass7Algorithm.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/python/plugins/processing/algs/grass7/Grass7Algorithm.py b/python/plugins/processing/algs/grass7/Grass7Algorithm.py index 9c035614511c..6b5cdfcf7451 100644 --- a/python/plugins/processing/algs/grass7/Grass7Algorithm.py +++ b/python/plugins/processing/algs/grass7/Grass7Algorithm.py @@ -116,6 +116,7 @@ def __init__(self, descriptionfile): self.commands = [] self.outputCommands = [] self.exportedLayers = {} + self.fileOutputs = {} self.descriptionFile = descriptionfile # Default GRASS parameters @@ -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 @@ -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 @@ -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 From 938dc618b185e9b61abf137333458616efb98812 Mon Sep 17 00:00:00 2001 From: Alexander Bruy Date: Fri, 22 May 2020 11:13:22 +0300 Subject: [PATCH 2/2] update algorithms which use "ext" mechanism --- python/plugins/processing/algs/grass7/Grass7Algorithm.py | 3 +++ python/plugins/processing/algs/grass7/ext/i_cluster.py | 1 + python/plugins/processing/algs/grass7/ext/i_gensig.py | 1 + python/plugins/processing/algs/grass7/ext/i_gensigset.py | 1 + 4 files changed, 6 insertions(+) diff --git a/python/plugins/processing/algs/grass7/Grass7Algorithm.py b/python/plugins/processing/algs/grass7/Grass7Algorithm.py index 6b5cdfcf7451..4f02a5b43a0f 100644 --- a/python/plugins/processing/algs/grass7/Grass7Algorithm.py +++ b/python/plugins/processing/algs/grass7/Grass7Algorithm.py @@ -445,6 +445,9 @@ def processAlgorithm(self, original_parameters, context, feedback): outName = out.name() if outName in parameters: if outName in self.fileOutputs: + print('ADD', outName) + print('VAL', parameters[outName]) + print('VAL 2', self.fileOutputs[outName]) outputs[outName] = self.fileOutputs[outName] else: outputs[outName] = parameters[outName] diff --git a/python/plugins/processing/algs/grass7/ext/i_cluster.py b/python/plugins/processing/algs/grass7/ext/i_cluster.py index b7ed20af6982..ab82fb946867 100644 --- a/python/plugins/processing/algs/grass7/ext/i_cluster.py +++ b/python/plugins/processing/algs/grass7/ext/i_cluster.py @@ -41,6 +41,7 @@ def processCommand(alg, parameters, context, feedback): # Re-add signature files parameters['signaturefile'] = signatureFile + alg.fileOutputs['signaturefile'] = signatureFile # Export signature file exportSigFile(alg, group, subgroup, signatureFile) diff --git a/python/plugins/processing/algs/grass7/ext/i_gensig.py b/python/plugins/processing/algs/grass7/ext/i_gensig.py index dfb9001975ed..6c2c01f6dbaa 100644 --- a/python/plugins/processing/algs/grass7/ext/i_gensig.py +++ b/python/plugins/processing/algs/grass7/ext/i_gensig.py @@ -37,6 +37,7 @@ def processCommand(alg, parameters, context, feedback): # Re-add signature files parameters['signaturefile'] = signatureFile + alg.fileOutputs['signaturefile'] = signatureFile # Export signature file exportSigFile(alg, group, subgroup, signatureFile) diff --git a/python/plugins/processing/algs/grass7/ext/i_gensigset.py b/python/plugins/processing/algs/grass7/ext/i_gensigset.py index c935dbf0e571..19a7de54db4e 100644 --- a/python/plugins/processing/algs/grass7/ext/i_gensigset.py +++ b/python/plugins/processing/algs/grass7/ext/i_gensigset.py @@ -37,6 +37,7 @@ def processCommand(alg, parameters, context, feedback): # Re-add signature files parameters['signaturefile'] = signatureFile + alg.fileOutputs['signaturefile'] = signatureFile # Export signature file exportSigFile(alg, group, subgroup, signatureFile, 'sigset')