[GRASS-SVN] r47442 - in grass/trunk: gui/wxpython/gui_modules
lib/python
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Aug 4 11:06:18 EDT 2011
Author: martinl
Date: 2011-08-04 08:06:18 -0700 (Thu, 04 Aug 2011)
New Revision: 47442
Modified:
grass/trunk/gui/wxpython/gui_modules/gselect.py
grass/trunk/lib/python/core.py
grass/trunk/lib/python/task.py
Log:
pythonlib: list_grouped() - check for search path optional
Modified: grass/trunk/gui/wxpython/gui_modules/gselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gselect.py 2011-08-04 14:46:36 UTC (rev 47441)
+++ grass/trunk/gui/wxpython/gui_modules/gselect.py 2011-08-04 15:06:18 UTC (rev 47442)
@@ -320,13 +320,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/trunk/lib/python/core.py
===================================================================
--- grass/trunk/lib/python/core.py 2011-08-04 14:46:36 UTC (rev 47441)
+++ grass/trunk/lib/python/core.py 2011-08-04 15:06:18 UTC (rev 47442)
@@ -608,7 +608,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
@@ -621,14 +621,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():
@@ -639,6 +641,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())
@@ -688,7 +692,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
@@ -702,12 +706,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",
@@ -718,7 +724,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/trunk/lib/python/task.py
===================================================================
--- grass/trunk/lib/python/task.py 2011-08-04 14:46:36 UTC (rev 47441)
+++ grass/trunk/lib/python/task.py 2011-08-04 15:06:18 UTC (rev 47442)
@@ -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