[GRASS-dev] making grass modules less verbose

Hallo,

following patch makes GRASS modules able to use --verbose flag or set
GRASS_VERBOSE environment variable.

In the code:

        if (module->verbose)
                    printf("Blah, blah, blah, blah\n");

or

        if (module->verbose)
                    G_percent(row, nrows, 2);

I thing, that according to Eric Steven Raymond, if the program does
not have anything interesting to say, it should say nothing. This is
good for embeding GRASS in some web server application or for some scripts.

But how to use it in old GRASS modules, so that the number of modules,
which must be corrected by hand, is as low as possible? Do you thing,
this is useful? Shall I put apply this to cvs?

Example session:

GRASS 6.3.cvs (spearfish60):~ > export GRASS_VERBOSE=0
GRASS 6.3.cvs (spearfish60):~ > r.example --help

Description:
My first raster module

Keywords:
  keyword1, keyword2, keyword3

Usage:
   r.example [-q] input=name output=name [--overwrite] [--verbose]

Flags:
    -q Quiet
    --o Force overwrite of output files
    --v Verbose module output

Parameters:
    input Name of input raster map
    output Name for output raster map
    
GRASS 6.3.cvs (spearfish60):~ > r.example in=aspect out=aspect
GRASS 6.3.cvs (spearfish60):~ >
GRASS 6.3.cvs (spearfish60):~ > r.example in=aspect out=aspect --v
Blah, blah, blah, blah
93%
GRASS 6.3.cvs (spearfish60):~ >
GRASS 6.3.cvs (spearfish60):~ > export GRASS_VERBOSE=1
GRASS 6.3.cvs (spearfish60):~ > r.example in=aspect out=aspect
Blah, blah, blah, blah
93%
GRASS 6.3.cvs (spearfish60):~ >

Looking forward to your comments

Jachym
--
Jachym Cepicky
e-mail: jachym.cepicky@centrum.cz
URL: http://les-ejk.cz
GPG: http://les-ejk.cz/gnupg_public_key/jachym_cepicky-gpg_public_key.asc
-----------------------------------------
OFFICE:
GDF-Hannover
Mengendamm 16d
30177 Hannover
Germany
e-mail: cepicky@gdf-hannover.de
URL: http://gdf-hannover.de
Tel.: +49 511-39088507

(attachments)

verbose.patch (3.53 KB)

Jachym Cepicky wrote:

following patch makes GRASS modules able to use --verbose flag or set
GRASS_VERBOSE environment variable.

In the code:

        if (module->verbose)
                    printf("Blah, blah, blah, blah\n");

or

        if (module->verbose)
                    G_percent(row, nrows, 2);

I thing, that according to Eric Steven Raymond, if the program does
not have anything interesting to say, it should say nothing. This is
good for embeding GRASS in some web server application or for some scripts.

But how to use it in old GRASS modules, so that the number of modules,
which must be corrected by hand, is as low as possible? Do you thing,
this is useful? Shall I put apply this to cvs?

Personally, I would look to integrate this with G_message(),
G_debug(), G_percent() etc. E.g. unless --verbose is used, or
GRASS_MESSAGE_FORMAT is set, G_message() and G_percent() wouldn't
print anything.

It shouldn't be up to individual modules to perform the checks.
Modules should unconditionally call G_message() etc and leave it up to
the library to determine how to handle this.

--
Glynn Clements <glynn@gclements.plus.com>

hi Glynn,

I fully agree with you. But how to do this the best way? Add new
parameter to the function?

e.g.

    G_percent(row,nrows,2,module)

    so that

    G_percent could call G_percent2(n,d,s,stderr,module->verbose)

Make G_percent(), G_debug() and G_message() read environment variable
GRASS_VERBOSE? I would say, this would be the best solution.

If nobody has any objection to this sollution, I will prepare next patch.

Jachym
    
On Tue, Sep 19, 2006 at 06:22:23PM +0100, Glynn Clements wrote:

Jachym Cepicky wrote:

> following patch makes GRASS modules able to use --verbose flag or set
> GRASS_VERBOSE environment variable.
>
> In the code:
>
> if (module->verbose)
> printf("Blah, blah, blah, blah\n");
>
>
> or
>
> if (module->verbose)
> G_percent(row, nrows, 2);
>
> I thing, that according to Eric Steven Raymond, if the program does
> not have anything interesting to say, it should say nothing. This is
> good for embeding GRASS in some web server application or for some scripts.
>
> But how to use it in old GRASS modules, so that the number of modules,
> which must be corrected by hand, is as low as possible? Do you thing,
> this is useful? Shall I put apply this to cvs?

Personally, I would look to integrate this with G_message(),
G_debug(), G_percent() etc. E.g. unless --verbose is used, or
GRASS_MESSAGE_FORMAT is set, G_message() and G_percent() wouldn't
print anything.

It shouldn't be up to individual modules to perform the checks.
Modules should unconditionally call G_message() etc and leave it up to
the library to determine how to handle this.

--
Glynn Clements <glynn@gclements.plus.com>

--
Jachym Cepicky
e-mail: jachym.cepicky@centrum.cz
URL: http://les-ejk.cz
GPG: http://les-ejk.cz/gnupg_public_key/jachym_cepicky-gpg_public_key.asc
-----------------------------------------
OFFICE:
GDF-Hannover
Mengendamm 16d
30177 Hannover
Germany
e-mail: cepicky@gdf-hannover.de
URL: http://gdf-hannover.de
Tel.: +49 511-39088507

Hi,
i think this is a nice idea.
Some modules are very verbose and with this approach a general
way is provided to handle this verbosity.

Best regards
Soeren

Jachym Cepicky schrieb:

Hallo,

following patch makes GRASS modules able to use --verbose flag or set
GRASS_VERBOSE environment variable.

In the code:

        if (module->verbose)
                    printf("Blah, blah, blah, blah\n");

or

        if (module->verbose)
                    G_percent(row, nrows, 2);

I thing, that according to Eric Steven Raymond, if the program does
not have anything interesting to say, it should say nothing. This is
good for embeding GRASS in some web server application or for some scripts.

But how to use it in old GRASS modules, so that the number of modules,
which must be corrected by hand, is as low as possible? Do you thing,
this is useful? Shall I put apply this to cvs?

Example session:

GRASS 6.3.cvs (spearfish60):~ > export GRASS_VERBOSE=0
GRASS 6.3.cvs (spearfish60):~ > r.example --help

Description:
My first raster module

Keywords:
  keyword1, keyword2, keyword3

Usage:
   r.example [-q] input=name output=name [--overwrite] [--verbose]

Flags:
    -q Quiet
    --o Force overwrite of output files
    --v Verbose module output

Parameters:
    input Name of input raster map
    output Name for output raster map
    GRASS 6.3.cvs (spearfish60):~ > r.example in=aspect out=aspect
GRASS 6.3.cvs (spearfish60):~ >
GRASS 6.3.cvs (spearfish60):~ > r.example in=aspect out=aspect --v
Blah, blah, blah, blah
93%
GRASS 6.3.cvs (spearfish60):~ > GRASS 6.3.cvs (spearfish60):~ > export GRASS_VERBOSE=1
GRASS 6.3.cvs (spearfish60):~ > r.example in=aspect out=aspect Blah, blah, blah, blah
93%
GRASS 6.3.cvs (spearfish60):~ >

Looking forward to your comments

Jachym

------------------------------------------------------------------------

Index: include/gis.h

RCS file: /home/grass/grassrepository/grass6/include/gis.h,v
retrieving revision 1.33
diff -u -r1.33 gis.h
--- include/gis.h 19 Aug 2006 12:52:21 -0000 1.33
+++ include/gis.h 19 Sep 2006 14:43:42 -0000
@@ -570,6 +570,7 @@
     char *keywords; /* Keywords describing module */
   /* further items are possible: author(s), version */
     int overwrite; /* overwrite old files */
+ int verbose; /* print all informations about progres and so on */
};
  struct TimeStamp
Index: lib/gis/parser.c

RCS file: /home/grass/grassrepository/grass6/lib/gis/parser.c,v
retrieving revision 1.85
diff -u -r1.85 parser.c
--- lib/gis/parser.c 17 Sep 2006 21:50:00 -0000 1.85
+++ lib/gis/parser.c 19 Sep 2006 14:43:43 -0000
@@ -136,6 +136,7 @@
static int n_opts = 0 ;
static int n_flags = 0 ;
static int overwrite = 0 ;
+static int verbose = 0 ;
  static struct Flag first_flag; /* First flag in a linked list */
static struct Flag *current_flag; /* Pointer for traversing list */
@@ -171,6 +172,7 @@
static int split_opts();
static int check_multiple_opts();
static int check_overwrite();
+static int check_verbose();
static int interactive( char *);
static int interactive_flag( struct Flag *);
static int interactive_option( struct Option *);
@@ -728,6 +730,12 @@
           overwrite = 1;
       }
+ /* Verbose option */
+ else if ( strcmp(ptr,"--v") == 0 || strcmp(ptr,"--verbose") == 0 )
+ {
+ module_info.verbose = 1;
+ }
+
       /* Force gui to come up */
       else if ( strcmp(ptr,"--ui") == 0 )
       {
@@ -794,6 +802,9 @@
   if ( check_overwrite () )
       return -1;
+ if (check_verbose ())
+ module_info.verbose = 1;
+
   return(0) ;
}
@@ -932,6 +943,10 @@
     len=show(item,len);
   }
+ strcpy (item, " [--verbose]");
+ len=show(item,len);
+
   fprintf (stderr, "\n");
    /* Print help info for flags */
@@ -960,8 +975,9 @@
   }
    if (new_prompt)
- fprintf(stderr," --o %s\n", _("Force overwrite of output files")) ;
-
+ fprintf(stderr," --o %s\n", _("Force overwrite of output files")) ;
+
+ fprintf(stderr," --v %s\n", _("Verbose module output")) ;
    /* Print help info for options */
@@ -1334,9 +1350,10 @@
     }
   }
   if (new_prompt)
- {
     fprintf(stdout, " [--<b>overwrite</b>] ");
- }
+
+ fprintf(stdout, " [--<b>verbose</b>] ");
+
   fprintf(stdout, "\n");

       fprintf(stdout, "<DT><b>--overwrite</b></DT>\n");
       fprintf(stdout, "<DD>Force overwrite of output files</DD>");
     }
+
+ fprintf(stdout, "<DT><b>--verbose</b></DT>\n");
+ fprintf(stdout, "<DD>Verbose module output</DD>");
+
     fprintf(stdout, "</DL>\n");
   }
@@ -2144,6 +2165,34 @@
   }
    return(error) ;
+}
+
+/* Check verbose */
+static int check_verbose (void)
+{
+ char *verstr;
+ int verb;
+
+ verb = 0;
+ /* Check the GRASS VERBOSE variable */
+ if ( (verstr = G__getenv ( "VERBOSE" )) ) {
+ verb = atoi ( verstr );
+ }
+
+ /* Check the GRASS_OVERWRITE environment variable */
+ if ( (verstr = getenv ( "GRASS_VERBOSE" )) ) {
+ if (atoi ( verstr ))
+ verb = 1;
+ }
+
+ if ( verb ) {
+ module_info.verbose = 1;
+ /* Set the environment so that programs run in a script also obey --o */
+ putenv("GRASS_OVERWRITE=1");
+ /* No need to check options for existing files if overwrite is true */
+ }
+
+ return(verb) ;
}
  static int interactive( char *command)

------------------------------------------------------------------------

_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

Hi,

another idea: what about putting all grass messages (G_message,
G_warning, G_percent) to some GRASS_LOG
file, which would be grassdata/location/mapset/.grass.log by default?

The user could see, what's happening, regardless to how GRASS_VERBOSE is
set.

Jachym

On Wed, Sep 20, 2006 at 09:37:36AM +0200, Sören Gebbert wrote:

Hi,
i think this is a nice idea.
Some modules are very verbose and with this approach a general
way is provided to handle this verbosity.

Best regards
Soeren

Jachym Cepicky schrieb:
>Hallo,
>
>following patch makes GRASS modules able to use --verbose flag or set
>GRASS_VERBOSE environment variable.
>
>In the code:
>
> if (module->verbose)
> printf("Blah, blah, blah, blah\n");
>
>
>or
>
> if (module->verbose)
> G_percent(row, nrows, 2);
>
>I thing, that according to Eric Steven Raymond, if the program does
>not have anything interesting to say, it should say nothing. This is
>good for embeding GRASS in some web server application or for some scripts.
>
>But how to use it in old GRASS modules, so that the number of modules,
>which must be corrected by hand, is as low as possible? Do you thing,
>this is useful? Shall I put apply this to cvs?
>
>Example session:
>
>GRASS 6.3.cvs (spearfish60):~ > export GRASS_VERBOSE=0
>GRASS 6.3.cvs (spearfish60):~ > r.example --help
>
>Description:
> My first raster module
>
> Keywords:
> keyword1, keyword2, keyword3
>
> Usage:
> r.example [-q] input=name output=name [--overwrite] [--verbose]
>
> Flags:
> -q Quiet
> --o Force overwrite of output files
> --v Verbose module output
>
>Parameters:
> input Name of input raster map
> output Name for output raster map
>
>GRASS 6.3.cvs (spearfish60):~ > r.example in=aspect out=aspect
>GRASS 6.3.cvs (spearfish60):~ >
>GRASS 6.3.cvs (spearfish60):~ > r.example in=aspect out=aspect --v
>Blah, blah, blah, blah
>93%
>GRASS 6.3.cvs (spearfish60):~ >
>GRASS 6.3.cvs (spearfish60):~ > export GRASS_VERBOSE=1
>GRASS 6.3.cvs (spearfish60):~ > r.example in=aspect out=aspect
>Blah, blah, blah, blah
>93%
>GRASS 6.3.cvs (spearfish60):~ >
>
>Looking forward to your comments
>
>Jachym
>
>
>------------------------------------------------------------------------
>
>Index: include/gis.h
>===================================================================
>RCS file: /home/grass/grassrepository/grass6/include/gis.h,v
>retrieving revision 1.33
>diff -u -r1.33 gis.h
>--- include/gis.h 19 Aug 2006 12:52:21 -0000 1.33
>+++ include/gis.h 19 Sep 2006 14:43:42 -0000
>@@ -570,6 +570,7 @@
> char *keywords; /* Keywords describing module */
> /* further items are possible: author(s), version */
> int overwrite; /* overwrite old files */
>+ int verbose; /* print all informations about progres and so on */
> };
>
> struct TimeStamp
>Index: lib/gis/parser.c
>===================================================================
>RCS file: /home/grass/grassrepository/grass6/lib/gis/parser.c,v
>retrieving revision 1.85
>diff -u -r1.85 parser.c
>--- lib/gis/parser.c 17 Sep 2006 21:50:00 -0000 1.85
>+++ lib/gis/parser.c 19 Sep 2006 14:43:43 -0000
>@@ -136,6 +136,7 @@
> static int n_opts = 0 ;
> static int n_flags = 0 ;
> static int overwrite = 0 ;
>+static int verbose = 0 ;
>
> static struct Flag first_flag; /* First flag in a linked list */
> static struct Flag *current_flag; /* Pointer for traversing list */
>@@ -171,6 +172,7 @@
> static int split_opts();
> static int check_multiple_opts();
> static int check_overwrite();
>+static int check_verbose();
> static int interactive( char *);
> static int interactive_flag( struct Flag *);
> static int interactive_option( struct Option *);
>@@ -728,6 +730,12 @@
> overwrite = 1;
> }
>
>+ /* Verbose option */
>+ else if ( strcmp(ptr,"--v") == 0 ||
>strcmp(ptr,"--verbose") == 0 )
>+ {
>+ module_info.verbose = 1;
>+ }
>+
> /* Force gui to come up */
> else if ( strcmp(ptr,"--ui") == 0 )
> {
>@@ -794,6 +802,9 @@
> if ( check_overwrite () )
> return -1;
>
>+ if (check_verbose ())
>+ module_info.verbose = 1;
>+
> return(0) ;
> }
>
>@@ -932,6 +943,10 @@
> len=show(item,len);
> }
>
>+ strcpy (item, " [--verbose]");
>+ len=show(item,len);
>+
>+
> fprintf (stderr, "\n");
>
> /* Print help info for flags */
>@@ -960,8 +975,9 @@
> }
>
> if (new_prompt)
>- fprintf(stderr," --o %s\n", _("Force overwrite of output
>files")) ;
>-
>+ fprintf(stderr," --o %s\n", _("Force overwrite of output
>files")) ;
>+
>+ fprintf(stderr," --v %s\n", _("Verbose module output")) ;
>
> /* Print help info for options */
>
>@@ -1334,9 +1350,10 @@
> }
> }
> if (new_prompt)
>- {
> fprintf(stdout, " [--<b>overwrite</b>] ");
>- }
>+
>+ fprintf(stdout, " [--<b>verbose</b>] ");
>+
> fprintf(stdout, "\n");
>
>
>@@ -1371,6 +1388,10 @@
> fprintf(stdout, "<DT><b>--overwrite</b></DT>\n");
> fprintf(stdout, "<DD>Force overwrite of output
> files</DD>");
> }
>+
>+ fprintf(stdout, "<DT><b>--verbose</b></DT>\n");
>+ fprintf(stdout, "<DD>Verbose module output</DD>");
>+
> fprintf(stdout, "</DL>\n");
> }
>
>@@ -2144,6 +2165,34 @@
> }
>
> return(error) ;
>+}
>+
>+/* Check verbose */
>+static int check_verbose (void)
>+{
>+ char *verstr;
>+ int verb;
>+
>+ verb = 0;
>+ /* Check the GRASS VERBOSE variable */
>+ if ( (verstr = G__getenv ( "VERBOSE" )) ) {
>+ verb = atoi ( verstr );
>+ }
>+
>+ /* Check the GRASS_OVERWRITE environment variable */
>+ if ( (verstr = getenv ( "GRASS_VERBOSE" )) ) {
>+ if (atoi ( verstr ))
>+ verb = 1;
>+ }
>+
>+ if ( verb ) {
>+ module_info.verbose = 1;
>+ /* Set the environment so that programs run in a script also
>obey --o */
>+ putenv("GRASS_OVERWRITE=1");
>+ /* No need to check options for existing files if overwrite is
>true */
>+ }
>+
>+ return(verb) ;
> }
>
> static int interactive( char *command)
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>grass-dev mailing list
>grass-dev@grass.itc.it
>http://grass.itc.it/mailman/listinfo/grass-dev

--
Jachym Cepicky
e-mail: jachym.cepicky@centrum.cz
URL: http://les-ejk.cz
GPG: http://les-ejk.cz/gnupg_public_key/jachym_cepicky-gpg_public_key.asc
-----------------------------------------
OFFICE:
GDF-Hannover
Mengendamm 16d
30177 Hannover
Germany
e-mail: cepicky@gdf-hannover.de
URL: http://gdf-hannover.de
Tel.: +49 511-39088507

On Wed, Sep 20, 2006 at 09:37:36AM +0200, Sören Gebbert wrote:

Hi,
i think this is a nice idea.
Some modules are very verbose and with this approach a general
way is provided to handle this verbosity.

Best regards
Soeren

I prepared new patch (for current cvs version) which makes all modules
be able to use --verbose flag or to set GRASS_VERBOSE env. variable.

G_message, G_warning and G_percent are now able to handle according to
the user needs.

Could anybody test this?

If this works well and nobody has any objection, I would implement the log file idea.

The hard part will be go throu all modules and replace (f)printf for
G_message(), but I could take care on this. Another thing: parts of g.* and v.* modules do not use G_message at all.

Jachym

--
Jachym Cepicky
e-mail: jachym.cepicky@centrum.cz
URL: http://les-ejk.cz
GPG: http://les-ejk.cz/gnupg_public_key/jachym_cepicky-gpg_public_key.asc
-----------------------------------------
OFFICE:
GDF-Hannover
Mengendamm 16d
30177 Hannover
Germany
e-mail: cepicky@gdf-hannover.de
URL: http://gdf-hannover.de
Tel.: +49 511-39088507

(attachments)

verbose-2.patch (5.22 KB)

Hello Jachym
In order to keep module output as consistent as possible, I feel it might be better to implement this as a "quiet" flag rather than a verbose flag? I.e. by default output continues as normal but if, as you say the modules need to be used in something like an emebedded system with minimal output then the quiet flag could be specified.

I was thinking also it would be a good test for which modules write directly to stderr and which should possibly be changed to use G_message(), if you set the quiet flag before running them. Although G_message() doesn't offer as much flexibility as printing to stderr,
e.g. no backspace or bell.

Paul

On Wed, 20 Sep 2006, Jachym Cepicky wrote:

On Wed, Sep 20, 2006 at 09:37:36AM +0200, Sören Gebbert wrote:

Hi,
i think this is a nice idea.
Some modules are very verbose and with this approach a general
way is provided to handle this verbosity.

Best regards
Soeren

I prepared new patch (for current cvs version) which makes all modules
be able to use --verbose flag or to set GRASS_VERBOSE env. variable.

G_message, G_warning and G_percent are now able to handle according to
the user needs.

Could anybody test this?

If this works well and nobody has any objection, I would implement the log file idea.

The hard part will be go throu all modules and replace (f)printf for
G_message(), but I could take care on this. Another thing: parts of g.* and v.* modules do not use G_message at all.

Jachym

--
Jachym Cepicky
e-mail: jachym.cepicky@centrum.cz
URL: http://les-ejk.cz
GPG: http://les-ejk.cz/gnupg_public_key/jachym_cepicky-gpg_public_key.asc
-----------------------------------------
OFFICE:
GDF-Hannover
Mengendamm 16d
30177 Hannover
Germany
e-mail: cepicky@gdf-hannover.de
URL: http://gdf-hannover.de
Tel.: +49 511-39088507

hallo Paul,

On Wed, Sep 20, 2006 at 11:52:13AM +0100, Paul Kelly wrote:

Hello Jachym
In order to keep module output as consistent as possible, I feel it might
be better to implement this as a "quiet" flag rather than a verbose flag?
I.e. by default output continues as normal but if, as you say the modules
need to be used in something like an emebedded system with minimal output
then the quiet flag could be specified.

http://www.faqs.org/docs/artu/ch11s09.html

I'm not UNIX coder, but I think, I can agree with most of the statemets
listed in this chapter of Art Of Unix Programing:

1) If your CLI program emits status messages to standard output, then
programs that try to interpret that output will be put to the trouble of
interpreting or discarding those messages (even if nothing went wrong!).

*Better to send only real errors to standard error and not to emit
unrequested data at all.*

g.remove (?)

2) The user's vertical screen space is precious.

v.in.ascii (?)

3) Junk messages are a careless waste of the human user's bandwidth.

g.remove

4) In general, it's bad style to tell the user things he already knows.

5) be chatty only about things that deviate from what's normally
expected.

G_fatal_error() will always be printed

This was the reasons, i was thinking about, when adding --verbose
and not --quiet flag. Most of the people do not actually care, that
some module is "opening raster files". The work can be done in
background. --verbose could be first step of debuging info. Because of
the user wants to check the progress of the program, i'm suggesting the
idea of log file, which would be removed after grass session is done.

Anyway, if most of the developers would prefere --quite, it is no
problem to implement this and also to change GRASS_VERBOSE to
GRASS_QUITE.

I was thinking also it would be a good test for which modules write
directly to stderr and which should possibly be changed to use
G_message(), if you set the quiet flag before running them. Although
G_message() doesn't offer as much flexibility as printing to stderr,
e.g. no backspace or bell.

Paul

How difficult would it be to make G_message to be able to print
backspaces or bells?

Jachym

On Wed, 20 Sep 2006, Jachym Cepicky wrote:

>On Wed, Sep 20, 2006 at 09:37:36AM +0200, Sören Gebbert wrote:
>>Hi,
>>i think this is a nice idea.
>>Some modules are very verbose and with this approach a general
>>way is provided to handle this verbosity.
>>
>>Best regards
>>Soeren
>>
>
>I prepared new patch (for current cvs version) which makes all modules
>be able to use --verbose flag or to set GRASS_VERBOSE env. variable.
>
>G_message, G_warning and G_percent are now able to handle according to
>the user needs.
>
>Could anybody test this?
>
>If this works well and nobody has any objection, I would implement the log
>file idea.
>
>The hard part will be go throu all modules and replace (f)printf for
>G_message(), but I could take care on this. Another thing: parts of g.*
>and v.* modules do not use G_message at all.
>
>Jachym
>
>--
>Jachym Cepicky
>e-mail: jachym.cepicky@centrum.cz
>URL: http://les-ejk.cz
>GPG: http://les-ejk.cz/gnupg_public_key/jachym_cepicky-gpg_public_key.asc
>-----------------------------------------
>OFFICE:
>GDF-Hannover
>Mengendamm 16d
>30177 Hannover
>Germany
>e-mail: cepicky@gdf-hannover.de
>URL: http://gdf-hannover.de
>Tel.: +49 511-39088507
>

--
Jachym Cepicky
e-mail: jachym.cepicky@centrum.cz
URL: http://les-ejk.cz
GPG: http://les-ejk.cz/gnupg_public_key/jachym_cepicky-gpg_public_key.asc
-----------------------------------------
OFFICE:
GDF-Hannover
Mengendamm 16d
30177 Hannover
Germany
e-mail: cepicky@gdf-hannover.de
URL: http://gdf-hannover.de
Tel.: +49 511-39088507

Jachym and others,

I want to put my support behind this effort. It helps address an issue I've
run into wrapping GRASS in a GUI--and whined to the list periodically.
Thanks very much.

Michael
__________________________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics and Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton

From: Jachym Cepicky <jachym.cepicky@centrum.cz>
Date: Wed, 20 Sep 2006 13:18:47 +0200
To: Paul Kelly <paul-grass@stjohnspoint.co.uk>
Cc: <grass-dev@grass.itc.it>
Subject: Re: [GRASS-dev] making grass modules less verbose

hallo Paul,

On Wed, Sep 20, 2006 at 11:52:13AM +0100, Paul Kelly wrote:

Hello Jachym
In order to keep module output as consistent as possible, I feel it might
be better to implement this as a "quiet" flag rather than a verbose flag?
I.e. by default output continues as normal but if, as you say the modules
need to be used in something like an emebedded system with minimal output
then the quiet flag could be specified.

http://www.faqs.org/docs/artu/ch11s09.html

I'm not UNIX coder, but I think, I can agree with most of the statemets
listed in this chapter of Art Of Unix Programing:

1) If your CLI program emits status messages to standard output, then
programs that try to interpret that output will be put to the trouble of
interpreting or discarding those messages (even if nothing went wrong!).

*Better to send only real errors to standard error and not to emit
unrequested data at all.*

g.remove (?)

2) The user's vertical screen space is precious.

v.in.ascii (?)

3) Junk messages are a careless waste of the human user's bandwidth.

g.remove

4) In general, it's bad style to tell the user things he already knows.

5) be chatty only about things that deviate from what's normally
expected.

G_fatal_error() will always be printed

This was the reasons, i was thinking about, when adding --verbose
and not --quiet flag. Most of the people do not actually care, that
some module is "opening raster files". The work can be done in
background. --verbose could be first step of debuging info. Because of
the user wants to check the progress of the program, i'm suggesting the
idea of log file, which would be removed after grass session is done.

Anyway, if most of the developers would prefere --quite, it is no
problem to implement this and also to change GRASS_VERBOSE to
GRASS_QUITE.

I was thinking also it would be a good test for which modules write
directly to stderr and which should possibly be changed to use
G_message(), if you set the quiet flag before running them. Although
G_message() doesn't offer as much flexibility as printing to stderr,
e.g. no backspace or bell.

Paul

How difficult would it be to make G_message to be able to print
backspaces or bells?

Jachym

On Wed, 20 Sep 2006, Jachym Cepicky wrote:

On Wed, Sep 20, 2006 at 09:37:36AM +0200, Sören Gebbert wrote:

Hi,
i think this is a nice idea.
Some modules are very verbose and with this approach a general
way is provided to handle this verbosity.

Best regards
Soeren

I prepared new patch (for current cvs version) which makes all modules
be able to use --verbose flag or to set GRASS_VERBOSE env. variable.

G_message, G_warning and G_percent are now able to handle according to
the user needs.

Could anybody test this?

If this works well and nobody has any objection, I would implement the log
file idea.

The hard part will be go throu all modules and replace (f)printf for
G_message(), but I could take care on this. Another thing: parts of g.*
and v.* modules do not use G_message at all.

Jachym

--
Jachym Cepicky
e-mail: jachym.cepicky@centrum.cz
URL: http://les-ejk.cz
GPG: http://les-ejk.cz/gnupg_public_key/jachym_cepicky-gpg_public_key.asc
-----------------------------------------
OFFICE:
GDF-Hannover
Mengendamm 16d
30177 Hannover
Germany
e-mail: cepicky@gdf-hannover.de
URL: http://gdf-hannover.de
Tel.: +49 511-39088507

--
Jachym Cepicky
e-mail: jachym.cepicky@centrum.cz
URL: http://les-ejk.cz
GPG: http://les-ejk.cz/gnupg_public_key/jachym_cepicky-gpg_public_key.asc
-----------------------------------------
OFFICE:
GDF-Hannover
Mengendamm 16d
30177 Hannover
Germany
e-mail: cepicky@gdf-hannover.de
URL: http://gdf-hannover.de
Tel.: +49 511-39088507

Jachym Cepicky wrote:

I fully agree with you. But how to do this the best way? Add new
parameter to the function?

e.g.

    G_percent(row,nrows,2,module)

    so that

    G_percent could call G_percent2(n,d,s,stderr,module->verbose)

Make G_percent(), G_debug() and G_message() read environment variable
GRASS_VERBOSE? I would say, this would be the best solution.

Add a function to query the verbosity level, and change G_percent()
etc to use it.

If there's a GRASS_VERBOSE environment variable, you probably want
both --verbose and --quiet (the latter would disable verbosity even
when GRASS_VERBOSE is set).

--
Glynn Clements <glynn@gclements.plus.com>

Jachym Cepicky wrote:

> i think this is a nice idea.
> Some modules are very verbose and with this approach a general
> way is provided to handle this verbosity.

I prepared new patch (for current cvs version) which makes all modules
be able to use --verbose flag or to set GRASS_VERBOSE env. variable.

G_message, G_warning and G_percent are now able to handle according to
the user needs.

A few comments:

1. G_warning() should not be affected; warnings should be displayed
regardless of the verbosity setting.

2. I would provide a --quiet flag to allow verbosity to be disabled
for individual cases.

3. I wouldn't check for a GRASS variable with G__getenv(), as you
can't override that on a per-process basis.

--
Glynn Clements <glynn@gclements.plus.com>

On Wed, 2006-09-20 at 21:30 +0100, Glynn Clements wrote:

Jachym Cepicky wrote:

> I fully agree with you. But how to do this the best way? Add new
> parameter to the function?
>
> e.g.
>
> G_percent(row,nrows,2,module)
>
> so that
>
> G_percent could call G_percent2(n,d,s,stderr,module->verbose)
>
> Make G_percent(), G_debug() and G_message() read environment variable
> GRASS_VERBOSE? I would say, this would be the best solution.

Add a function to query the verbosity level, and change G_percent()
etc to use it.

If there's a GRASS_VERBOSE environment variable, you probably want
both --verbose and --quiet (the latter would disable verbosity even
when GRASS_VERBOSE is set).

A smaller issue is that of '\n'. G_message("\n") doesn't work well and
the alternative has been to use:

fprintf(stderr, "\n");

Going quiet may yield an extraneous number of CRs depending on the
module...

--
Brad Douglas <rez touchofmadness com> KB8UYR
Address: 37.493,-121.924 / WGS84 National Map Corps #TNMC-3785

On Wed, 2006-09-20 at 11:24 -0700, Michael Barton wrote:

Jachym and others,

I want to put my support behind this effort. It helps address an issue I've
run into wrapping GRASS in a GUI--and whined to the list periodically.
Thanks very much.

Agreed. It'll also have a nice side effect of cleaning up the modules a
bit by not constantly testing a flag for verbosity.

--
Brad Douglas <rez touchofmadness com> KB8UYR
Address: 37.493,-121.924 / WGS84 National Map Corps #TNMC-3785

Brad Douglas wrote:

On Wed, 2006-09-20 at 11:24 -0700, Michael Barton wrote:

Jachym and others,

I want to put my support behind this effort. It helps address an issue I've
run into wrapping GRASS in a GUI--and whined to the list periodically.
Thanks very much.

Agreed. It'll also have a nice side effect of cleaning up the modules a
bit by not constantly testing a flag for verbosity.

+1

Maciek

Dear developers,

third version of the patch + one new file makes GRASS modules to be
verbose according to user's needs.

Currently, 3 levels of verbosity are defined:

    0: Modules will print only errors and warnings (using G_fatal_error and
        G_warning)
    1: Modules can show progres info (e.g. G_percent)
    2: Modules will print all messages, which are usually not importand
    (G_message)

Verbosity level is set via env. variable GRASS_VERBOSE

Two new flags have been added to each module (parser.c), which enables
the user to set the verbosity level on demand:

    --verbose (--v): set verbosity level to maximum
    --quite (--q): set verbosity level to miminum

One new file (lib/gis/verbose.c) has new 3 functions:

int G_verbose() - returns actual verbosity level
int G_verbose_max() - returns maximal level of verbosity (currently 2)
int G_verbose_min() - returns minimal level of verbosity (currently 0)

Problem: I tryed to set env. variable like this:

        char buff[32];
        sprintf(buff,"GRASS_VERBOSE=%d",G_verbose_max());
        putenv(buff);

but it did not work :frowning: how to fix it ? (parser.c, lines 738, 750)

Looking forward to your comments

Jachym

On Wed, Sep 20, 2006 at 09:38:44PM +0100, Glynn Clements wrote:

Jachym Cepicky wrote:

> > i think this is a nice idea.
> > Some modules are very verbose and with this approach a general
> > way is provided to handle this verbosity.
>
> I prepared new patch (for current cvs version) which makes all modules
> be able to use --verbose flag or to set GRASS_VERBOSE env. variable.
>
> G_message, G_warning and G_percent are now able to handle according to
> the user needs.

A few comments:

1. G_warning() should not be affected; warnings should be displayed
regardless of the verbosity setting.

2. I would provide a --quiet flag to allow verbosity to be disabled
for individual cases.

3. I wouldn't check for a GRASS variable with G__getenv(), as you
can't override that on a per-process basis.

--
Glynn Clements <glynn@gclements.plus.com>

--
Jachym Cepicky
e-mail: jachym.cepicky@centrum.cz
URL: http://les-ejk.cz
GPG: http://les-ejk.cz/gnupg_public_key/jachym_cepicky-gpg_public_key.asc
-----------------------------------------
OFFICE:
GDF-Hannover
Mengendamm 16d
30177 Hannover
Germany
e-mail: cepicky@gdf-hannover.de
URL: http://gdf-hannover.de
Tel.: +49 511-39088507

(attachments)

verbose3.patch (7.74 KB)
verbose.c (1.58 KB)

Brad Douglas wrote:

> > I fully agree with you. But how to do this the best way? Add new
> > parameter to the function?
> >
> > e.g.
> >
> > G_percent(row,nrows,2,module)
> >
> > so that
> >
> > G_percent could call G_percent2(n,d,s,stderr,module->verbose)
> >
> > Make G_percent(), G_debug() and G_message() read environment variable
> > GRASS_VERBOSE? I would say, this would be the best solution.
>
> Add a function to query the verbosity level, and change G_percent()
> etc to use it.
>
> If there's a GRASS_VERBOSE environment variable, you probably want
> both --verbose and --quiet (the latter would disable verbosity even
> when GRASS_VERBOSE is set).

A smaller issue is that of '\n'. G_message("\n") doesn't work well and
the alternative has been to use:

fprintf(stderr, "\n");

Going quiet may yield an extraneous number of CRs depending on the
module...

Can you clarify.

G_message() ought to terminate anything it writes.

--
Glynn Clements <glynn@gclements.plus.com>

Jachym Cepicky wrote:

Problem: I tryed to set env. variable like this:

        char buff[32];
        sprintf(buff,"GRASS_VERBOSE=%d",G_verbose_max());
        putenv(buff);

but it did not work :frowning: how to fix it ? (parser.c, lines 738, 750)

putenv() doesn't copy the string, just the pointer. Consequently,
using an automatic (non-"static" local) array won't work; you need to
use e.g. G_store() to make a persistent copy of the string.

--
Glynn Clements <glynn@gclements.plus.com>

This is great. One minor editorial change:

it should be --quiet, not --quite

Thanks for this very useful change.

Michael
__________________________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics and Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton

From: Jachym Cepicky <jachym.cepicky@centrum.cz>
Date: Thu, 21 Sep 2006 13:43:46 +0200
To: Glynn Clements <glynn@gclements.plus.com>
Cc: <grass-dev@grass.itc.it>
Subject: Re: [GRASS-dev] making grass modules less verbose

Dear developers,

third version of the patch + one new file makes GRASS modules to be
verbose according to user's needs.

Currently, 3 levels of verbosity are defined:

    0: Modules will print only errors and warnings (using G_fatal_error and
        G_warning)
    1: Modules can show progres info (e.g. G_percent)
    2: Modules will print all messages, which are usually not importand
    (G_message)

Verbosity level is set via env. variable GRASS_VERBOSE

Two new flags have been added to each module (parser.c), which enables
the user to set the verbosity level on demand:

    --verbose (--v): set verbosity level to maximum
    --quite (--q): set verbosity level to miminum

One new file (lib/gis/verbose.c) has new 3 functions:

int G_verbose() - returns actual verbosity level
int G_verbose_max() - returns maximal level of verbosity (currently 2)
int G_verbose_min() - returns minimal level of verbosity (currently 0)

Problem: I tryed to set env. variable like this:

        char buff[32];
        sprintf(buff,"GRASS_VERBOSE=%d",G_verbose_max());
        putenv(buff);

but it did not work :frowning: how to fix it ? (parser.c, lines 738, 750)

Looking forward to your comments

Jachym

On Wed, Sep 20, 2006 at 09:38:44PM +0100, Glynn Clements wrote:

Jachym Cepicky wrote:

i think this is a nice idea.
Some modules are very verbose and with this approach a general
way is provided to handle this verbosity.

I prepared new patch (for current cvs version) which makes all modules
be able to use --verbose flag or to set GRASS_VERBOSE env. variable.

G_message, G_warning and G_percent are now able to handle according to
the user needs.

A few comments:

1. G_warning() should not be affected; warnings should be displayed
regardless of the verbosity setting.

2. I would provide a --quiet flag to allow verbosity to be disabled
for individual cases.

3. I wouldn't check for a GRASS variable with G__getenv(), as you
can't override that on a per-process basis.

--
Glynn Clements <glynn@gclements.plus.com>

--
Jachym Cepicky
e-mail: jachym.cepicky@centrum.cz
URL: http://les-ejk.cz
GPG: http://les-ejk.cz/gnupg_public_key/jachym_cepicky-gpg_public_key.asc
-----------------------------------------
OFFICE:
GDF-Hannover
Mengendamm 16d
30177 Hannover
Germany
e-mail: cepicky@gdf-hannover.de
URL: http://gdf-hannover.de
Tel.: +49 511-39088507

On Thu, 2006-09-21 at 17:58 +0100, Glynn Clements wrote:

Brad Douglas wrote:

> > > I fully agree with you. But how to do this the best way? Add new
> > > parameter to the function?
> > >
> > > e.g.
> > >
> > > G_percent(row,nrows,2,module)
> > >
> > > so that
> > >
> > > G_percent could call G_percent2(n,d,s,stderr,module->verbose)
> > >
> > > Make G_percent(), G_debug() and G_message() read environment variable
> > > GRASS_VERBOSE? I would say, this would be the best solution.
> >
> > Add a function to query the verbosity level, and change G_percent()
> > etc to use it.
> >
> > If there's a GRASS_VERBOSE environment variable, you probably want
> > both --verbose and --quiet (the latter would disable verbosity even
> > when GRASS_VERBOSE is set).
>
> A smaller issue is that of '\n'. G_message("\n") doesn't work well and
> the alternative has been to use:
>
> fprintf(stderr, "\n");
>
> Going quiet may yield an extraneous number of CRs depending on the
> module...

Can you clarify.

G_message() ought to terminate anything it writes.

I was thinking of the many loops that output text. After the loop is
finished, there is usually a single CR after the loop:

fprintf(stderr, "\n");

For the loops that use fprintf() throughout, it won't be a major
inconvenience (it just won't shut up :-), but for loops that use
G_message(), you'll probably end up with a few extra CRs output to
stderr...

--
Brad Douglas <rez touchofmadness com> KB8UYR
Address: 37.493,-121.924 / WGS84 National Map Corps #TNMC-3785

hallo,

On Thu, Sep 21, 2006 at 10:35:05AM -0700, Michael Barton wrote:

This is great. One minor editorial change:

it should be --quiet, not --quite

I'll have to take english course :frowning: thanks for this

Thanks for this very useful change.

Michael

and thanks also for testing! I'll try to correct the (so far) last
problem (setenv()) and if there will be no objections, the patch can be
applied

jachym

--
Jachym Cepicky
e-mail: jachym.cepicky@centrum.cz
URL: http://les-ejk.cz
GPG: http://les-ejk.cz/gnupg_public_key/jachym_cepicky-gpg_public_key.asc
-----------------------------------------
OFFICE:
GDF-Hannover
Mengendamm 16d
30177 Hannover
Germany
e-mail: cepicky@gdf-hannover.de
URL: http://gdf-hannover.de
Tel.: +49 511-39088507