[GRASS-SVN] r69711 - grass/trunk/lib/init
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Oct 19 17:40:52 PDT 2016
Author: wenzeslaus
Date: 2016-10-19 17:40:52 -0700 (Wed, 19 Oct 2016)
New Revision: 69711
Modified:
grass/trunk/lib/init/grass.py
Log:
init: more explanations for invalid location or mapset
Also added comments from
https://lists.osgeo.org/pipermail/grass-dev/2016-September/082317.html
Modified: grass/trunk/lib/init/grass.py
===================================================================
--- grass/trunk/lib/init/grass.py 2016-10-20 00:13:13 UTC (rev 69710)
+++ grass/trunk/lib/init/grass.py 2016-10-20 00:40:52 UTC (rev 69711)
@@ -800,9 +800,15 @@
fatal(err.value.strip('"').strip("'").replace('\\n', os.linesep))
+# TODO: distinguish between valid for getting maps and usable as current
+# https://lists.osgeo.org/pipermail/grass-dev/2016-September/082317.html
# interface created according to the current usage
def is_mapset_valid(full_mapset):
"""Return True if GRASS Mapset is valid"""
+ # WIND is created from DEFAULT_WIND by `g.region -d` and functions
+ # or modules which create a new mapset. Most modules will fail if
+ # WIND doesn't exist (assuming that neither GRASS_REGION nor
+ # WIND_OVERRIDE environmental variables are set).
return os.access(os.path.join(full_mapset, "WIND"), os.R_OK)
@@ -812,6 +818,10 @@
:param gisdbase: Path to GRASS GIS database directory
:param location: name of a Location
"""
+ # DEFAULT_WIND file should not be required until you do something
+ # that actually uses them. The check is just a heuristic; a directory
+ # containing a PERMANENT/DEFAULT_WIND file is probably a GRASS
+ # location, while a directory lacking it probably isn't.
return os.access(os.path.join(gisdbase, location,
"PERMANENT", "DEFAULT_WIND"), os.F_OK)
@@ -840,10 +850,16 @@
return _("<%s> is not a valid GRASS Location"
" because PERMANENT Mapset does not have a DEFAULT_WIND file"
" (default computational region)") % full_location
- else:
+ elif mapset not in os.listdir(full_location):
return _("Mapset <{mapset}> doesn't exist in GRASS Location <{loc}>. "
"A new mapset can be created by '-c' switch.").format(
mapset=mapset, loc=location)
+ elif not os.path.isdir(os.path.join(full_location, mapset)):
+ return _("<%s> is not a GRASS Mapset"
+ " because it is not a directory") % mapset
+ else:
+ return _("Mapset <{mapset}> is invalid for an unknown reason").format(
+ mapset=mapset, loc=location)
def set_mapset(gisrc, arg, geofile=None, create_new=False):
More information about the grass-commit
mailing list