[GRASS-SVN] r60491 - in grass/trunk/lib/python/pygrass: docs gis

svn_grass at osgeo.org svn_grass at osgeo.org
Mon May 26 06:49:09 PDT 2014


Author: lucadelu
Date: 2014-05-26 06:49:09 -0700 (Mon, 26 May 2014)
New Revision: 60491

Modified:
   grass/trunk/lib/python/pygrass/docs/gis.rst
   grass/trunk/lib/python/pygrass/gis/__init__.py
Log:
pygrass: improve documentation of Region class; add method to reset the SEARCH_PATH

Modified: grass/trunk/lib/python/pygrass/docs/gis.rst
===================================================================
--- grass/trunk/lib/python/pygrass/docs/gis.rst	2014-05-26 11:53:50 UTC (rev 60490)
+++ grass/trunk/lib/python/pygrass/docs/gis.rst	2014-05-26 13:49:09 UTC (rev 60491)
@@ -1,7 +1,10 @@
 
-Location and region management
-========
+GRASS database management
+===============================
 
+These classes are used to manage the infrastructure
+of GRASS database: Gisdbase, Location and Mapset
+
 .. autoclass:: pygrass.gis.Gisdbase
     :members:
 
@@ -14,3 +17,11 @@
 .. autoclass:: pygrass.gis.VisibleMapset
     :members:
 
+Region management
+======================
+
+The Region class it is useful to obtain information
+about the computational region and to change it.
+
+.. autoclass:: pygrass.gis.region.Region
+    :members:

Modified: grass/trunk/lib/python/pygrass/gis/__init__.py
===================================================================
--- grass/trunk/lib/python/pygrass/gis/__init__.py	2014-05-26 11:53:50 UTC (rev 60490)
+++ grass/trunk/lib/python/pygrass/gis/__init__.py	2014-05-26 13:49:09 UTC (rev 60491)
@@ -154,6 +154,8 @@
         True
         >>> location.name == gisenv()['LOCATION_NAME']
         True
+
+    ..
     """
     def __init__(self, location='', gisdbase=''):
         self.gisdbase = gisdbase
@@ -324,6 +326,12 @@
 
 
 class VisibleMapset(object):
+    """VisibleMapset object::
+
+        >>> mapset = VisibleMapset('user1')
+        >>> mapset
+        ['user1', 'PERMANENT']
+    """
     def __init__(self, mapset, location='', gisdbase=''):
         self.mapset = mapset
         self.location = Location(location, gisdbase)
@@ -338,6 +346,7 @@
             yield mapset
 
     def read(self):
+        """Return the mapsets in the search path"""
         with open(self.spath, "a+") as f:
             lines = f.readlines()
             #lines.remove('')
@@ -347,12 +356,14 @@
         self.write(lns)
         return lns
 
-    def write(self, mapsets):
+    def _write(self, mapsets):
+        """Write to SEARCH_PATH file the changes in the search path"""
         with open(self.spath, "w+") as f:
             ms = self.location.mapsets()
             f.write('%s' % '\n'.join([m for m in mapsets if m in ms]))
 
     def add(self, mapset):
+        """Add a mapset to the search path"""
         if mapset not in self.read() and mapset in self.location:
             with open(self.spath, "a+") as f:
                 f.write('\n%s' % mapset)
@@ -360,12 +371,19 @@
             raise TypeError('Mapset not found')
 
     def remove(self, mapset):
+        """Remove mapset to the search path"""
         mapsets = self.read()
         mapsets.remove(mapset)
-        self.write(mapsets)
+        self._write(mapsets)
 
     def extend(self, mapsets):
+        """Add more mapsets to the search path"""
         ms = self.location.mapsets()
         final = self.read()
         final.extend([m for m in mapsets if m in ms and m not in final])
-        self.write(final)
+        self._write(final)
+
+    def reset(self):
+        """Reset to the original search path"""
+        final = [self.mapset, 'PERMANENT']
+        self._write(final)



More information about the grass-commit mailing list