sqlalchemy

This commit is contained in:
Emmanuel Garette 2014-01-30 22:55:15 +01:00
parent 2eb63c917b
commit 02a987b39d
8 changed files with 77 additions and 75 deletions

View File

@ -85,7 +85,7 @@ def test_base_config_and_groups():
assert nm.impl_getname() == 'name' assert nm.impl_getname() == 'name'
gc = config.unwrap_from_path('gc') gc = config.unwrap_from_path('gc')
assert gc.impl_getname() == 'gc' assert gc.impl_getname() == 'gc'
#nm = config.unwrap_fromimpl_getname()('name') #nm = config.unwrap_from_name('name')
#assert nm.impl_getname() == 'name' #assert nm.impl_getname() == 'name'

View File

@ -146,10 +146,10 @@ def test_force_store_value():
assert conf.getowner(conf.unwrap_from_path('wantref')) == 'user' assert conf.getowner(conf.unwrap_from_path('wantref')) == 'user'
#def test_force_store_value_ro(): def test_force_store_value_ro():
# descr = make_description_freeze() descr = make_description_freeze()
# conf = Config(descr) conf = Config(descr)
# conf.read_only() conf.read_only()
# assert conf.getowner(conf.unwrap_from_path('wantref')) == 'default' assert conf.getowner(conf.unwrap_from_path('wantref')) == 'default'
# conf.wantref conf.wantref
# assert conf.getowner(conf.unwrap_from_path('wantref')) == 'user' assert conf.getowner(conf.unwrap_from_path('wantref')) == 'user'

View File

@ -102,8 +102,7 @@ def test_consistency_after_config():
od2 = OptionDescription('od2', '', [b]) od2 = OptionDescription('od2', '', [b])
od = OptionDescription('root', '', [od1, od2]) od = OptionDescription('root', '', [od1, od2])
Config(od) Config(od)
#FIXME a cause du read_only raises(AttributeError, "a.impl_add_consistency('not_equal', b)")
#raises(AttributeError, "a.impl_add_consistency('not_equal', b)")
def test_consistency_not_equal_symlink(): def test_consistency_not_equal_symlink():

View File

@ -503,19 +503,19 @@ def test_requires_multi_disabled_inverse_2():
assert props == ['disabled'] assert props == ['disabled']
#def test_requires_requirement_append(): def test_requires_requirement_append():
# a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
# b = IPOption('ip_address_service', '', b = IPOption('ip_address_service', '',
# requires=[{'option': a, 'expected': False, 'action': 'disabled'}]) requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
# od = OptionDescription('service', '', [a, b]) od = OptionDescription('service', '', [a, b])
# c = Config(od) c = Config(od)
# c.read_write() c.read_write()
# str(c.cfgimpl_get_settings()) str(c.cfgimpl_get_settings())
# str(c.cfgimpl_get_settings()[b]) str(c.cfgimpl_get_settings()[b])
# raises(ValueError, 'c.cfgimpl_get_settings()[b].append("disabled")') raises(ValueError, 'c.cfgimpl_get_settings()[b].append("disabled")')
# c.activate_service = False c.activate_service = False
# # disabled is now set, test to remove disabled before store in storage # disabled is now set, test to remove disabled before store in storage
# c.cfgimpl_get_settings()[b].append("test") c.cfgimpl_get_settings()[b].append("test")
def test_requires_different_inverse(): def test_requires_different_inverse():

View File

@ -29,8 +29,7 @@ def carry_out_calculation(option, config, callback, callback_params,
index=None, max_len=None): index=None, max_len=None):
"""a function that carries out a calculation for an option's value """a function that carries out a calculation for an option's value
:param name: the option name (`opt.impl_getname()`) :param option: the option
:param name: the option
:param config: the context config in order to have :param config: the context config in order to have
the whole options available the whole options available
:param callback: the name of the callback function :param callback: the name of the callback function

View File

@ -22,11 +22,10 @@
# ____________________________________________________________ # ____________________________________________________________
import re import re
import sys import sys
from copy import copy # , deepcopy from copy import copy
from types import FunctionType from types import FunctionType
from IPy import IP from IPy import IP
import warnings import warnings
#from pickle import loads, dumps
from tiramisu.error import ConfigError, ConflictError, ValueWarning from tiramisu.error import ConfigError, ConflictError, ValueWarning
from tiramisu.setting import groups, multitypes from tiramisu.setting import groups, multitypes
@ -335,43 +334,45 @@ class Option(BaseOption):
warnings_only, choice_values, warnings_only, choice_values,
choice_open_values) choice_open_values)
#def __setattr__(self, name, value): def impl_is_readonly(self):
# """set once and only once some attributes in the option, try:
# like `_name`. `_name` cannot be changed one the option and if self._readonly is True:
# pushed in the :class:`tiramisu.option.OptionDescription`. return True
except AttributeError:
pass
return False
# if the attribute `_readonly` is set to `True`, the option is def __setattr__(self, name, value):
# "frozen" (which has noting to do with the high level "freeze" """set once and only once some attributes in the option,
# propertie or "read_only" property) like `_name`. `_name` cannot be changed one the option and
# """ pushed in the :class:`tiramisu.option.OptionDescription`.
# #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_getproperties(self): if the attribute `_readonly` is set to `True`, the option is
# for prop in self._properties: "frozen" (which has noting to do with the high level "freeze"
# yield(prop.name) 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): def impl_getrequires(self):
return self._requires return self._requires
@ -443,8 +444,6 @@ class Option(BaseOption):
if self._validator is not None: if self._validator is not None:
if self._validator_params is not None: if self._validator_params is not None:
validator_params = {} validator_params = {}
#FIXME toujours utile ce deepcopy ?
#validator_params = deepcopy(self._validator_params)
for val_param, values in self._validator_params.items(): for val_param, values in self._validator_params.items():
validator_params[val_param] = values validator_params[val_param] = values
#FIXME ... ca sert à quoi ... #FIXME ... ca sert à quoi ...
@ -550,6 +549,11 @@ class Option(BaseOption):
:param other_opts: options used to validate value :param other_opts: options used to validate value
:type other_opts: `list` of `tiramisu.option.Option` :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: for opt in other_opts:
if not isinstance(opt, Option): if not isinstance(opt, Option):
raise ConfigError(_('consistency should be set with an option')) raise ConfigError(_('consistency should be set with an option'))
@ -1010,7 +1014,7 @@ class DomainnameOption(Option):
domainname: domainname:
fqdn: with tld, not supported yet 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, def __init__(self, name, doc, default=None, default_multi=None,
requires=None, multi=False, callback=None, requires=None, multi=False, callback=None,
@ -1167,7 +1171,7 @@ class OptionDescription(BaseOption, StorageOptionDescription):
self._cache_paths = None self._cache_paths = None
self._cache_consistencies = None self._cache_consistencies = None
# the group_type is useful for filtering OptionDescriptions in a config # 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): #def impl_getproperties(self):
# #FIXME # #FIXME
@ -1317,12 +1321,12 @@ class OptionDescription(BaseOption, StorageOptionDescription):
:param group_type: an instance of `GroupType` or `MasterGroupType` :param group_type: an instance of `GroupType` or `MasterGroupType`
that lives in `setting.groups` 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 ' 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)) group_type))
if isinstance(group_type, groups.GroupType): if isinstance(group_type, groups.GroupType):
self._optiondescription_group_type = group_type self._group_type = group_type
if isinstance(group_type, groups.MasterGroupType): if isinstance(group_type, groups.MasterGroupType):
#if master (same name has group) is set #if master (same name has group) is set
#for collect all slaves #for collect all slaves
@ -1367,7 +1371,7 @@ class OptionDescription(BaseOption, StorageOptionDescription):
' not allowed').format(group_type)) ' not allowed').format(group_type))
def impl_get_group_type(self): 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): def _valid_consistency(self, option, value, context, index):
if self._cache_consistencies is None: if self._cache_consistencies is None:
@ -1396,7 +1400,7 @@ class OptionDescription(BaseOption, StorageOptionDescription):
self.impl_build_cache() self.impl_build_cache()
descr = self descr = self
super(OptionDescription, self)._impl_getstate(descr) 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(): for option in self.impl_getchildren():
option._impl_getstate(descr) option._impl_getstate(descr)
@ -1426,7 +1430,7 @@ class OptionDescription(BaseOption, StorageOptionDescription):
self._cache_consistencies = None self._cache_consistencies = None
self.impl_build_cache(force_no_consistencies=True) self.impl_build_cache(force_no_consistencies=True)
descr = self 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) del(self._state_group_type)
super(OptionDescription, self)._impl_setstate(descr) super(OptionDescription, self)._impl_setstate(descr)
for option in self.impl_getchildren(): for option in self.impl_getchildren():
@ -1450,7 +1454,7 @@ def validate_requires_arg(requires, name):
the description of the requires dictionary the description of the requires dictionary
""" """
if requires is None: if requires is None:
return None return None, None
ret_requires = {} ret_requires = {}
config_action = {} config_action = {}

View File

@ -268,7 +268,7 @@ class Property(object):
:type propname: string :type propname: string
""" """
if self._opt is not None and self._opt.impl_getrequires() is not None \ if self._opt is not None and self._opt.impl_getrequires() is not None \
and propname in self._opt.impl_getrequires(): and propname in self._opt._calc_properties:
raise ValueError(_('cannot append {0} property for option {1}: ' raise ValueError(_('cannot append {0} property for option {1}: '
'this property is calculated').format( 'this property is calculated').format(
propname, self._opt.impl_getname())) propname, self._opt.impl_getname()))

View File

@ -275,7 +275,7 @@ class _Base(SqlAlchemyBase):
'polymorphic_on': _type 'polymorphic_on': _type
} }
#FIXME devrait etre une table #FIXME devrait etre une table
_optiondescription_group_type = Column(String) _group_type = Column(String)
def __init__(self): def __init__(self):
self.commit() self.commit()