Parcourir la source

init: more explanations for invalid location or mapset

Also added comments from
https://lists.osgeo.org/pipermail/grass-dev/2016-September/082317.html


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@69711 15284696-431f-4ddb-bdfa-cd5b030d7da7
Vaclav Petras il y a 8 ans
Parent
commit
7a6c9d98f8
1 fichiers modifiés avec 17 ajouts et 1 suppressions
  1. 17 1
      lib/init/grass.py

+ 17 - 1
lib/init/grass.py

@@ -800,9 +800,15 @@ def create_location(gisdbase, location, geostring):
         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 @@ def is_location_valid(gisdbase, location):
     :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 @@ def get_mapset_invalid_reason(gisdbase, location, mapset):
         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):