Przeglądaj źródła

pythonlib: list_grouped() - check for search path optional

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@47442 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 13 lat temu
rodzic
commit
492df342e2
3 zmienionych plików z 24 dodań i 14 usunięć
  1. 4 3
      gui/wxpython/gui_modules/gselect.py
  2. 16 7
      lib/python/core.py
  3. 4 4
      lib/python/task.py

+ 4 - 3
gui/wxpython/gui_modules/gselect.py

@@ -320,13 +320,14 @@ class TreeCtrlComboPopup(wx.combo.ComboPopup):
             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

+ 16 - 7
lib/python/core.py

@@ -608,7 +608,7 @@ def find_file(name, element = 'cell', mapset = None):
 
 # 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
@@ -621,14 +621,16 @@ def list_grouped(type):
     @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():
@@ -639,6 +641,8 @@ def list_grouped(type):
 	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())
@@ -688,7 +692,7 @@ def list_strings(type):
 
 # 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
@@ -702,12 +706,14 @@ def mlist_grouped(type, pattern = None):
     
     @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",
@@ -718,7 +724,10 @@ def mlist_grouped(type, pattern = None):
             warning(_("Invalid element '%s'") % line)
             continue
         
-        result[mapset].append(name)
+        if mapset in result:
+            result[mapset].append(name) 
+        else:  	  	 
+            result[mapset] = [name, ] 
     
     return result
 

+ 4 - 4
lib/python/task.py

@@ -430,12 +430,12 @@ def get_interface_description(cmd):
         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'))