[GRASS-SVN] r47443 - in grass/branches/develbranch_6: gui/wxpython/gui_modules lib/python

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Aug 4 11:07:20 EDT 2011


Author: martinl
Date: 2011-08-04 08:07:20 -0700 (Thu, 04 Aug 2011)
New Revision: 47443

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/gselect.py
   grass/branches/develbranch_6/lib/python/core.py
   grass/branches/develbranch_6/lib/python/task.py
Log:
pythonlib: list_grouped() - check for search path optional
	   (merge r47442 from trunk)


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gselect.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gselect.py	2011-08-04 15:06:18 UTC (rev 47442)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gselect.py	2011-08-04 15:07:20 UTC (rev 47443)
@@ -319,13 +319,14 @@
             return
         
         if globalvar.have_mlist:
-            filesdict = grass.mlist_grouped(elementdict[element])
+            filesdict = grass.mlist_grouped(elementdict[element],
+                                            check_search_path = False)
         else:
-            filesdict = grass.list_grouped(elementdict[element])
+            filesdict = grass.list_grouped(elementdict[element],
+                                           check_search_path = False)
         
         # list of mapsets in current location
         if mapsets is None:
-            # mapsets = filesdict.keys()
             mapsets = grass.mapsets()
         
         # current mapset first

Modified: grass/branches/develbranch_6/lib/python/core.py
===================================================================
--- grass/branches/develbranch_6/lib/python/core.py	2011-08-04 15:06:18 UTC (rev 47442)
+++ grass/branches/develbranch_6/lib/python/core.py	2011-08-04 15:07:20 UTC (rev 47443)
@@ -599,7 +599,7 @@
 
 # interface to g.list
 
-def list_grouped(type):
+def list_grouped(type, check_search_path = True):
     """!List elements grouped by mapsets.
 
     Returns the output from running g.list, as a dictionary where the
@@ -612,14 +612,16 @@
     @endcode
     
     @param type element type (rast, vect, rast3d, region, ...)
+    @param check_search_path True to add mapsets for the search path with no found elements
 
     @return directory of mapsets/elements
     """
     dashes_re = re.compile("^----+$")
     mapset_re = re.compile("<(.*)>")
     result = {}
-    for mapset in mapsets(accessible = True):
-        result[mapset] = []
+    if check_search_path:
+        for mapset in mapsets(accessible = True):
+            result[mapset] = []
     
     mapset = None
     for line in read_command("g.list", type = type).splitlines():
@@ -630,6 +632,8 @@
 	m = mapset_re.search(line)
 	if m:
 	    mapset = m.group(1)
+            if mapset not in result.keys():
+                result[mapset] = []
 	    continue
         if mapset:
             result[mapset].extend(line.split())
@@ -679,7 +683,7 @@
 
 # interface to g.mlist
 
-def mlist_grouped(type, pattern = None):
+def mlist_grouped(type, pattern = None, check_search_path = True):
     """!List of elements grouped by mapsets.
 
     Returns the output from running g.mlist, as a dictionary where the
@@ -693,12 +697,14 @@
     
     @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
 
     @return directory of mapsets/elements
     """
     result = {}
-    for mapset in mapsets(accessible = True):
-        result[mapset] = []
+    if check_search_path:
+        for mapset in mapsets(accessible = True):
+            result[mapset] = []
     
     mapset = None
     for line in read_command("g.mlist", flags = "m",
@@ -709,7 +715,10 @@
             warning(_("Invalid element '%s'") % line)
             continue
         
-        result[mapset].append(name)
+        if mapset in result:
+            result[mapset].append(name) 
+        else:  	  	 
+            result[mapset] = [name, ] 
     
     return result
 

Modified: grass/branches/develbranch_6/lib/python/task.py
===================================================================
--- grass/branches/develbranch_6/lib/python/task.py	2011-08-04 15:06:18 UTC (rev 47442)
+++ grass/branches/develbranch_6/lib/python/task.py	2011-08-04 15:07:20 UTC (rev 47443)
@@ -430,12 +430,12 @@
         cmdout, cmderr = Popen([cmd, '--interface-description'], stdout = PIPE,
                                      stderr = PIPE).communicate()
     except OSError, e:
-        raise ScriptError, _("Unable to fetch interface description for command '%s'."
-                             "\n\nDetails: %s") % (cmd, e)
+        raise ScriptError, _("Unable to fetch interface description for command '%(cmd)s'."
+                             "\n\nDetails: %(det)s") % { 'cmd' : cmd, 'det' : e }
     
     if cmderr and cmderr[:7] != 'WARNING':
-        raise ScriptError, _("Unable to fetch interface description for command '%s'."
-                             "\n\nDetails: %s") % (cmd, decode(cmderr))
+        raise ScriptError, _("Unable to fetch interface description for command '%(cmd)s'."
+                             "\n\nDetails: %(det)s") % { 'cmd': cmd, 'det' : decode(cmderr) }
     
     return cmdout.replace('grass-interface.dtd', os.path.join(os.getenv('GISBASE'), 'etc', 'grass-interface.dtd'))
 



More information about the grass-commit mailing list