[GRASS-SVN] r55598 - grass/trunk/lib/python/pygrass/gis
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Apr 3 01:13:52 PDT 2013
Author: zarch
Date: 2013-04-03 01:13:52 -0700 (Wed, 03 Apr 2013)
New Revision: 55598
Modified:
grass/trunk/lib/python/pygrass/gis/__init__.py
Log:
Add new methods to the Mapset class to set, delete mapsets.
Modified: grass/trunk/lib/python/pygrass/gis/__init__.py
===================================================================
--- grass/trunk/lib/python/pygrass/gis/__init__.py 2013-04-03 08:13:44 UTC (rev 55597)
+++ grass/trunk/lib/python/pygrass/gis/__init__.py 2013-04-03 08:13:52 UTC (rev 55598)
@@ -4,6 +4,7 @@
#import os
from os import listdir
from os.path import join
+import shutil
import ctypes as ct
import fnmatch
@@ -59,6 +60,14 @@
join(path, value)))
+def set_current_mapset(mapset, location=None, gisdbase=None):
+ libgis.G_setenv('MAPSET', mapset)
+ if location:
+ libgis.G_setenv('LOCATION_NAME', location)
+ if gisdbase:
+ libgis.G_setenv('GISDBASEE', gisdbase)
+
+
def make_mapset(mapset, location=None, gisdbase=None):
if libgis.G__make_mapset(gisdbase, location, mapset) != 0:
raise GrassError("I cannot create a new mapset.")
@@ -187,14 +196,17 @@
def __repr__(self):
return 'Location(%r)' % self.name
- def mapsets(self):
+ def mapsets(self, pattern=None):
"""Return a list of the available mapsets. ::
>>> location = Location()
>>> location.mapsets()
['PERMANENT', 'user1']
"""
- return [mapset for mapset in self]
+ mapsets = [mapset for mapset in self]
+ if pattern:
+ return fnmatch.filter(mapsets, pattern)
+ return mapsets
class Mapset(object):
@@ -285,3 +297,18 @@
if pattern:
return fnmatch.filter(elist, pattern)
return elist
+
+ def is_current(self):
+ return (self.name == libgis.G_getenv('MAPSET') and
+ self.location == libgis.G_getenv('LOCATION_NAME') and
+ self.gisdbase == libgis.G_getenv('GISDBASE'))
+
+ def current(self):
+ """Set the mapset as current"""
+ set_current_mapset(self.name, self.location, self.gisdbase)
+
+ def delete(self):
+ """Delete the mapset"""
+ if self.is_current():
+ raise GrassError('The mapset is in use.')
+ shutil.rmtree(join(self.gisdbase, self.location, self.name))
More information about the grass-commit
mailing list