Skip to content

Commit

Permalink
[sextante] add mechanism to allow easily piping grass console output …
Browse files Browse the repository at this point in the history
…to text file
  • Loading branch information
volaya committed Apr 11, 2013
1 parent 3034a46 commit 5a6562a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
11 changes: 8 additions & 3 deletions python/plugins/sextante/grass/GrassAlgorithm.py
Expand Up @@ -294,9 +294,14 @@ def processAlgorithm(self, progress):
uniqueSufix = str(uuid.uuid4()).replace("-","");
for out in self.outputs:
if isinstance(out, OutputFile):
command+=(" " + out.name + "=\"" + out.value + "\"");
elif not isinstance(out, OutputHTML): #html files are not generated by grass, only by sextante to decorate grass output
#an output name to make sure it is unique if the session uses this algorithm several times
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 + "\"");
elif not isinstance(out, OutputHTML):
#html files are not generated by GRASS, only by SEXTANTE 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
uniqueOutputName = out.name + uniqueSufix
command += (" " + out.name + "=" + uniqueOutputName)
# add output file to exported layers, to indicate that they are present in GRASS
Expand Down
1 change: 1 addition & 0 deletions python/plugins/sextante/grass/description/r.quantile.txt
Expand Up @@ -5,3 +5,4 @@ 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|Output report
OutputFile|outputtext|Output text file
16 changes: 16 additions & 0 deletions python/plugins/sextante/grass/grass.txt
Expand Up @@ -76,3 +76,19 @@ to tag a parameter as "advanced", just add "*" before its declaration. For insta
*ParameterBoolean|-c|-c|True


ADVANCED OUTPUT PROCESSING
-------------------------

In some cases, it might be interesting to take the console otput from GRASS and extract a part of it for saving or formatting.

Two things can be done about this:

-Creating an HTML file with output. Just add an output of type OutputHTML.
It's value will not be passed to GRASS, but you can use it later to create the HTML file from the console output.
You should create a python file in the grass/ext package, with the same name as the grass module, with dots replaced by low hyphens
(for instance r_quantile.py for the r.quantile command), and add a postProcessResults(alg) method. It will be called when the
execution of the GRASS command is finished.
-Creating a text file. Do as above, but adding an otput of type OutputFile. Since some GRASS commands might use this type of output,
and to make sure that the value of this output is not passed to the GRASS comman when calling it, the output has to be named 'outputtext'


0 comments on commit 5a6562a

Please sign in to comment.