[GRASS-SVN] r50977 - grass/branches/develbranch_6/lib/python

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Mar 3 09:49:26 EST 2012


Author: martinl
Date: 2012-03-03 06:49:26 -0800 (Sat, 03 Mar 2012)
New Revision: 50977

Modified:
   grass/branches/develbranch_6/lib/python/core.py
Log:
glynn: Add mlist_strings, mlist_pairs
       Add flag= option to mlist_*
       (merge r50971 from trunk)


Modified: grass/branches/develbranch_6/lib/python/core.py
===================================================================
--- grass/branches/develbranch_6/lib/python/core.py	2012-03-03 08:46:05 UTC (rev 50976)
+++ grass/branches/develbranch_6/lib/python/core.py	2012-03-03 14:49:26 UTC (rev 50977)
@@ -686,7 +686,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
@@ -701,6 +740,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
     """
@@ -710,7 +750,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