[GRASS-SVN] r65605 - grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Jul 18 06:02:23 PDT 2015
Author: martinl
Date: 2015-07-18 06:02:23 -0700 (Sat, 18 Jul 2015)
New Revision: 65605
Modified:
grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface/flag.py
grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface/module.py
grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface/read.py
Log:
Add suppress_required attribute to the Flag object
pygrass: Add a new method to check the correctness of the provide parameter, a new special parameter: check_ is added to skip the check
(merge r65596, r65598 from trunk)
Modified: grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface/flag.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface/flag.py 2015-07-18 13:00:42 UTC (rev 65604)
+++ grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface/flag.py 2015-07-18 13:02:23 UTC (rev 65605)
@@ -33,6 +33,7 @@
self.description = diz.get('description', None)
self.default = diz.get('default', None)
self.guisection = diz.get('guisection', None)
+ self.suppress_required = True if 'suppress_required' in diz else False
def get_bash(self):
"""Return the BASH representation of a flag.
@@ -88,11 +89,18 @@
"""Return a string with the python representation of the instance."""
return "Flag <%s> (%s)" % (self.name, self.description)
+ def __bool__(self):
+ """Return a boolean value"""
+ return self.value
+
+ def __nonzero__(self):
+ return self.__bool__()
+
@docstring_property(__doc__)
def __doc__(self):
"""Return a documentation string, something like:
- {name}: {default}
+ {name}: {default}, suppress required {supress}
{description}
>>> flag = Flag(diz=dict(name='a', description='Flag description',
@@ -109,4 +117,7 @@
"""
return read.DOC['flag'].format(name=self.name,
default=repr(self.default),
- description=self.description)
+ description=self.description,
+ supress=('suppress required'
+ if self.suppress_required
+ else ''))
Modified: grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface/module.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface/module.py 2015-07-18 13:00:42 UTC (rev 65604)
+++ grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface/module.py 2015-07-18 13:02:23 UTC (rev 65605)
@@ -504,6 +504,7 @@
#
self.run_ = True
self.finish_ = True
+ self.check_ = True
self.env_ = None
self.stdin_ = None
self.stdin = None
@@ -543,7 +544,7 @@
del(kargs['flags'])
# set attributs
- for key in ('run_', 'env_', 'finish_', 'stdout_', 'stderr_'):
+ for key in ('run_', 'env_', 'finish_', 'stdout_', 'stderr_', 'check_'):
if key in kargs:
setattr(self, key, kargs.pop(key))
@@ -553,7 +554,7 @@
self.inputs[key[:-1]].value = kargs.pop(key)
#
- # check args
+ # set/update args
#
for param, arg in zip(self.params_list, args):
param.value = arg
@@ -576,11 +577,8 @@
#
# check reqire parameters
#
- for k in self.required:
- if ((k in self.inputs and self.inputs[k].value is None) or
- (k in self.outputs and self.outputs[k].value is None)):
- msg = "Required parameter <%s> not set."
- raise ParameterError(msg % k)
+ if self.check_:
+ self.check()
return self.run()
return self
@@ -634,6 +632,19 @@
flags = self.flags.__doc__
return '\n'.join([head, params, DOC['flag_head'], flags, DOC['foot']])
+ def check(self):
+ """Check the correctness of the provide parameters"""
+ required = True
+ for flg in self.flags.values():
+ if flg and flg.suppress_required:
+ required = False
+ if required:
+ for k in self.required:
+ if ((k in self.inputs and self.inputs[k].value is None) or
+ (k in self.outputs and self.outputs[k].value is None)):
+ msg = "Required parameter <%s> not set."
+ raise ParameterError(msg % k)
+
def get_dict(self):
"""Return a dictionary that includes the name, all valid
inputs, outputs and flags
Modified: grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface/read.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface/read.py 2015-07-18 13:00:42 UTC (rev 65604)
+++ grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface/read.py 2015-07-18 13:02:23 UTC (rev 65605)
@@ -91,7 +91,7 @@
""",
#------------------------------------------------------------
# flag
- 'flag': """{name}: {default}
+ 'flag': """{name}: {default}, {supress}
{description}""",
#------------------------------------------------------------
# foot
More information about the grass-commit
mailing list