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

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Aug 4 11:22:17 EDT 2011


Author: martinl
Date: 2011-08-04 08:22:17 -0700 (Thu, 04 Aug 2011)
New Revision: 47445

Modified:
   grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gselect.py
   grass/branches/releasebranch_6_4/lib/python/core.py
   grass/branches/releasebranch_6_4/lib/python/task.py
Log:
pythonlib: list_grouped() - check for search path optional
          (merge r47439, r47441 & r47443  from devbr6)


Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gselect.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gselect.py	2011-08-04 15:21:50 UTC (rev 47444)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gselect.py	2011-08-04 15:22:17 UTC (rev 47445)
@@ -268,10 +268,6 @@
         # get current mapset
         curr_mapset = grass.gisenv()['MAPSET']
         
-        # list of mapsets in current location
-        if mapsets is None:
-            mapsets = utils.ListOfMapsets(get = 'accessible')
-        
         # map element types to g.mlist types
         elementdict = {'cell':'rast',
                        'raster':'rast',
@@ -322,18 +318,22 @@
             self.AddItem(_('Not selectable element'))
             return
         
-        # get directory tree nodes
-        # reorder mapsets based on search path (TODO)
-        for i in range(len(mapsets)):
-            if i > 0 and mapsets[i] == curr_mapset:
-                mapsets[i] = mapsets[0]
-                mapsets[0] = curr_mapset
-        
         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 = grass.mapsets()
+        
+        # current mapset first
+        if curr_mapset in mapsets and mapsets[0] != curr_mapset:
+            mapsets.remove(curr_mapset)
+            mapsets.insert(0, curr_mapset)
+        
         first_mapset = None
         for mapset in mapsets:
             mapset_node = self.AddItem('Mapset: ' + mapset)

Modified: grass/branches/releasebranch_6_4/lib/python/core.py
===================================================================
--- grass/branches/releasebranch_6_4/lib/python/core.py	2011-08-04 15:21:50 UTC (rev 47444)
+++ grass/branches/releasebranch_6_4/lib/python/core.py	2011-08-04 15:22:17 UTC (rev 47445)
@@ -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/releasebranch_6_4/lib/python/task.py
===================================================================
--- grass/branches/releasebranch_6_4/lib/python/task.py	2011-08-04 15:21:50 UTC (rev 47444)
+++ grass/branches/releasebranch_6_4/lib/python/task.py	2011-08-04 15:22:17 UTC (rev 47445)
@@ -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