multi types with None
This commit is contained in:
parent
2569cc5e59
commit
13c4819b14
27
autolib.py
27
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,9 +51,10 @@ 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:
|
||||||
|
if opt_value != None:
|
||||||
len_value = len(opt_value)
|
len_value = len(opt_value)
|
||||||
if len_multi != 0 and len_multi != len_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: '
|
'option values with multi types must have same length for: '
|
||||||
+ name)
|
+ name)
|
||||||
len_multi = len_value
|
len_multi = len_value
|
||||||
|
@ -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 New Issue