multi types with None
This commit is contained in:
parent
2569cc5e59
commit
13c4819b14
3 changed files with 31 additions and 20 deletions
27
autolib.py
27
autolib.py
|
@ -19,8 +19,7 @@
|
|||
# the whole pypy projet is under MIT licence
|
||||
# ____________________________________________________________
|
||||
"enables us to carry out a calculation and return an option's value"
|
||||
from tiramisu.error import DisabledOptionError, SpecialOwnersError, ConfigError
|
||||
from creole import eosfunc
|
||||
from tiramisu.error import DisabledOptionError, SpecialOwnersError
|
||||
# ____________________________________________________________
|
||||
# automatic Option object
|
||||
special_owners = ['auto', 'fill']
|
||||
|
@ -52,9 +51,10 @@ def calc_factory(name, callback, callback_params, config):
|
|||
raise DisabledOptionError(e)
|
||||
is_multi = opt.is_multi()
|
||||
if is_multi:
|
||||
if opt_value != None:
|
||||
len_value = len(opt_value)
|
||||
if len_multi != 0 and len_multi != len_value:
|
||||
raise ConfigError('unable to carry out a calculation, '
|
||||
raise SpecialOwnersError('unable to carry out a calculation, '
|
||||
'option values with multi types must have same length for: '
|
||||
+ name)
|
||||
len_multi = len_value
|
||||
|
@ -69,19 +69,26 @@ def calc_factory(name, callback, callback_params, config):
|
|||
tcp = {}
|
||||
for key, couple in tcparams.items():
|
||||
value, ismulti = couple
|
||||
if ismulti:
|
||||
if ismulti and value != None:
|
||||
tcp[key] = value[incr]
|
||||
else:
|
||||
tcp[key] = value
|
||||
ret.append(calculate(callback, tcp))
|
||||
ret.append(calculate(name, callback, tcp))
|
||||
return ret
|
||||
else:
|
||||
return calculate(callback, tcparams)
|
||||
tcp = {}
|
||||
for key, couple in tcparams.items():
|
||||
tcp[key] = couple[0]
|
||||
return calculate(name, callback, tcp)
|
||||
|
||||
def calculate(callback, tcparams):
|
||||
def calculate(name, callback, tcparams):
|
||||
try:
|
||||
# XXX not only creole...
|
||||
from creole import eosfunc
|
||||
return getattr(eosfunc, callback)(**tcparams)
|
||||
except AttributeError:
|
||||
raise SpecialOwnersError("callback: {0} not found for "
|
||||
"option: {1}".format(callback, name))
|
||||
except AttributeError, err:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
raise SpecialOwnersError("callback: {0} return error {1} for "
|
||||
"option: {2}".format(callback, str(err), name))
|
||||
|
||||
|
|
|
@ -203,9 +203,8 @@ class Config(object):
|
|||
if owner == 'fill' and None not in value:
|
||||
return value
|
||||
else:
|
||||
if owner == 'fill':
|
||||
if owner == 'fill' and value != None:
|
||||
return value
|
||||
# ______________________________________________________________
|
||||
result = special_owner_factory(name, owner,
|
||||
value=value,
|
||||
callback=opt_or_descr.getcallback(),
|
||||
|
@ -233,7 +232,6 @@ class Config(object):
|
|||
else:
|
||||
_result = result
|
||||
return _result
|
||||
# ______________________________________________________________
|
||||
# mandatory options
|
||||
if not isinstance(opt_or_descr, OptionDescription):
|
||||
homeconfig = self._cfgimpl_get_toplevel()
|
||||
|
|
10
option.py
10
option.py
|
@ -34,14 +34,20 @@ group_types = ['default', 'family', 'group', 'master']
|
|||
class Option(HiddenBaseType, DisabledBaseType, ModeBaseType):
|
||||
#reminder: an Option object is **not** a container for the value
|
||||
_frozen = False
|
||||
def __init__(self, name, doc, default=None, requires=None,
|
||||
mandatory=False, multi=False, callback=None,
|
||||
def __init__(self, name, doc, default=None, default_multi=None,
|
||||
requires=None, mandatory=False, multi=False, callback=None,
|
||||
callback_params=None, mode='normal'):
|
||||
self._name = name
|
||||
self.doc = doc
|
||||
self._requires = requires
|
||||
self._mandatory = mandatory
|
||||
self.multi = multi
|
||||
if not self.multi and default_multi is not None:
|
||||
raise ConfigError("a default_multi is set whereas multi is False"
|
||||
" in option: {0}".format(name))
|
||||
self.default_multi = default_multi
|
||||
#if self.multi and default_multi is None:
|
||||
# _cfgimpl_warnings[name] = DefaultMultiWarning
|
||||
self.callback = callback
|
||||
if self.callback is None and callback_params is not None:
|
||||
raise ConfigError("params defined for a callback function but"
|
||||
|
|
Loading…
Reference in a new issue