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