[GRASS-SVN] r44492 - in grass/branches/releasebranch_6_4: gui/wxpython/gui_modules lib/python

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Nov 29 16:08:42 EST 2010


Author: martinl
Date: 2010-11-29 13:08:42 -0800 (Mon, 29 Nov 2010)
New Revision: 44492

Modified:
   grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gdialogs.py
   grass/branches/releasebranch_6_4/lib/python/core.py
Log:
pythonlib: define mlist()
(merge r44489 from devbr6)


Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gdialogs.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gdialogs.py	2010-11-29 21:07:25 UTC (rev 44491)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gdialogs.py	2010-11-29 21:08:42 UTC (rev 44492)
@@ -828,11 +828,7 @@
         @param type layer type ('raster' or 'vector')
         @param mapset mapset name
         """
-        try:
-            self.map_layers = grass.mlist_grouped(type=type, mapset=mapset)[mapset]
-        except KeyError:
-            self.map_layers = []
-        
+        self.map_layers = grass.mlist(type = type, mapset = mapset)
         self.layers.Set(self.map_layers)
         
         # check all items by default

Modified: grass/branches/releasebranch_6_4/lib/python/core.py
===================================================================
--- grass/branches/releasebranch_6_4/lib/python/core.py	2010-11-29 21:07:25 UTC (rev 44491)
+++ grass/branches/releasebranch_6_4/lib/python/core.py	2010-11-29 21:08:42 UTC (rev 44492)
@@ -613,40 +613,6 @@
     
     return result
 
-def mlist_grouped(type, pattern = None):
-    """!List of elements grouped by mapsets.
-
-    Returns the output from running g.mlist, as a dictionary where the
-    keys are mapset names and the values are lists of maps in that
-    mapset. Example:
-
-    @code
-    >>> grass.mlist_grouped('rast', pattern='r*')['PERMANENT']
-    ['railroads', 'roads', 'rstrct.areas', 'rushmore']
-    @endcode
-    
-    @param type element type (rast, vect, rast3d, region, ...)
-    @param pattern pattern string
-
-    @return directory of mapsets/elements
-    """
-    result = {}
-    mapset_element = None
-    for line in read_command("g.mlist", flags="m",
-                             type = type, pattern = pattern).splitlines():
-        try:
-            map, mapset_element = line.split('@')
-        except ValueError:
-            print >> sys.stderr, "Invalid element '%s'" % line
-            continue
-        
-        if result.has_key(mapset_element):
-            result[mapset_element].append(map)
-        else:
-	    result[mapset_element] = [map, ]
-    
-    return result
-
 def _concat(xs):
     result = []
     for x in xs:
@@ -688,6 +654,60 @@
     """
     return ["%s@%s" % pair for pair in list_pairs(type)]
 
+# interface to g.mlist
+
+def mlist(type, pattern = None, mapset = None):
+    """!List of elements
+
+    @param type element type (rast, vect, rast3d, region, ...)
+    @param pattern pattern string
+    @param mapset mapset name (if not given use search path)
+
+    @return list of elements
+    """
+    result = list()
+    for line in read_command("g.mlist",
+                             type = type,
+                             pattern = pattern,
+                             mapset = mapset).splitlines():
+        result.append(line.strip())
+    
+    return result
+    
+def mlist_grouped(type, pattern = None):
+    """!List of elements grouped by mapsets.
+
+    Returns the output from running g.mlist, as a dictionary where the
+    keys are mapset names and the values are lists of maps in that
+    mapset. Example:
+
+    @code
+    >>> grass.mlist_grouped('rast', pattern='r*')['PERMANENT']
+    ['railroads', 'roads', 'rstrct.areas', 'rushmore']
+    @endcode
+    
+    @param type element type (rast, vect, rast3d, region, ...)
+    @param pattern pattern string
+
+    @return directory of mapsets/elements
+    """
+    result = dict()
+    mapset_element = None
+    for line in read_command("g.mlist", flags = "m",
+                             type = type, pattern = pattern).splitlines():
+        try:
+            map, mapset_element = line.split('@')
+        except ValueError:
+            warning(_("Invalid element '%s'") % line)
+            continue
+        
+        if result.has_key(mapset_element):
+            result[mapset_element].append(map)
+        else:
+	    result[mapset_element] = [map, ]
+    
+    return result
+
 # color parsing
 
 named_colors = {



More information about the grass-commit mailing list