Skip to content
Permalink
Browse files

[processing] fixed text and html output in GRASS algorithms

This changes the way text outputs are handled.
Now the output of the command is piped to a file, and with that file, the raw and HTML outputs are generated.

More formatting for the HTML file should be added in the future, since it is now rather basic

fixes #6379
  • Loading branch information
volaya committed Jun 23, 2015
1 parent 77ca802 commit a842d475126d3dd368f7af45278015420149a1ae
Showing with 36 additions and 967 deletions.
  1. +0 −2 python/plugins/processing/algs/grass/CMakeLists.txt
  2. +15 −27 python/plugins/processing/algs/grass/GrassAlgorithm.py
  3. +2 −1 python/plugins/processing/algs/grass/GrassUtils.py
  4. +0 −1 python/plugins/processing/algs/grass/description/r.horizon.height.txt
  5. +1 −2 python/plugins/processing/algs/grass/description/r.quantile.txt
  6. +0 −3 python/plugins/processing/algs/grass/ext/CMakeLists.txt
  7. +0 −39 python/plugins/processing/algs/grass/ext/HtmlReportPostProcessor.py
  8. 0 python/plugins/processing/algs/grass/ext/__init__.py
  9. +0 −32 python/plugins/processing/algs/grass/ext/r_coin.py
  10. +0 −32 python/plugins/processing/algs/grass/ext/r_covar.py
  11. +0 −32 python/plugins/processing/algs/grass/ext/r_describe.py
  12. +0 −32 python/plugins/processing/algs/grass/ext/r_info.py
  13. +0 −32 python/plugins/processing/algs/grass/ext/r_regression_line.py
  14. +0 −32 python/plugins/processing/algs/grass/ext/r_report.py
  15. +0 −32 python/plugins/processing/algs/grass/ext/r_stats.py
  16. +0 −32 python/plugins/processing/algs/grass/ext/r_sum.py
  17. +0 −32 python/plugins/processing/algs/grass/ext/v_class.py
  18. +0 −32 python/plugins/processing/algs/grass/ext/v_info.py
  19. +0 −32 python/plugins/processing/algs/grass/ext/v_normal.py
  20. +0 −32 python/plugins/processing/algs/grass/ext/v_report.py
  21. +0 −32 python/plugins/processing/algs/grass/ext/v_univar.py
  22. +4 −13 python/plugins/processing/algs/grass/grass.txt
  23. +0 −2 python/plugins/processing/algs/grass7/CMakeLists.txt
  24. +11 −27 python/plugins/processing/algs/grass7/Grass7Algorithm.py
  25. +0 −1 python/plugins/processing/algs/grass7/Grass7Utils.py
  26. +1 −2 python/plugins/processing/algs/grass7/description/r.horizon.height.txt
  27. +1 −2 python/plugins/processing/algs/grass7/description/r.quantile.txt
  28. +1 −2 python/plugins/processing/algs/grass7/description/r.surf.area.txt
  29. +0 −3 python/plugins/processing/algs/grass7/ext/CMakeLists.txt
  30. +0 −40 python/plugins/processing/algs/grass7/ext/HtmlReportPostProcessor.py
  31. 0 python/plugins/processing/algs/grass7/ext/__init__.py
  32. +0 −32 python/plugins/processing/algs/grass7/ext/r_coin.py
  33. +0 −32 python/plugins/processing/algs/grass7/ext/r_covar.py
  34. +0 −32 python/plugins/processing/algs/grass7/ext/r_describe.py
  35. +0 −32 python/plugins/processing/algs/grass7/ext/r_info.py
  36. +0 −32 python/plugins/processing/algs/grass7/ext/r_regression_line.py
  37. +0 −32 python/plugins/processing/algs/grass7/ext/r_report.py
  38. +0 −32 python/plugins/processing/algs/grass7/ext/r_stats.py
  39. +0 −32 python/plugins/processing/algs/grass7/ext/v_class.py
  40. +0 −32 python/plugins/processing/algs/grass7/ext/v_info.py
  41. +0 −32 python/plugins/processing/algs/grass7/ext/v_normal.py
  42. +0 −32 python/plugins/processing/algs/grass7/ext/v_report.py
  43. +0 −32 python/plugins/processing/algs/grass7/ext/v_univar.py
@@ -2,7 +2,5 @@ FILE(GLOB PY_FILES *.py)
FILE(GLOB OTHER_FILES grass.txt)
FILE(GLOB DESCR_FILES description/*.txt)

ADD_SUBDIRECTORY(ext)

PLUGIN_INSTALL(processing algs/grass ${PY_FILES} ${OTHER_FILES})
PLUGIN_INSTALL(processing algs/grass/description ${DESCR_FILES})
@@ -69,10 +69,6 @@ def __init__(self, descriptionfile):
self.defineCharacteristicsFromFile()
self.numExportedLayers = 0

# GRASS console output, needed to do postprocessing in case GRASS
# dumps results to the console
self.consoleOutput = []

def getCopy(self):
newone = GrassAlgorithm(self.descriptionFile)
newone.provider = self.provider
@@ -125,7 +121,7 @@ def defineCharacteristicsFromFile(self):
if isinstance(parameter, ParameterVector):
hasVectorInput = True
if isinstance(parameter, ParameterMultipleInput) \
and parameter.datatype < 3:
and parameter.datatype < 3:
hasVectorInput = True
elif line.startswith('*Parameter'):
param = getParameterFromString(line[1:])
@@ -138,6 +134,9 @@ def defineCharacteristicsFromFile(self):
hasRasterOutput = True
elif isinstance(output, OutputVector):
vectorOutputs += 1
if isinstance(output, OutputHTML):
self.addOutput(OutputFile("rawoutput", output.description +
" (raw output)", "txt"))
line = lines.readline().strip('\n').strip()
except Exception, e:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
@@ -320,17 +319,10 @@ def processAlgorithm(self, progress):
uniqueSufix = str(uuid.uuid4()).replace('-', '')
for out in self.outputs:
if isinstance(out, OutputFile):
if out.name == 'outputtext':
# The 'outputtext' file is generated by piping output
# from GRASS, is not an actual grass command
command += ' > ' + out.value
else:
command += ' ' + out.name + '="' + out.value + '"'
command += ' > ' + out.value
elif not isinstance(out, OutputHTML):
# Html files are not generated by GRASS, only by us to
# decorate GRASS output, so we skip them. An output name
# to make sure it is unique if the session uses this
# algorithm several times.
# We add an output name to make sure it is unique if the session
# uses this algorithm several times.
uniqueOutputName = out.name + uniqueSufix
command += ' ' + out.name + '=' + uniqueOutputName

@@ -394,9 +386,14 @@ def processAlgorithm(self, progress):
loglines.append(line)
if ProcessingConfig.getSetting(GrassUtils.GRASS_LOG_COMMANDS):
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)
self.consoleOutput = GrassUtils.executeGrass(commands, progress,
outputCommands)
self.postProcessResults()
GrassUtils.executeGrass(commands, progress, outputCommands)

for out in self.outputs:
if isinstance(out, OutputHTML):
with open(self.getOutputFromName("rawoutput").value) as f:
rawOutput = "".join(f.readlines())
with open(out.value, "w") as f:
f.write("<pre>%s</pre>" % rawOutput)

# If the session has been created outside of this algorithm, add
# the new GRASS layers to it otherwise finish the session
@@ -405,15 +402,6 @@ def processAlgorithm(self, progress):
else:
GrassUtils.endGrassSession()

def postProcessResults(self):
name = self.commandLineName().replace('.', '_')[len('grass:'):]
try:
module = importlib.import_module('processing.algs.grass.ext.' + name)
except ImportError:
return
if hasattr(module, 'postProcessResults'):
func = getattr(module, 'postProcessResults')
func(self)

def exportVectorLayer(self, orgFilename):

@@ -319,7 +319,8 @@ def executeGrass(commands, progress, outputCommands=None):

if ProcessingConfig.getSetting(GrassUtils.GRASS_LOG_CONSOLE):
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)
return loglines



# GRASS session is used to hold the layers already exported or
# produced in GRASS between multiple calls to GRASS algorithms.
@@ -9,4 +9,3 @@ ParameterNumber|maxdistance|The maximum distance to consider when finding the ho
ParameterString|dist|Sampling distance step coefficient (0.5-1.5)|1.0
ParameterBoolean|-d|Write output in degrees (default is radians)|False
OutputHTML|html|Horizon
OutputFile|outputtext|Horizon (text)
@@ -4,5 +4,4 @@ Raster (r.*)
ParameterRaster|input|Input raster layer|False
ParameterNumber|quantiles|Number of quantiles|2|None|4
*ParameterBoolean|-r|Generate recode rules based on quantile-defined intervals|False
OutputHTML|html|Quantiles
OutputFile|outputtext|Quantiles (text)
OutputHTML|html|Quantiles

This file was deleted.

This file was deleted.

No changes.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit a842d47

Please sign in to comment.
You can’t perform that action at this time.