# ____________________________________________________________
import re
import sys
-from copy import copy # , deepcopy
+from copy import copy
from types import FunctionType
from IPy import IP
import warnings
-#from pickle import loads, dumps
from tiramisu.error import ConfigError, ConflictError, ValueWarning
from tiramisu.setting import groups, multitypes
warnings_only, choice_values,
choice_open_values)
- #def __setattr__(self, name, value):
- # """set once and only once some attributes in the option,
- # like `_name`. `_name` cannot be changed one the option and
- # pushed in the :class:`tiramisu.option.OptionDescription`.
-
- # if the attribute `_readonly` is set to `True`, the option is
- # "frozen" (which has noting to do with the high level "freeze"
- # propertie or "read_only" property)
- # """
- # #FIXME ne devrait pas pouvoir redefinir _option
- # if not name == '_option':
- # is_readonly = False
- # # never change _name
- # if name == '_name':
- # try:
- # self._name
- # #so _name is already set
- # is_readonly = True
- # except:
- # pass
- # elif name != '_readonly':
- # try:
- # if self._readonly is True:
- # is_readonly = True
- # except AttributeError:
- # self._readonly = False
- # if is_readonly:
- # raise AttributeError(_("'{0}' ({1}) object attribute '{2}' is"
- # " read-only").format(
- # self.__class__.__name__,
- # self._name,
- # name))
- # object.__setattr__(self, name, value)
+ def impl_is_readonly(self):
+ try:
+ if self._readonly is True:
+ return True
+ except AttributeError:
+ pass
+ return False
- #def impl_getproperties(self):
- # for prop in self._properties:
- # yield(prop.name)
+ def __setattr__(self, name, value):
+ """set once and only once some attributes in the option,
+ like `_name`. `_name` cannot be changed one the option and
+ pushed in the :class:`tiramisu.option.OptionDescription`.
+
+ if the attribute `_readonly` is set to `True`, the option is
+ "frozen" (which has noting to do with the high level "freeze"
+ propertie or "read_only" property)
+ """
+ #FIXME ne devrait pas pouvoir redefinir _option
+ #FIXME c'est une merde pour sqlachemy surement un cache ...
+ if not name == '_option' and not isinstance(value, tuple):
+ is_readonly = False
+ # never change _name
+ if name == '_name':
+ try:
+ if self._name is not None:
+ #so _name is already set
+ is_readonly = True
+ #FIXME je n'aime pas ce except ...
+ except:
+ pass
+ elif name != '_readonly':
+ is_readonly = self.impl_is_readonly()
+ if is_readonly:
+ raise AttributeError(_("'{0}' ({1}) object attribute '{2}' is"
+ " read-only").format(
+ self.__class__.__name__,
+ self._name,
+ name))
+ super(Option, self).__setattr__(name, value)
def impl_getrequires(self):
return self._requires
if self._validator is not None:
if self._validator_params is not None:
validator_params = {}
- #FIXME toujours utile ce deepcopy ?
- #validator_params = deepcopy(self._validator_params)
for val_param, values in self._validator_params.items():
validator_params[val_param] = values
#FIXME ... ca sert à quoi ...
:param other_opts: options used to validate value
:type other_opts: `list` of `tiramisu.option.Option`
"""
+ if self.impl_is_readonly():
+ raise AttributeError(_("'{0}' ({1}) cannont add consistency, option is"
+ " read-only").format(
+ self.__class__.__name__,
+ self._name))
for opt in other_opts:
if not isinstance(opt, Option):
raise ConfigError(_('consistency should be set with an option'))
domainname:
fqdn: with tld, not supported yet
"""
- #__slots__ = ('_dom_type', '_allow_ip', '_allow_without_dot', '_domain_re')
+ #__slots__ = ('_type', '_allow_ip', '_allow_without_dot', '_domain_re')
def __init__(self, name, doc, default=None, default_multi=None,
requires=None, multi=False, callback=None,
self._cache_paths = None
self._cache_consistencies = None
# the group_type is useful for filtering OptionDescriptions in a config
- self._optiondescription_group_type = groups.default
+ self._group_type = groups.default
#def impl_getproperties(self):
# #FIXME
:param group_type: an instance of `GroupType` or `MasterGroupType`
that lives in `setting.groups`
"""
- if self._optiondescription_group_type != groups.default:
+ if self._group_type != groups.default:
raise TypeError(_('cannot change group_type if already set '
- '(old {0}, new {1})').format(self._optiondescription_group_type,
+ '(old {0}, new {1})').format(self._group_type,
group_type))
if isinstance(group_type, groups.GroupType):
- self._optiondescription_group_type = group_type
+ self._group_type = group_type
if isinstance(group_type, groups.MasterGroupType):
#if master (same name has group) is set
#for collect all slaves
' not allowed').format(group_type))
def impl_get_group_type(self):
- return getattr(groups, self._optiondescription_group_type)
+ return getattr(groups, self._group_type)
def _valid_consistency(self, option, value, context, index):
if self._cache_consistencies is None:
self.impl_build_cache()
descr = self
super(OptionDescription, self)._impl_getstate(descr)
- self._state_group_type = str(self._optiondescription_group_type)
+ self._state_group_type = str(self._group_type)
for option in self.impl_getchildren():
option._impl_getstate(descr)
self._cache_consistencies = None
self.impl_build_cache(force_no_consistencies=True)
descr = self
- self._optiondescription_group_type = getattr(groups, self._state_group_type)
+ self._group_type = getattr(groups, self._state_group_type)
del(self._state_group_type)
super(OptionDescription, self)._impl_setstate(descr)
for option in self.impl_getchildren():
the description of the requires dictionary
"""
if requires is None:
- return None
+ return None, None
ret_requires = {}
config_action = {}