g.message.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <h2>DESCRIPTION</h2>
  2. <p>This program is to be used in Shell/Perl/Python scripts, so the author does not
  3. need to use the <tt>echo</tt> program. The advantage of <em>g.message</em> is
  4. that it formats messages just like other GRASS modules do and that its
  5. functionality is influenced by the <tt>GRASS_VERBOSE</tt> and
  6. <tt>GRASS_MESSAGE_FORMAT</tt> environment variables.
  7. <p>
  8. The program can be used for standard informative messages as well as warnings
  9. (<b>-w</b> flag) and fatal errors (<b>-e</b> flag). For debugging
  10. purposes, the <b>-d</b> flag will cause <em>g.message</em> to print a debugging
  11. message at the given level.
  12. <h2>NOTES</h2>
  13. Messages containing "<tt>=</tt>" must use the full <b>message=</b> syntax so
  14. the parser doesn't get confused.
  15. <p>
  16. If you want a long message (multi-line) to be dealt with as a single
  17. paragraph, use a single call to <em>g.message</em> with text split in the
  18. script using the backslash as the last character. (In shell scripts don't
  19. close the "quote")
  20. <p>
  21. A blank line may be obtained with
  22. <div class="code"><pre>
  23. g.message message=""
  24. </pre></div>
  25. <p>
  26. Redundant whitespace will be stripped away.
  27. <p>
  28. It's advisable to single quote the messages that are to be printed literally.
  29. It prevents a number of characters (most notably, space and the dollar sign
  30. '<tt>$</tt>') from being treated specifically by the shell.
  31. <p>
  32. When it is necessary to include, for example, a variable's value as part of
  33. the message, the double quotes may be used, which do not deprive the
  34. dollar sign of its special variable-expansion powers.
  35. <p>
  36. While it is known that the interactive Bash instances may treat the
  37. exclamation mark '<tt>!</tt>' character specifically (making single quoting
  38. of it necessary), it shouldn't be the case for the non-interactive
  39. instances of Bash. Nonetheless, to avoid context-based confusion later on
  40. you are enouraged to single-quote messages that do not require
  41. <tt>$VARIABLE</tt> expansion.
  42. <h3>Usage in Python scripts</h3>
  43. <a href="http://grass.osgeo.org/grass70/manuals/libpython/">GRASS
  44. Python Scripting Library</a> defines special wrappers
  45. for <em>g.message</em>.
  46. <ul>
  47. <li><tt>debug()</tt> for <tt>g.message -d</tt>
  48. <li><tt>error()</tt> for <tt>g.message -e</tt>
  49. <li><tt>fatal()</tt> for <tt>g.message -e</tt> + <tt>exit()</tt>
  50. <li><tt>info()</tt> for <tt>g.message -i</tt>
  51. <li><tt>message()</tt> for <tt>g.message</tt>
  52. <li><tt>verbose()</tt> for <tt>g.message -v</tt>
  53. <li><tt>warning()</tt> for <tt>g.message -w</tt>
  54. </ul>
  55. <p>
  56. Note: The Python shell in the <em>wxGUI</em> can be used for entering the
  57. following sample code:
  58. <p>
  59. <div class="code"><pre>
  60. import grass.script as gcore
  61. gcore.warning("This is a warning")
  62. </pre></div>
  63. is identical with
  64. <div class="code"><pre>
  65. g.message -w message="This is a warning"
  66. </pre></div>
  67. <h3>VERBOSITY LEVELS</h3>
  68. Controlled by the "<tt>GRASS_VERBOSE</tt>" environment variable. Typically this
  69. is set using the <b>--quiet</b> or <b>--verbose</b> command line options.
  70. <ul>
  71. <li>0 - only errors and warnings are printed
  72. <li>1 - progress messages are printed
  73. <li>2 - all module messages are printed
  74. <li>3 - additional verbose messages are printed
  75. </ul>
  76. <h3>DEBUG LEVELS</h3>
  77. Controlled by the "<tt>DEBUG</tt>" GRASS <i>gisenv</i> variable (set with
  78. <em><a href="g.gisenv.html">g.gisenv</a></em>).
  79. <br>
  80. Recommended levels:
  81. <ul>
  82. <li>1 - message is printed once or few times per module
  83. <li>3 - each row (raster) or line (vector)
  84. <li>5 - each cell (raster) or point (vector)
  85. </ul>
  86. <h2>SEE ALSO</h2>
  87. <em>
  88. <a href="variables.html">GRASS variables and environment variables</a><br>
  89. <a href="g.gisenv.html">g.gisenv</a>,
  90. <a href="g.parser.html">g.parser</a>
  91. </em>
  92. <h2>AUTHOR</h2>
  93. Jachym Cepicky
  94. <p>
  95. <i>Last changed: $Date$</i>