[GRASS-SVN] r72203 - grass/trunk/lib/init

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jan 31 18:40:20 PST 2018


Author: wenzeslaus
Date: 2018-01-31 18:40:20 -0800 (Wed, 31 Jan 2018)
New Revision: 72203

Modified:
   grass/trunk/lib/init/grass.py
Log:
init: more messages for invalid location or mapset (but still not perfect)

Modified: grass/trunk/lib/init/grass.py
===================================================================
--- grass/trunk/lib/init/grass.py	2018-01-29 17:53:11 UTC (rev 72202)
+++ grass/trunk/lib/init/grass.py	2018-02-01 02:40:20 UTC (rev 72203)
@@ -835,34 +835,50 @@
 def get_mapset_invalid_reason(gisdbase, location, mapset):
     """Returns a message describing what is wrong with the Mapset
 
+    The goal is to provide the most suitable error message
+    (rather than to do a quick check).
+
     :param gisdbase: Path to GRASS GIS database directory
     :param location: name of a Location
     :param mapset: name of a Mapset
     :returns: translated message
     """
     full_location = os.path.join(gisdbase, location)
+    full_permanent = os.path.join(full_location, 'PERMANENT')
+    full_mapset = os.path.join(full_location, mapset)
+    # first checking the location validity
     if not os.path.exists(full_location):
         return _("Location <%s> doesn't exist") % full_location
     elif 'PERMANENT' not in os.listdir(full_location):
         return _("<%s> is not a valid GRASS Location"
                  " because PERMANENT Mapset is missing") % full_location
-    elif not os.path.isdir(os.path.join(full_location, 'PERMANENT')):
+    elif not os.path.isdir(full_permanent):
         return _("<%s> is not a valid GRASS Location"
                  " because PERMANENT is not a directory") % full_location
-    elif not os.path.isfile((os.path.join(full_location,
-                                          'PERMANENT', 'DEFAULT_WIND'))):
+    # partially based on the is_location_valid() function
+    elif not os.path.isfile(os.path.join(full_permanent,
+                                         'DEFAULT_WIND')):
         return _("<%s> is not a valid GRASS Location"
                  " because PERMANENT Mapset does not have a DEFAULT_WIND file"
                  " (default computational region)") % full_location
+    # if location is valid, check mapset
     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)):
+    elif not os.path.isdir(full_mapset):
         return _("<%s> is not a GRASS Mapset"
                  " because it is not a directory") % mapset
+    elif not os.path.isfile(os.path.join(full_mapset, 'WIND')):
+        return _("<%s> is not a valid GRASS Mapset"
+                 " because it does not have a WIND file") % mapset
+    # based on the is_mapset_valid() function
+    elif not os.access(os.path.join(full_mapset, "WIND"), os.R_OK):
+        return _("<%s> is not a valid GRASS Mapset"
+                 " because its WIND file is not readable") % mapset
     else:
-        return _("Mapset <{mapset}> is invalid for an unknown reason").format(
+        return _("Mapset <{mapset}> or Location <{location}> is"
+                 " invalid for an unknown reason").format(
                      mapset=mapset, loc=location)
 
 



More information about the grass-commit mailing list