eosfunc and autolib
This commit is contained in:
parent
934d011847
commit
b533bd996b
|
@ -14,21 +14,22 @@
|
|||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
# The original `Config` design model is unproudly borrowed from
|
||||
# The original `Config` design model is unproudly borrowed from
|
||||
# the rough gus of pypy: pypy: http://codespeak.net/svn/pypy/dist/pypy/config/
|
||||
# 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 PropertiesOptionError, ConflictConfigError
|
||||
from tiramisu.error import PropertiesOptionError, ConflictConfigError,
|
||||
NoValueReturned
|
||||
# ____________________________________________________________
|
||||
# automatic Option object
|
||||
#def special_owner_factory(name, owner, value,
|
||||
#def special_owner_factory(name, owner, value,
|
||||
# callback, callback_params=None, config=None):
|
||||
# # in case of an 'auto' and a 'fill' without a value,
|
||||
# # in case of an 'auto' and a 'fill' without a value,
|
||||
# # we have to carry out a calculation
|
||||
# return calc_factory(name, callback, callback_params, config)
|
||||
def carry_out_calculation(name, callback, callback_params, config):
|
||||
# FIXME we have to know the exact status of the config
|
||||
# FIXME we have to know the exact status of the config
|
||||
# not to disrupt it
|
||||
# config.freeze()
|
||||
if callback_params is None:
|
||||
|
@ -67,22 +68,34 @@ def carry_out_calculation(name, callback, callback_params, config):
|
|||
for key, couple in tcparams.items():
|
||||
value, ismulti = couple
|
||||
if ismulti and value != None:
|
||||
tcp[key] = value[incr]
|
||||
if key == '':
|
||||
params.append(value[incr])
|
||||
else:
|
||||
tcp[key] = value[incr]
|
||||
else:
|
||||
tcp[key] = value
|
||||
if key == '':
|
||||
params.append(value)
|
||||
else:
|
||||
tcp[key] = value
|
||||
ret.append(calculate(name, callback, tcp))
|
||||
return ret
|
||||
else:
|
||||
tcp = {}
|
||||
params = []
|
||||
for key, couple in tcparams.items():
|
||||
tcp[key] = couple[0]
|
||||
return calculate(name, callback, tcp)
|
||||
|
||||
def calculate(name, callback, tcparams):
|
||||
if key == '':
|
||||
params.append(couple[0])
|
||||
else:
|
||||
tcp[key] = couple[0]
|
||||
return calculate(name, callback, params, tcp)
|
||||
|
||||
def calculate(name, callback, params, tcparams):
|
||||
try:
|
||||
# XXX not only creole...
|
||||
from creole import eosfunc
|
||||
return getattr(eosfunc, callback)(**tcparams)
|
||||
return getattr(eosfunc, callback)(*params, **tcparams)
|
||||
except NoValueReturned, err:
|
||||
return ""
|
||||
except AttributeError, err:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
|
|
@ -231,9 +231,6 @@ class Config(object):
|
|||
(self.__class__, name))
|
||||
if not isinstance(opt_or_descr, OptionDescription):
|
||||
# options with callbacks (fill or auto)
|
||||
if name == 'interface_gw':
|
||||
print "pouet"
|
||||
print opt_or_descr.has_callback()
|
||||
if opt_or_descr.has_callback():
|
||||
value = self._cfgimpl_values[name]
|
||||
if (not opt_or_descr.is_frozen() or \
|
||||
|
|
|
@ -14,11 +14,12 @@ class PropertiesOptionError(AttributeError):
|
|||
class NotFoundError(Exception):
|
||||
pass
|
||||
class MethodCallError(Exception):
|
||||
pass
|
||||
pass
|
||||
class RequiresError(Exception):
|
||||
pass
|
||||
pass
|
||||
class RequirementRecursionError(RequiresError):
|
||||
pass
|
||||
class MandatoryError(Exception):
|
||||
pass
|
||||
|
||||
pass
|
||||
class NoValueReturned(Exception):
|
||||
pass
|
||||
|
|
|
@ -23,9 +23,10 @@
|
|||
from tiramisu.basetype import HiddenBaseType, DisabledBaseType
|
||||
from tiramisu.error import (ConfigError, ConflictConfigError, NotFoundError,
|
||||
RequiresError, RequirementRecursionError, MandatoryError)
|
||||
available_actions = ['hide', 'show', 'enable', 'disable']
|
||||
available_actions = ['hide', 'show', 'enable', 'disable', 'freeze', 'unfreeze']
|
||||
reverse_actions = {'hide': 'show', 'show': 'hide',
|
||||
'disable':'enable', 'enable': 'disable'}
|
||||
'disable': 'enable', 'enable': 'disable',
|
||||
'freeze': 'unfreeze', 'unfreeze': 'freeze'}
|
||||
# ____________________________________________________________
|
||||
# OptionDescription authorized group_type values
|
||||
group_types = ['default', 'family', 'group', 'master']
|
||||
|
@ -101,7 +102,7 @@ class Option(HiddenBaseType, DisabledBaseType):
|
|||
#if self.multi and default_multi is None:
|
||||
# _cfgimpl_warnings[name] = DefaultMultiWarning
|
||||
if callback is not None and (default is not None or default_multi is not None):
|
||||
raise ConfigError("defaut values not allowed if option: {0}"
|
||||
raise ConfigError("defaut values not allowed if option: {0} "
|
||||
"is calculated".format(name))
|
||||
self.callback = callback
|
||||
if self.callback is None and callback_params is not None:
|
||||
|
|
Loading…
Reference in New Issue