[GRASS-dev] Re: [GRASS-SVN] r49205 - in grass/trunk: lib/python raster/r.info

I highly *disagree* with this revert! Merging very specific options
which just prints one information to generic `-g` is a good idea (from
my POV). Please don't revert the commits which are just against your
*personal* taste! What's the opinion of other developers?

Martin

2011/11/14 <svn_grass@osgeo.org>:

Author: hamish
Date: 2011-11-13 22:55:13 -0800 (Sun, 13 Nov 2011)
New Revision: 49205

Modified:
grass/trunk/lib/python/raster.py
grass/trunk/raster/r.info/main.c
Log:
undo r49166: units, vdatum, and title can not be eval'd so needed to be split out. on doing that it was apparent that -g needs to act the same as g.region and v.info modules -- basic region info only. -s is debatable to belong to -g or not, but -gs is very easy if needed.

Modified: grass/trunk/lib/python/raster.py

--- grass/trunk/lib/python/raster.py 2011-11-14 06:49:25 UTC (rev 49204)
+++ grass/trunk/lib/python/raster.py 2011-11-14 06:55:13 UTC (rev 49205)
@@ -73,7 +73,7 @@
else:
return float(s)

- s = read_command('r.info', flags = 'g', map = map)
+ s = read_command('r.info', flags = 'rgstmpud', map = map)
kv = parse_key_val(s)
for k in ['min', 'max']:
kv[k] = float_or_null(kv[k])

Modified: grass/trunk/raster/r.info/main.c

--- grass/trunk/raster/r.info/main.c 2011-11-14 06:49:25 UTC (rev 49204)
+++ grass/trunk/raster/r.info/main.c 2011-11-14 06:55:13 UTC (rev 49205)
@@ -60,8 +60,9 @@
struct Reclass reclass;
struct GModule *module;
struct Option *opt1;
- struct Flag *gflag, *hflag;
-
+ struct Flag *rflag, *sflag, *tflag, *gflag, *hflag, *mflag;
+ struct Flag *uflag, *dflag, *timestampflag;
+
/* Initialize GIS Engine */
G_gisinit(argv[0]);

@@ -74,14 +75,44 @@

opt1 = G\_define\_standard\_option\(G\_OPT\_R\_MAP\);

+ rflag = G_define_flag();
+ rflag->key = 'r';
+ rflag->description = _("Print range only");
+
+ sflag = G_define_flag();
+ sflag->key = 's';
+ sflag->description =
+ _("Print raster map resolution (NS-res, EW-res) only");
+
+ tflag = G_define_flag();
+ tflag->key = 't';
+ tflag->description = _("Print raster map type only");
+
gflag = G_define_flag();
gflag->key = 'g';
- gflag->description = _("Print basic info in shell script style");
+ gflag->description = _("Print map region only");

hflag = G\_define\_flag\(\);
hflag\-&gt;key = &#39;h&#39;;
hflag\-&gt;description = \_\(&quot;Print raster history instead of info&quot;\);

+ uflag = G_define_flag();
+ uflag->key = 'u';
+ uflag->description = _("Print raster map data units only");
+
+ dflag = G_define_flag();
+ dflag->key = 'd';
+ dflag->description = _("Print raster map vertical datum only");
+
+ mflag = G_define_flag();
+ mflag->key = 'm';
+ mflag->description = _("Print map title only");
+
+ timestampflag = G_define_flag();
+ timestampflag->key = 'p';
+ timestampflag->description =
+ _("Print raster map timestamp (day.month.year hour:minute:seconds) only");
+
if (G_parser(argc, argv))
exit(EXIT_FAILURE);

@@ -115,8 +146,9 @@

out = stdout;

- /* no flags */
- if (!gflag->answer && !hflag->answer) {
+ if (!rflag->answer && !sflag->answer && !tflag->answer &&
+ !gflag->answer && !hflag->answer && !timestampflag->answer &&
+ !mflag->answer && !uflag->answer && !dflag->answer) {
divider('+');

   compose\_line\(out, &quot;Layer:    %\-29\.29s  Date: %s&quot;, name,

@@ -289,10 +321,9 @@

   fprintf\(out, &quot;\\n&quot;\);
\}

- else { /* g,h flag */
+ else { /* r,s,t,g,h, or m flag */

- if (gflag->answer) {
- /* old rflag */
+ if (rflag->answer) {
if (data_type == CELL_TYPE) {
if (2 == Rast_read_range(name, "", &crange)) {
fprintf(out, "min=NULL\n");
@@ -311,7 +342,10 @@
fprintf(out, "min=%.15g\n", zmin);
fprintf(out, "max=%.15g\n", zmax);
}
-
+
+ }
+
+ if (gflag->answer) {
G_format_northing(cellhd.north, tmp1, -1);
G_format_northing(cellhd.south, tmp2, -1);
fprintf(out, "north=%s\n", tmp1);
@@ -321,46 +355,47 @@
G_format_easting(cellhd.west, tmp2, -1);
fprintf(out, "east=%s\n", tmp1);
fprintf(out, "west=%s\n", tmp2);
-
- /* old sflag */
+ }
+
+ if (sflag->answer) {
G_format_resolution(cellhd.ns_res, tmp3, cellhd.proj);
fprintf(out, "nsres=%s\n", tmp3);

       G\_format\_resolution\(cellhd\.ew\_res, tmp3, cellhd\.proj\);
       fprintf\(out, &quot;ewres=%s\\n&quot;, tmp3\);

-
- /* new rows and columns parameters */
- fprintf(out, "rows=%d\n", cellhd.rows);
- fprintf(out, "cols=%d\n", cellhd.cols);
-
- /* old tflag */
+ }
+
+ if (tflag->answer) {
fprintf(out, "datatype=%s\n",
(data_type == CELL_TYPE ? "CELL" :
(data_type == DCELL_TYPE ? "DCELL" :
(data_type == FCELL_TYPE ? "FCELL" : "??"))));
-
- /* old mflag */
+ }
+
+ if (mflag->answer) {
fprintf(out, "title=%s (%s)\n", cats_ok ? cats.title :
"??", hist_ok ? Rast_get_history(&hist, HIST_TITLE) : "??");
-
- /* old timestampflag */
+ }
+
+ if (timestampflag->answer) {
if (time_ok && (first_time_ok || second_time_ok)) {

           G\_format\_timestamp\(&amp;ts, timebuff\);

           /\*Create the r\.info timestamp string \*/
           fprintf\(out, &quot;timestamp=\\&quot;%s\\&quot;\\n&quot;, timebuff\);

+
}
else {
fprintf(out, "timestamp=\"none\"\n");
- }
-
- /* old uflag */
- fprintf(out, "units=%s\n", units ? units : "(none)");
- /* old dflag */
- fprintf(out, "vertical_datum=%s\n", vdatum ? vdatum : "(none)");
+ }
}

+ if (uflag->answer)
+ fprintf(out, "units=%s\n", units ? units : "(none)");
+ if (dflag->answer)
+ fprintf(out, "vertical_datum=%s\n", vdatum ? vdatum : "(none)");
+
if (hflag->answer) {
if (hist_ok) {
fprintf(out, "Data Source:\n");
@@ -375,7 +410,8 @@
}
}
}
- }
+ } /* else rflag or sflag or tflag or gflag or hflag or mflag */
+
return EXIT_SUCCESS;
}

_______________________________________________
grass-commit mailing list
grass-commit@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-commit

--
Martin Landa <landa.martin gmail.com> * http://geo.fsv.cvut.cz/~landa

Hi all,
i agree with Martins point of view. Having just a single flag "-g" to
print all available information in "shell" style makes IMHO much more
sense. It reduces the need for many flags which may change over time
and which confuses module developer and API designer.
Having only a single flag allows that additionally information can be
added without the need for a new flag. This is also very useful when
designing the GRASS Python API.

The implementation of "-g" in Martins way for r.info, v.info.
r3.info, g.region and many more, helps to implement a convenient and
compatible module behavior.

I use this solution in the temporal extension too.

My 2c
Soeren

2011/11/14 Martin Landa <landa.martin@gmail.com>:

I highly *disagree* with this revert! Merging very specific options
which just prints one information to generic `-g` is a good idea (from
my POV). Please don't revert the commits which are just against your
*personal* taste! What's the opinion of other developers?

Martin

2011/11/14 <svn_grass@osgeo.org>:

Author: hamish
Date: 2011-11-13 22:55:13 -0800 (Sun, 13 Nov 2011)
New Revision: 49205

Modified:
grass/trunk/lib/python/raster.py
grass/trunk/raster/r.info/main.c
Log:
undo r49166: units, vdatum, and title can not be eval'd so needed to be split out. on doing that it was apparent that -g needs to act the same as g.region and v.info modules -- basic region info only. -s is debatable to belong to -g or not, but -gs is very easy if needed.

Modified: grass/trunk/lib/python/raster.py

--- grass/trunk/lib/python/raster.py 2011-11-14 06:49:25 UTC (rev 49204)
+++ grass/trunk/lib/python/raster.py 2011-11-14 06:55:13 UTC (rev 49205)
@@ -73,7 +73,7 @@
else:
return float(s)

- s = read_command('r.info', flags = 'g', map = map)
+ s = read_command('r.info', flags = 'rgstmpud', map = map)
kv = parse_key_val(s)
for k in ['min', 'max']:
kv[k] = float_or_null(kv[k])

Modified: grass/trunk/raster/r.info/main.c

--- grass/trunk/raster/r.info/main.c 2011-11-14 06:49:25 UTC (rev 49204)
+++ grass/trunk/raster/r.info/main.c 2011-11-14 06:55:13 UTC (rev 49205)
@@ -60,8 +60,9 @@
struct Reclass reclass;
struct GModule *module;
struct Option *opt1;
- struct Flag *gflag, *hflag;
-
+ struct Flag *rflag, *sflag, *tflag, *gflag, *hflag, *mflag;
+ struct Flag *uflag, *dflag, *timestampflag;
+
/* Initialize GIS Engine */
G_gisinit(argv[0]);

@@ -74,14 +75,44 @@

opt1 = G\_define\_standard\_option\(G\_OPT\_R\_MAP\);

+ rflag = G_define_flag();
+ rflag->key = 'r';
+ rflag->description = _("Print range only");
+
+ sflag = G_define_flag();
+ sflag->key = 's';
+ sflag->description =
+ _("Print raster map resolution (NS-res, EW-res) only");
+
+ tflag = G_define_flag();
+ tflag->key = 't';
+ tflag->description = _("Print raster map type only");
+
gflag = G_define_flag();
gflag->key = 'g';
- gflag->description = _("Print basic info in shell script style");
+ gflag->description = _("Print map region only");

hflag = G\_define\_flag\(\);
hflag\-&gt;key = &#39;h&#39;;
hflag\-&gt;description = \_\(&quot;Print raster history instead of info&quot;\);

+ uflag = G_define_flag();
+ uflag->key = 'u';
+ uflag->description = _("Print raster map data units only");
+
+ dflag = G_define_flag();
+ dflag->key = 'd';
+ dflag->description = _("Print raster map vertical datum only");
+
+ mflag = G_define_flag();
+ mflag->key = 'm';
+ mflag->description = _("Print map title only");
+
+ timestampflag = G_define_flag();
+ timestampflag->key = 'p';
+ timestampflag->description =
+ _("Print raster map timestamp (day.month.year hour:minute:seconds) only");
+
if (G_parser(argc, argv))
exit(EXIT_FAILURE);

@@ -115,8 +146,9 @@

out = stdout;

- /* no flags */
- if (!gflag->answer && !hflag->answer) {
+ if (!rflag->answer && !sflag->answer && !tflag->answer &&
+ !gflag->answer && !hflag->answer && !timestampflag->answer &&
+ !mflag->answer && !uflag->answer && !dflag->answer) {
divider('+');

   compose\_line\(out, &quot;Layer:    %\-29\.29s  Date: %s&quot;, name,

@@ -289,10 +321,9 @@

   fprintf\(out, &quot;\\n&quot;\);
\}

- else { /* g,h flag */
+ else { /* r,s,t,g,h, or m flag */

- if (gflag->answer) {
- /* old rflag */
+ if (rflag->answer) {
if (data_type == CELL_TYPE) {
if (2 == Rast_read_range(name, "", &crange)) {
fprintf(out, "min=NULL\n");
@@ -311,7 +342,10 @@
fprintf(out, "min=%.15g\n", zmin);
fprintf(out, "max=%.15g\n", zmax);
}
-
+
+ }
+
+ if (gflag->answer) {
G_format_northing(cellhd.north, tmp1, -1);
G_format_northing(cellhd.south, tmp2, -1);
fprintf(out, "north=%s\n", tmp1);
@@ -321,46 +355,47 @@
G_format_easting(cellhd.west, tmp2, -1);
fprintf(out, "east=%s\n", tmp1);
fprintf(out, "west=%s\n", tmp2);
-
- /* old sflag */
+ }
+
+ if (sflag->answer) {
G_format_resolution(cellhd.ns_res, tmp3, cellhd.proj);
fprintf(out, "nsres=%s\n", tmp3);

       G\_format\_resolution\(cellhd\.ew\_res, tmp3, cellhd\.proj\);
       fprintf\(out, &quot;ewres=%s\\n&quot;, tmp3\);

-
- /* new rows and columns parameters */
- fprintf(out, "rows=%d\n", cellhd.rows);
- fprintf(out, "cols=%d\n", cellhd.cols);
-
- /* old tflag */
+ }
+
+ if (tflag->answer) {
fprintf(out, "datatype=%s\n",
(data_type == CELL_TYPE ? "CELL" :
(data_type == DCELL_TYPE ? "DCELL" :
(data_type == FCELL_TYPE ? "FCELL" : "??"))));
-
- /* old mflag */
+ }
+
+ if (mflag->answer) {
fprintf(out, "title=%s (%s)\n", cats_ok ? cats.title :
"??", hist_ok ? Rast_get_history(&hist, HIST_TITLE) : "??");
-
- /* old timestampflag */
+ }
+
+ if (timestampflag->answer) {
if (time_ok && (first_time_ok || second_time_ok)) {

           G\_format\_timestamp\(&amp;ts, timebuff\);

           /\*Create the r\.info timestamp string \*/
           fprintf\(out, &quot;timestamp=\\&quot;%s\\&quot;\\n&quot;, timebuff\);

+
}
else {
fprintf(out, "timestamp=\"none\"\n");
- }
-
- /* old uflag */
- fprintf(out, "units=%s\n", units ? units : "(none)");
- /* old dflag */
- fprintf(out, "vertical_datum=%s\n", vdatum ? vdatum : "(none)");
+ }
}

+ if (uflag->answer)
+ fprintf(out, "units=%s\n", units ? units : "(none)");
+ if (dflag->answer)
+ fprintf(out, "vertical_datum=%s\n", vdatum ? vdatum : "(none)");
+
if (hflag->answer) {
if (hist_ok) {
fprintf(out, "Data Source:\n");
@@ -375,7 +410,8 @@
}
}
}
- }
+ } /* else rflag or sflag or tflag or gflag or hflag or mflag */
+
return EXIT_SUCCESS;
}

_______________________________________________
grass-commit mailing list
grass-commit@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-commit

--
Martin Landa <landa.martin gmail.com> * http://geo.fsv.cvut.cz/~landa
_______________________________________________
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

Sören Gebbert:

Hi all,
i agree with Martins point of view. Having just a single flag "-g" to
print all available information in "shell" style makes IMHO much more
sense. It reduces the need for many flags which may change over time
and which confuses module developer and API designer.
Having only a single flag allows that additionally information can be
added without the need for a new flag. This is also very useful when
designing the GRASS Python API.

The implementation of "-g" in Martins way for r.info, v.info.
r3.info, g.region and many more, helps to implement a convenient and
compatible module behavior.

+1

"-g" is generally used in GRASS to print info in shell script style. A
bunch of flags each printing one bit of information in shell style is
IMHO a bit messy, one single flag should do (most of the times).

Markus M

I use this solution in the temporal extension too.

My 2c
Soeren

2011/11/14 Martin Landa <landa.martin@gmail.com>:

I highly *disagree* with this revert! Merging very specific options
which just prints one information to generic `-g` is a good idea (from
my POV). Please don't revert the commits which are just against your
*personal* taste! What's the opinion of other developers?

Martin

2011/11/14 <svn_grass@osgeo.org>:

Author: hamish
Date: 2011-11-13 22:55:13 -0800 (Sun, 13 Nov 2011)
New Revision: 49205

Modified:
grass/trunk/lib/python/raster.py
grass/trunk/raster/r.info/main.c
Log:
undo r49166: units, vdatum, and title can not be eval'd so needed to be split out. on doing that it was apparent that -g needs to act the same as g.region and v.info modules -- basic region info only. -s is debatable to belong to -g or not, but -gs is very easy if needed.

Modified: grass/trunk/lib/python/raster.py

--- grass/trunk/lib/python/raster.py 2011-11-14 06:49:25 UTC (rev 49204)
+++ grass/trunk/lib/python/raster.py 2011-11-14 06:55:13 UTC (rev 49205)
@@ -73,7 +73,7 @@
else:
return float(s)

- s = read_command('r.info', flags = 'g', map = map)
+ s = read_command('r.info', flags = 'rgstmpud', map = map)
kv = parse_key_val(s)
for k in ['min', 'max']:
kv[k] = float_or_null(kv[k])

Modified: grass/trunk/raster/r.info/main.c

--- grass/trunk/raster/r.info/main.c 2011-11-14 06:49:25 UTC (rev 49204)
+++ grass/trunk/raster/r.info/main.c 2011-11-14 06:55:13 UTC (rev 49205)
@@ -60,8 +60,9 @@
struct Reclass reclass;
struct GModule *module;
struct Option *opt1;
- struct Flag *gflag, *hflag;
-
+ struct Flag *rflag, *sflag, *tflag, *gflag, *hflag, *mflag;
+ struct Flag *uflag, *dflag, *timestampflag;
+
/* Initialize GIS Engine */
G_gisinit(argv[0]);

@@ -74,14 +75,44 @@

opt1 = G\_define\_standard\_option\(G\_OPT\_R\_MAP\);

+ rflag = G_define_flag();
+ rflag->key = 'r';
+ rflag->description = _("Print range only");
+
+ sflag = G_define_flag();
+ sflag->key = 's';
+ sflag->description =
+ _("Print raster map resolution (NS-res, EW-res) only");
+
+ tflag = G_define_flag();
+ tflag->key = 't';
+ tflag->description = _("Print raster map type only");
+
gflag = G_define_flag();
gflag->key = 'g';
- gflag->description = _("Print basic info in shell script style");
+ gflag->description = _("Print map region only");

hflag = G\_define\_flag\(\);
hflag\-&gt;key = &#39;h&#39;;
hflag\-&gt;description = \_\(&quot;Print raster history instead of info&quot;\);

+ uflag = G_define_flag();
+ uflag->key = 'u';
+ uflag->description = _("Print raster map data units only");
+
+ dflag = G_define_flag();
+ dflag->key = 'd';
+ dflag->description = _("Print raster map vertical datum only");
+
+ mflag = G_define_flag();
+ mflag->key = 'm';
+ mflag->description = _("Print map title only");
+
+ timestampflag = G_define_flag();
+ timestampflag->key = 'p';
+ timestampflag->description =
+ _("Print raster map timestamp (day.month.year hour:minute:seconds) only");
+
if (G_parser(argc, argv))
exit(EXIT_FAILURE);

@@ -115,8 +146,9 @@

out = stdout;

- /* no flags */
- if (!gflag->answer && !hflag->answer) {
+ if (!rflag->answer && !sflag->answer && !tflag->answer &&
+ !gflag->answer && !hflag->answer && !timestampflag->answer &&
+ !mflag->answer && !uflag->answer && !dflag->answer) {
divider('+');

   compose\_line\(out, &quot;Layer:    %\-29\.29s  Date: %s&quot;, name,

@@ -289,10 +321,9 @@

   fprintf\(out, &quot;\\n&quot;\);
\}

- else { /* g,h flag */
+ else { /* r,s,t,g,h, or m flag */

- if (gflag->answer) {
- /* old rflag */
+ if (rflag->answer) {
if (data_type == CELL_TYPE) {
if (2 == Rast_read_range(name, "", &crange)) {
fprintf(out, "min=NULL\n");
@@ -311,7 +342,10 @@
fprintf(out, "min=%.15g\n", zmin);
fprintf(out, "max=%.15g\n", zmax);
}
-
+
+ }
+
+ if (gflag->answer) {
G_format_northing(cellhd.north, tmp1, -1);
G_format_northing(cellhd.south, tmp2, -1);
fprintf(out, "north=%s\n", tmp1);
@@ -321,46 +355,47 @@
G_format_easting(cellhd.west, tmp2, -1);
fprintf(out, "east=%s\n", tmp1);
fprintf(out, "west=%s\n", tmp2);
-
- /* old sflag */
+ }
+
+ if (sflag->answer) {
G_format_resolution(cellhd.ns_res, tmp3, cellhd.proj);
fprintf(out, "nsres=%s\n", tmp3);

       G\_format\_resolution\(cellhd\.ew\_res, tmp3, cellhd\.proj\);
       fprintf\(out, &quot;ewres=%s\\n&quot;, tmp3\);

-
- /* new rows and columns parameters */
- fprintf(out, "rows=%d\n", cellhd.rows);
- fprintf(out, "cols=%d\n", cellhd.cols);
-
- /* old tflag */
+ }
+
+ if (tflag->answer) {
fprintf(out, "datatype=%s\n",
(data_type == CELL_TYPE ? "CELL" :
(data_type == DCELL_TYPE ? "DCELL" :
(data_type == FCELL_TYPE ? "FCELL" : "??"))));
-
- /* old mflag */
+ }
+
+ if (mflag->answer) {
fprintf(out, "title=%s (%s)\n", cats_ok ? cats.title :
"??", hist_ok ? Rast_get_history(&hist, HIST_TITLE) : "??");
-
- /* old timestampflag */
+ }
+
+ if (timestampflag->answer) {
if (time_ok && (first_time_ok || second_time_ok)) {

           G\_format\_timestamp\(&amp;ts, timebuff\);

           /\*Create the r\.info timestamp string \*/
           fprintf\(out, &quot;timestamp=\\&quot;%s\\&quot;\\n&quot;, timebuff\);

+
}
else {
fprintf(out, "timestamp=\"none\"\n");
- }
-
- /* old uflag */
- fprintf(out, "units=%s\n", units ? units : "(none)");
- /* old dflag */
- fprintf(out, "vertical_datum=%s\n", vdatum ? vdatum : "(none)");
+ }
}

+ if (uflag->answer)
+ fprintf(out, "units=%s\n", units ? units : "(none)");
+ if (dflag->answer)
+ fprintf(out, "vertical_datum=%s\n", vdatum ? vdatum : "(none)");
+
if (hflag->answer) {
if (hist_ok) {
fprintf(out, "Data Source:\n");
@@ -375,7 +410,8 @@
}
}
}
- }
+ } /* else rflag or sflag or tflag or gflag or hflag or mflag */
+
return EXIT_SUCCESS;
}

_______________________________________________
grass-commit mailing list
grass-commit@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-commit

--
Martin Landa <landa.martin gmail.com> * http://geo.fsv.cvut.cz/~landa
_______________________________________________
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

_______________________________________________
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

hamish:

> undo r49166: units, vdatum, and title can not be
> eval'd so needed to be split out. on doing that it was
> apparent that -g needs to act the same as g.region and
> v.info modules -- basic region info only. -s is debatable to
> belong to -g or not, but -gs is very easy if needed.

Martin wrote:

I highly *disagree* with this revert!
Merging very specific options which just prints one information
to generic `-g` is a good idea (from my POV).

-g as a shell style debug dump of all internal variables does
not provide a clean interface for command line users to work with.

'r.info -r mapname' is a beautiful thing when working from the
command line. really, it is. simple, to the point, just what
you want.

r.info, v.info, and g.region shell style output is probably
the most common of all modules used by users for scripting,
and must remain clear and to the point.

Please don't revert the commits which are just against your
*personal* taste!

reverting the units= vdatum= and title= *had* to be done, as
explained in an email of a few days ago. commit log message
explains the rest- not leaving it in a half and half mess of
concepts (I did try that first, but in testing the mess was
obvious). -g remains primarily for use with map bounds in
those modules, as it always has been, and that is not a bad
thing.

this does not make python scripting any more complicated,
it is just a matter of getting what you ask for instead of
the kitchen sink, and not messing with what wasn't broken.

I considered adding quotes (see r.timestamp) for free-form text
but do not think that quoting for bourne shell will be the right
solution for all cases, and it is better to just output verbatim
and let the user split on the first '=' in whatever language they
are using.

best,
Hamish

Markus Metz wrote:

"-g" is generally used in GRASS to print info in shell
script style.

that is not in dispute at all, and has not changed.
the change puts things back closer to how they were before.

the question is if in future -g should be a defacto debug dump
of all possibilities (in shell style), or more limited info as
it has been in grass 5 and 6.

A bunch of flags each printing one bit of information in
shell style is IMHO a bit messy,

as per last email, "r.info -r elevation" is an elegant and
beautiful bit of command line magic to work with, and not
something I am going to part with lightly.

one single flag should do (most of the times).

in which context? called by a human on the command line or
by a module? I agree that if a module/gui tool is calling
you might as well consolidate, but when doing custom scripting
using g.region, r.info, v.info as fundamental building blocks?
In that case no -- K.I.S.S. and don't have 1/2 dozen n= enviro
variables overwriting each other.

best,
Hamish

Martin Landa wrote:

I highly *disagree* with this revert! Merging very specific options
which just prints one information to generic `-g` is a good idea (from
my POV). Please don't revert the commits which are just against your
*personal* taste! What's the opinion of other developers?

Having "-g" for "dump everything, key=value format" is a good idea.

Having additional options to dump specific pieces of information may
be worthwhile, particularly if some items require non-trivial effort
to retrieve. Even if it doesn't seem particularly useful, it is at
least harmless.

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

Hi,

2011/11/14 Glynn Clements <glynn@gclements.plus.com>:

Martin Landa wrote:

I highly *disagree* with this revert! Merging very specific options
which just prints one information to generic `-g` is a good idea (from
my POV). Please don't revert the commits which are just against your
*personal* taste! What's the opinion of other developers?

Having "-g" for "dump everything, key=value format" is a good idea.

Having additional options to dump specific pieces of information may
be worthwhile, particularly if some items require non-trivial effort
to retrieve. Even if it doesn't seem particularly useful, it is at
least harmless.

Thats indeed the best solution. Lets use this idea as design decision.

I think r.univar is a good example. Extended stats are computed only
when specified, because of its additional computation effort and
memory usage. The output is added automatically to shell style output
in case "-g" is specified.

Modules:
* g.region is ok
* r.info, v..info and r3.info can be reduced to use only the "-g" flag
to print all info in shell style
* ... ?

Best regards
Soeren

--
Glynn Clements <glynn@gclements.plus.com>
_______________________________________________
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

Hi,

2011/11/16 Sören Gebbert <soerengebbert@googlemail.com>:
* r.info, v..info and r3.info can be reduced to use only the "-g" flag

to print all info in shell style

similar for v.info, see [1] which should be basically reverted.

Martin

[1] http://trac.osgeo.org/grass/changeset/49204

--
Martin Landa <landa.martin gmail.com> * http://geo.fsv.cvut.cz/~landa

2011/11/16 Martin Landa <landa.martin@gmail.com>:

Hi,

2011/11/16 Sören Gebbert <soerengebbert@googlemail.com>:
* r.info, v..info and r3.info can be reduced to use only the "-g" flag

to print all info in shell style

similar for v.info, see [1] which should be basically reverted.

+1

Martin

[1] http://trac.osgeo.org/grass/changeset/49204

--
ciao
Luca

http://gis.cri.fmach.it/delucchi/
www.lucadelu.org

Sören wrote:

I think r.univar is a good example. Extended
stats are computed only when specified, because
of its additional computation effort and memory
usage. The output is added automatically to shell
style output in case "-g" is specified.

I much prefer the present way for v.info (in grass7)
and r.univar, where -g gives basic eval-safe info
and -e gives extended parser-friendly output (but
not necessarily eval-safe, ie free-form text fields)
simple, clean, consistent, and doesn't stop others
from working the way they want to work.

wrt unnecessarily viewing this as a 0/1 conflict--
I really don't mind --dump-everything-parse-friendly
flags -- just don't take away the ability to do a
simple 'r.info -r elevation' in the process. These
things (and more generally CLI vs GUI) are not
mutually exclusive, and shouldn't be coded so that
they become so. A little thinking from the other-
guy's end-user workflow goes a long way.

wrt the benefits of keeping language agnostic/safe--
CLI, GUI, perl, python, batch files, shell scripts,
java, R, system(), Ruby, whatever: if we can easily
make the building blocks work for whatever the end
user wants to use, then we should. We shouldn't
impose artificial python-only solutions (and we
should work very hard to make sure that we
haven't), even if nothing in the grass7 codebase
itself uses that language. Users will be most happy
in whatever they are most happy in. If we impose
single solutions we lose their patronage for very
little gain.

wrt r.info's too big pile of flags--
As mentioned in the commit log message for r.info,
-s (res) could be moved into -g (region bounds) as
they are related. Perhaps -t (CELL type) too; it
doesn't have anything to do with the array size
but is a fundamental parameter of the array
definition.

For the purely meta-data items, -u (units), -d
(vertical datum), -p (timestamp), -m (map title)
which are generally not eval-safe could be merged
into a single -e extended-info flag. I don't mind
that at all, what I oppose is making -g eval-unsafe
and forcing debug-dump parsing on CLI users who have
to look at the basic output every few minutes.

if r.info -gre is still too much clutter for you in
the GUI auto-menu it's simple enough to create a
wrapper --script which either hides or consolidates
away the GUI-irrelevant parts.

... I'll reply to specific concerns later (probably
tomorrow); please don't change anything in the mean
time.

regards,
Hamish

Hamish wrote:

simple, clean, consistent, and doesn't stop others
from working the way they want to work.

well, maybe "consistent" for all sets/perspectives is
the part we're working on right now. :slight_smile:

Hamish

Hi,

2011/11/18 Hamish <hamish_b@yahoo.com>:

Hamish wrote:

simple, clean, consistent, and doesn't stop others
from working the way they want to work.

well, maybe "consistent" for all sets/perspectives is
the part we're working on right now. :slight_smile:

current situation is

r.info
  -g Print raster array information only
  -e Print extended metadata information only

v.info
  -g Print region info in shell script style
  -e Print extended metadata info in shell script style

which forces to open discussion again. I would still incline to use
`-g` for shell script output as used in others modules. I have counted
more than 45 modules in trunk which use `-g` for shell script style
output. I don't see any reason why `r.info` or `v.info` should be
exceptions.

Martin

--
Martin Landa <landa.martin gmail.com> * http://geo.fsv.cvut.cz/~landa

Martin:

current situation is

r.info
-g Print raster array information only

[in shell script style!]

-e Print extended metadata information only

[also in shell script style!]

v.info
-g Print region info in shell script style
-e Print extended metadata info in shell
script style

which forces to open discussion again.

..did it ever close? :slight_smile:

what is new since last we discussed this is r.info's
many shell script style flags are now grouped* so
it is not as messy in the module GUI. IMHO it is a
good compromise, and consistent design among modules
is still respected.

[*] https://trac.osgeo.org/grass/changeset/49293

so -rgstmpud becomes -ger instead of just one huge
-g. Non shell-script safe foo=(bar) things are kept
in -e, so you can still `eval` -g. Instances of
'(none)' have been changed to '"none"' to become
more shell friendly as well.

I would still incline to use `-g` for shell
script output as used in others modules.
I have counted more than 45 modules in trunk
which use `-g` for shell script style output.

huh? I don't understand what you are talking about.

** r.info -g, v.info -g, and g.region -g DO all
print eval-safe shell script style ** same as ever,
still shell script style, still similar to -g in
other modules...

Keep in mind that r.info and v.info's default
"pretty" output mode is a tractor-fed dot-matrix
printer style report, not a "foo: bar" listing. [and
fwiw there is no point for "min: 1.2345" instead of
"min=1.2345" style, since min= is perfectly human
friendly to read]

What they are not is a full --parsable-debug-data-
dump which may save a gui programmer 5 keystrokes
in a python library which is revisited once every
3 years, but make things totally annoying for a
command line user who uses that same flag 20 times
a day, not to mention making them eval-unsafe.

If you need a --dump-everything-parsable flag some-
where then fine add that (better yet just make a
wrapper --script instead of messing up the code),
but don't remove the fine grained eval-safe shell
script style options in the process. These things
do not have to be mutually exclusive. But -g does
have to stay shell-script (ie eval) safe.

I don't see any reason why `r.info` or `v.info`
should be exceptions.

?! they aren't !?

If you want to see an exception, look at d.what.rast
-t "terse" output flag.

Hamish

Hi,

2011/11/27 Hamish <hamish_b@yahoo.com>:

I would still incline to use `-g` for shell
script output as used in others modules.
I have counted more than 45 modules in trunk
which use `-g` for shell script style output.

huh? I don't understand what you are talking about.

OK, sorry for wrong counting, there are 68 GRASS modules with `g` flag
(in trunk), from them 16 uses `g` flags for shell script style output.
Note that in most cases the modules which prints something to the
stdout uses `g` flag for shell script style output. So I hoped that my
question is clear, why should be r.info and v.info exceptions? I think
it would be good decision to reserve `g` flag for shell script output
in the case that modules serves such output. That could be clear rule
for user POV.

Martin

--
Martin Landa <landa.martin gmail.com> * http://geo.fsv.cvut.cz/~landa

Martin:

>> I would still incline to use `-g` for shell
>> script output as used in others modules.
>> I have counted more than 45 modules in trunk
>> which use `-g` for shell script style output.

Hamish:

> huh? I don't understand what you are talking about.

Martin:

OK, sorry for wrong counting, there are 68 GRASS modules
with `g` flag (in trunk), from them 16 uses `g` flags for
shell script style output. Note that in most cases the
modules which prints something to the stdout uses `g` flag
for shell script style output. So I hoped that my question
is clear, why should be r.info and v.info exceptions?

?! they aren't !?

I think it would be good decision to reserve `g` flag for
shell script output in the case that modules serves such
output.

But -g for r.info and v.info *do* output shell script style.

so I still don't understand what you are trying to say.

"Extra/esoteric" metadata items moved into -e are generally not
safe to use directly in shell scripts as many of them can contain
freeform text fields. It took me less than 48 hours to run across
that problem in the wild when all output was merged into one flag.
(bash/eval does not like title= for pretty much any raster map)

Working around that by quoting all strings in the output does not
seem very language-portable to me. (making it nicer for shell scripts
should not make it much more of a pain to parse in python scripts,
and vice versa)

Hamish