[GRASS-SVN] r55052 - grass/trunk/lib/python/pygrass/modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Feb 14 07:30:07 PST 2013
Author: zarch
Date: 2013-02-14 07:30:07 -0800 (Thu, 14 Feb 2013)
New Revision: 55052
Modified:
grass/trunk/lib/python/pygrass/modules/__init__.py
Log:
Add support for modules with key with more than one values and that are not multiple
Modified: grass/trunk/lib/python/pygrass/modules/__init__.py
===================================================================
--- grass/trunk/lib/python/pygrass/modules/__init__.py 2013-02-14 15:29:58 UTC (rev 55051)
+++ grass/trunk/lib/python/pygrass/modules/__init__.py 2013-02-14 15:30:07 UTC (rev 55052)
@@ -22,6 +22,14 @@
from grass.pygrass.errors import GrassError, ParameterError
+
+def _read_keydesc(par):
+ name = par.text.strip()
+ items = [e.text.strip() for e in par.findall('item')]
+ #import ipdb; ipdb.set_trace()
+ return name, tuple(items) if len(items) > 1 else None
+
+
#
# this dictionary is used to extract the value of interest from the xml
# the lambda experssion is used to define small simple functions,
@@ -34,7 +42,7 @@
#
_GETFROMTAG = {
'description': lambda p: p.text.strip(),
- 'keydesc': lambda p: p.text.strip(),
+ 'keydesc': _read_keydesc,
'gisprompt': lambda p: dict(p.items()),
'default': lambda p: p.text.strip(),
'values': lambda p: [e.text.strip() for e in p.findall('value/name')],
@@ -53,7 +61,6 @@
'all': lambda x: x,
}
-
def _element2dict(xparameter):
diz = dict(xparameter.items())
for p in xparameter:
@@ -76,7 +83,7 @@
#------------------------------------------------------------
# param
'param': """{name}: {default}{required}{multi}{ptype}
- {description}{values}""",
+ {description}{values}{keydescvalues}""",
#------------------------------------------------------------
# flag_head
'flag_head': """
@@ -125,7 +132,7 @@
raise TypeError('New type: %s, ignored' % diz['type'])
self.description = diz.get('description', None)
- self.keydesc = diz.get('keydesc', None)
+ self.keydesc, self.keydescvalues = diz.get('keydesc', (None, None))
#
# values
@@ -170,7 +177,7 @@
def _set_value(self, value):
if isinstance(value, list) or isinstance(value, tuple):
- if self.multiple:
+ if self.multiple or self.keydescvalues:
# check each value
self._value = [self._type(val) for val in value]
else:
@@ -233,12 +240,14 @@
vals = ', '.join([repr(val) for val in self.values])
else:
vals = False
+ keydescvals = "\n (%s)" % ', '.join(self.keydescvalues)
return _DOC['param'].format(name=self.name,
default=repr(self.default) + ', ' if self.default else '',
required='required, ' if self.required else 'optional, ',
multi='multi' if self.multiple else '',
ptype=self.typedesc, description=self.description,
- values='\n Values: {0}'.format(vals) if vals else '')
+ values='\n Values: {0}'.format(vals) if vals else '',
+ keydescvalues= keydescvals if self.keydescvalues else '')
class TypeDict(OrderedDict):
@@ -591,7 +600,7 @@
class MetaModule(object):
"""Example how to use MetaModule
-
+
>>> g = MetaModule('g')
>>> g_mlist = g.mlist
>>> g_mlist.name
More information about the grass-commit
mailing list