[GRASS-SVN] r50971 - grass/trunk/lib/python
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Mar 2 11:55:37 EST 2012
Author: glynn
Date: 2012-03-02 08:55:37 -0800 (Fri, 02 Mar 2012)
New Revision: 50971
Modified:
grass/trunk/lib/python/core.py
Log:
Add mlist_strings, mlist_pairs
Add flag= option to mlist_*
Modified: grass/trunk/lib/python/core.py
===================================================================
--- grass/trunk/lib/python/core.py 2012-03-02 13:56:51 UTC (rev 50970)
+++ grass/trunk/lib/python/core.py 2012-03-02 16:55:37 UTC (rev 50971)
@@ -706,7 +706,46 @@
# interface to g.mlist
-def mlist_grouped(type, pattern = None, check_search_path = True):
+def mlist_strings(type, pattern = None, mapset = None, flag = ''):
+ """!List of elements as strings.
+
+ Returns the output from running g.mlist, as a list of qualified
+ names.
+
+ @param type element type (rast, vect, rast3d, region, ...)
+ @param pattern pattern string
+ @param mapset mapset name (if not given use search path)
+ @param flag pattern type: 'r' (basic regexp), 'e' (extended regexp), or '' (glob pattern)
+
+ @return list of elements
+ """
+ result = list()
+ for line in read_command("g.mlist",
+ quiet = True,
+ flags = 'm' + flag,
+ type = type,
+ pattern = pattern,
+ mapset = mapset).splitlines():
+ result.append(line.strip())
+
+ return result
+
+def mlist_pairs(type, pattern = None, mapset = None, flag = ''):
+ """!List of elements as pairs
+
+ Returns the output from running g.mlist, as a list of
+ (name, mapset) pairs
+
+ @param type element type (rast, vect, rast3d, region, ...)
+ @param pattern pattern string
+ @param mapset mapset name (if not given use search path)
+ @param flag pattern type: 'r' (basic regexp), 'e' (extended regexp), or '' (glob pattern)
+
+ @return list of elements
+ """
+ return [tuple(map.split('@', 1)) for map in mlist_strings(type, pattern, mapset, flag)]
+
+def mlist_grouped(type, pattern = None, check_search_path = True, flag = ''):
"""!List of elements grouped by mapsets.
Returns the output from running g.mlist, as a dictionary where the
@@ -721,6 +760,7 @@
@param type element type (rast, vect, rast3d, region, ...)
@param pattern pattern string
@param check_search_path True to add mapsets for the search path with no found elements
+ @param flag pattern type: 'r' (basic regexp), 'e' (extended regexp), or '' (glob pattern)
@return directory of mapsets/elements
"""
@@ -730,7 +770,7 @@
result[mapset] = []
mapset = None
- for line in read_command("g.mlist", quiet = True, flags = "m",
+ for line in read_command("g.mlist", quiet = True, flags = "m" + flag,
type = type, pattern = pattern).splitlines():
try:
name, mapset = line.split('@')
More information about the grass-commit
mailing list