Hi,

the attached patch adds to g.mapset module new flag '-l' (print
available mapsets with write permission). It requires dummy value for
mapset, e.g.

g.mapset -l map=dummy

same story like `r.in.gdal -f` and others. It would be reasonable to
introduce new attribute in option/flag structure, something like
'suppress_required'. The value could be global (YES/NO), to suppress
all required flags/options or better list of option/flags (e.g. their
keys) which are required and will be suppressed by the given
flag/option.

Regards, Martin

2008/3/21, Glynn Clements <[EMAIL PROTECTED]>:
>
>  Martin Landa wrote:
>
>  > >  > is there a way how to determine if a mapset is accessible without need
>  > >  > to switch 'g.mapset name' -> 'ERROR: You don't have permission to use
>  > >  > this mapset'. If not maybe new flag for g.mapsets would make sense?
>  > >  >
>  > >  > -a 'List all accessible mapsets'
>  > >
>  > > At the C level, G__mapset_permissions() and G__mapset_permissions2()
>  > >  determines whether or not a specific mapset can be used as the current
>  > >  mapset (i.e. it's a directory, and you own it).
>  > >
>  > >  AFAIK, there isn't a user command to determine this. If it's useful,
>  > >  it really belongs in g.mapset rather than g.mapsets, as the former
>  > >  deals with the current mapset (used for output) while the latter deals
>  > >  with the mapsets used for input.
>  >
>  > I think it would be useful, at least for creating list of mapsets in
>  > GUI start-up screen. Currently is used 'g.mapsets -l' which prints all
>  > mapsets in the location. I don't fully understand here, why g.mapsets
>  > is not good place for that.
>
>
> "g.mapsets -l" displays a list of mapsets which are suitable for use
>  as values in g.mapsets' mapset= and addmapset= options.
>
>  You are essentially asking about mapsets which are suitable for use as
>  values in the mapset= option of g.mapset[1]. The logical place for
>  such an option is in g.mapset.
>
>  [1] init.sh/init.bat have their own built-in clone of g.mapset. It
>  would be worth looking into whether they can be changed to use
>  g.mapset instead.
>
>  There is a great deal of asymmetry between output and input; the
>  current mapset and the mapset search path are really very different
>  entities. g.mapset deals exclusively with the former, g.mapsets deals
>  exclusively with the latter.
>
>  And the option which you're proposing is related to the former.
>
>
>  > g.mapsets -l -> prints *all* mapsets
>  > g.mapsets -a -> print only *accessible* mapset
>
>
> "accessible" is the wrong word here. You can "access" any mapset for
>  which you have read permission.
>
>
>  --
>
> Glynn Clements <[EMAIL PROTECTED]>
>


-- 
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa *
Index: general/g.mapset/main.c
===================================================================
--- general/g.mapset/main.c	(revision 30709)
+++ general/g.mapset/main.c	(working copy)
@@ -32,7 +32,7 @@
     int    ret;
     struct GModule *module;
     struct Option *gisdbase_opt, *location_opt, *mapset_opt;
-    struct Flag *f_add;
+    struct Flag *f_add, *f_list;
     char   *gisdbase_old, *location_old, *mapset_old;
     char   *gisdbase_new, *location_new, *mapset_new;
     char   *gis_lock; 
@@ -74,6 +74,10 @@
     f_add->description = _("Create mapset if it doesn't exist");
     f_add->answer      = FALSE;
 
+    f_list = G_define_flag() ;
+    f_list->key         = 'l' ;
+    f_list->description = _("List all available mapsets with write permission");
+
     if (G_parser(argc, argv))
     	exit(EXIT_FAILURE);
 
@@ -96,6 +100,21 @@
     else
 	location_new = location_old;
 
+    if (f_list->answer) {
+	char **ms;
+	int nmapsets;
+	ms = G_available_mapsets();
+	
+	for (nmapsets = 0; ms[nmapsets]; nmapsets++) {
+	    if (G__mapset_permissions2 (gisdbase_new, location_new,  ms[nmapsets]) > 0) {
+		fprintf(stdout, "%s ", ms[nmapsets]);
+	    }
+	}
+	fprintf(stdout, "\n");
+	
+	exit(EXIT_SUCCESS);
+    }
+
     mapset_new = mapset_opt->answer;
     G_asprintf ( &mapset_new_path, "%s/%s/%s", gisdbase_new, location_new, 
 		mapset_new );
_______________________________________________
grass-dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/grass-dev

Reply via email to