[GRASS-SVN] r47429 - grass/branches/develbranch_6/lib/python
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Aug 4 08:52:31 EDT 2011
Author: martinl
Date: 2011-08-04 05:52:31 -0700 (Thu, 04 Aug 2011)
New Revision: 47429
Modified:
grass/branches/develbranch_6/lib/python/core.py
Log:
pythonlib: fix list_grouped() to list all mapsets in the search path
remove mlist() - can be replaced by mlist_grouped()
(merge r47427 from trunk)
Modified: grass/branches/develbranch_6/lib/python/core.py
===================================================================
--- grass/branches/develbranch_6/lib/python/core.py 2011-08-04 12:51:08 UTC (rev 47428)
+++ grass/branches/develbranch_6/lib/python/core.py 2011-08-04 12:52:31 UTC (rev 47429)
@@ -618,6 +618,9 @@
dashes_re = re.compile("^----+$")
mapset_re = re.compile("<(.*)>")
result = {}
+ for mapset in mapsets(accessible = True):
+ result[mapset] = []
+
mapset = None
for line in read_command("g.list", type = type).splitlines():
if line == "":
@@ -627,7 +630,6 @@
m = mapset_re.search(line)
if m:
mapset = m.group(1)
- result[mapset] = []
continue
if mapset:
result[mapset].extend(line.split())
@@ -677,24 +679,6 @@
# 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.
@@ -712,20 +696,20 @@
@return directory of mapsets/elements
"""
- result = dict()
- mapset_element = None
+ result = {}
+ for mapset in mapsets(accessible = True):
+ result[mapset] = []
+
+ mapset = None
for line in read_command("g.mlist", flags = "m",
type = type, pattern = pattern).splitlines():
try:
- map, mapset_element = line.split('@')
+ name, mapset = line.split('@')
except ValueError:
warning(_("Invalid element '%s'") % line)
continue
- if mapset_element in result:
- result[mapset_element].append(map)
- else:
- result[mapset_element] = [map, ]
+ result[mapset].append(name)
return result
More information about the grass-commit
mailing list