[GRASS-SVN] r58115 - grass/trunk/lib/python/pygrass
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Oct 28 07:08:03 PDT 2013
Author: zarch
Date: 2013-10-28 07:08:02 -0700 (Mon, 28 Oct 2013)
New Revision: 58115
Modified:
grass/trunk/lib/python/pygrass/functions.py
Log:
Add a function to look for a map in a different mapset, location, gisdbase
Modified: grass/trunk/lib/python/pygrass/functions.py
===================================================================
--- grass/trunk/lib/python/pygrass/functions.py 2013-10-28 12:35:12 UTC (rev 58114)
+++ grass/trunk/lib/python/pygrass/functions.py 2013-10-28 14:08:02 UTC (rev 58115)
@@ -44,6 +44,53 @@
return res
+def findmaps(type, pattern=None, mapset='', location='', gisdbase=''):
+ """Return a list of tuple contining the names of the:
+ * map
+ * mapset,
+ * location,
+ * gisdbase
+
+ """
+ from grass.pygrass.gis import Gisdbase, Location, Mapset
+
+ def find_in_location(type, pattern, location):
+ res = []
+ for msetname in location.mapsets():
+ mset = Mapset(msetname, location.name, location.gisdbase)
+ res.extend([(m, mset.name, mset.location, mset.gisdbase)
+ for m in mset.glist(type, pattern)])
+ return res
+
+ def find_in_gisdbase(type, pattern, gisdbase):
+ res = []
+ for loc in gisdbase.locations():
+ res.extend(find_in_location(type, pattern,
+ Location(loc, gisdbase.name)))
+ return res
+
+ if gisdbase and location and mapset:
+ mset = Mapset(mapset, location, gisdbase)
+ return [(m, mset.name, mset.location, mset.gisdbase)
+ for m in mset.glist(type, pattern)]
+ elif gisdbase and location:
+ loc = Location(location, gisdbase)
+ return find_in_location(type, pattern, loc)
+ elif gisdbase:
+ gis = Gisdbase(gisdbase)
+ return find_in_gisdbase(type, pattern, gis)
+ elif location:
+ loc = Location(location)
+ return find_in_location(type, pattern, loc)
+ elif mapset:
+ mset = Mapset(mapset)
+ return [(m, mset.name, mset.location, mset.gisdbase)
+ for m in mset.glist(type, pattern)]
+ else:
+ gis = Gisdbase()
+ return find_in_gisdbase(type, pattern, gis)
+
+
def remove(oldname, maptype):
"""Remove a map"""
grasscore.run_command('g.remove', quiet=True,
More information about the grass-commit
mailing list