[GRASS-SVN] r53929 - grass/trunk/lib/python/pygrass/modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Nov 19 14:34:20 PST 2012
Author: zarch
Date: 2012-11-19 14:34:20 -0800 (Mon, 19 Nov 2012)
New Revision: 53929
Modified:
grass/trunk/lib/python/pygrass/modules/__init__.py
Log:
Fix Parameter class for parameters with a range like v.mkgrid
Modified: grass/trunk/lib/python/pygrass/modules/__init__.py
===================================================================
--- grass/trunk/lib/python/pygrass/modules/__init__.py 2012-11-19 22:23:22 UTC (rev 53928)
+++ grass/trunk/lib/python/pygrass/modules/__init__.py 2012-11-19 22:34:20 UTC (rev 53929)
@@ -8,6 +8,7 @@
from __future__ import print_function
import subprocess
import fnmatch
+import re
try:
from collections import OrderedDict
@@ -145,13 +146,36 @@
self.description = diz.get('description', None)
self.keydesc = diz.get('keydesc', None)
- self.values = [self._type(
- i) for i in diz['values']] if 'values' in diz else None
+
+ #
+ # values
+ #
+ if 'values' in diz:
+ try:
+ # chek if it's a range string: "3-30"
+ isrange = re.match("(?P<min>\d+)-(?P<max>\d+)",
+ diz['values'][0])
+ if isrange:
+ range_min, range_max = isrange.groups()
+ self.values = range(int(range_min), int(range_max) + 1)
+ self.isrange = diz['values'][0]
+ except TypeError:
+ self.values = [self._type(i) for i in diz['values']]
+ self.isrange = False
+
+ #
+ # default
+ #
self.default = self._type(
diz['default']) if 'default' in diz else None
if self.default is not None:
self._value = self.default
+
self.guisection = diz.get('guisection', None)
+
+ #
+ # gisprompt
+ #
if 'gisprompt' in diz:
self.type = diz['gisprompt']['prompt']
self.input = False if diz['gisprompt']['age'] == 'new' else True
@@ -171,7 +195,7 @@
str_err = 'The Parameter <%s> does not accept multiple inputs'
raise TypeError(str_err % self.name)
elif isinstance(value, self._type):
- if self.values:
+ if hasattr(self, 'values'):
if value in self.values:
self._value = value
else:
@@ -218,14 +242,19 @@
{name}: {default}{required}{multi}{ptype}
{description}{values}"","""
+ if hasattr(self, 'values'):
+ if self.isrange:
+ vals = self.isrange
+ else:
+ vals = ', '.join([repr(val) for val in self.values])
+ else:
+ vals = False
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(', '.join([repr(val)
- for val in self.values]))
- if self.values else '')
+ values='\n Values: {0}'.format(vals) if vals else '')
class TypeDict(OrderedDict):
More information about the grass-commit
mailing list