Skip to content

Commit 585db64

Browse files
authoredMay 24, 2020
Merge pull request #36618 from alexbruy/grass-tempfile
[processing] fix handling for stdout and file outputs in GRASS
2 parents d73eaa1 + 938dc61 commit 585db64

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed
 

‎python/plugins/processing/algs/grass7/Grass7Algorithm.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ def __init__(self, descriptionfile):
116116
self.commands = []
117117
self.outputCommands = []
118118
self.exportedLayers = {}
119+
self.fileOutputs = {}
119120
self.descriptionFile = descriptionfile
120121

121122
# Default GRASS parameters
@@ -398,6 +399,7 @@ def processAlgorithm(self, original_parameters, context, feedback):
398399
self.commands = []
399400
self.outputCommands = []
400401
self.exportedLayers = {}
402+
self.fileOutputs = {}
401403

402404
# If GRASS session has been created outside of this algorithm then
403405
# get the list of layers loaded in GRASS otherwise start a new
@@ -442,9 +444,15 @@ def processAlgorithm(self, original_parameters, context, feedback):
442444
for out in self.outputDefinitions():
443445
outName = out.name()
444446
if outName in parameters:
445-
outputs[outName] = parameters[outName]
447+
if outName in self.fileOutputs:
448+
print('ADD', outName)
449+
print('VAL', parameters[outName])
450+
print('VAL 2', self.fileOutputs[outName])
451+
outputs[outName] = self.fileOutputs[outName]
452+
else:
453+
outputs[outName] = parameters[outName]
446454
if isinstance(out, QgsProcessingOutputHtml):
447-
self.convertToHtml(parameters[outName])
455+
self.convertToHtml(self.fileOutputs[outName])
448456

449457
return outputs
450458

@@ -643,23 +651,18 @@ def processCommand(self, parameters, context, feedback, delOutputs=False):
643651
# For File destination
644652
if isinstance(out, QgsProcessingParameterFileDestination):
645653
if outName in parameters and parameters[outName] is not None:
654+
outPath = self.parameterAsFileOutput(parameters, outName, context)
655+
self.fileOutputs[outName] = outPath
646656
# for HTML reports, we need to redirect stdout
647657
if out.defaultFileExtension().lower() == 'html':
648658
if outName == 'html':
649659
# for "fake" outputs redirect command stdout
650-
command += ' > "{}"'.format(
651-
self.parameterAsFileOutput(
652-
parameters, outName, context)
653-
)
660+
command += ' > "{}"'.format(outPath)
654661
else:
655662
# for real outputs only output itself should be redirected
656-
command += ' {}=- > "{}"'.format(
657-
outName,
658-
self.parameterAsFileOutput(parameters, outName, context))
663+
command += ' {}=- > "{}"'.format(outName, outPath)
659664
else:
660-
command += ' {}="{}"'.format(
661-
outName,
662-
self.parameterAsFileOutput(parameters, outName, context))
665+
command += ' {}="{}"'.format(outName, outPath)
663666
# For folders destination
664667
elif isinstance(out, QgsProcessingParameterFolderDestination):
665668
# We need to add a unique temporary basename

‎python/plugins/processing/algs/grass7/ext/i_cluster.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def processCommand(alg, parameters, context, feedback):
4141

4242
# Re-add signature files
4343
parameters['signaturefile'] = signatureFile
44+
alg.fileOutputs['signaturefile'] = signatureFile
4445

4546
# Export signature file
4647
exportSigFile(alg, group, subgroup, signatureFile)

‎python/plugins/processing/algs/grass7/ext/i_gensig.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def processCommand(alg, parameters, context, feedback):
3737

3838
# Re-add signature files
3939
parameters['signaturefile'] = signatureFile
40+
alg.fileOutputs['signaturefile'] = signatureFile
4041

4142
# Export signature file
4243
exportSigFile(alg, group, subgroup, signatureFile)

‎python/plugins/processing/algs/grass7/ext/i_gensigset.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def processCommand(alg, parameters, context, feedback):
3737

3838
# Re-add signature files
3939
parameters['signaturefile'] = signatureFile
40+
alg.fileOutputs['signaturefile'] = signatureFile
4041

4142
# Export signature file
4243
exportSigFile(alg, group, subgroup, signatureFile, 'sigset')

0 commit comments

Comments
 (0)
Please sign in to comment.