In Config, name and session_id was quite equal, remove name
session_id is now validate set_value return Configs with error add new_config to MetaConfig
This commit is contained in:
@ -317,11 +317,13 @@ class SubConfig(object):
|
||||
_commit=_commit)
|
||||
else:
|
||||
subpath = self._get_subpath(name)
|
||||
self.cfgimpl_get_values().setitem(child, value, subpath,
|
||||
force_permissive=force_permissive,
|
||||
not_raises=not_raises, index=index,
|
||||
_setting_properties=_setting_properties,
|
||||
_commit=_commit)
|
||||
ret = self.cfgimpl_get_values().setitem(child, value, subpath,
|
||||
force_permissive=force_permissive,
|
||||
not_raises=not_raises, index=index,
|
||||
_setting_properties=_setting_properties,
|
||||
_commit=_commit)
|
||||
if ret is not None:
|
||||
return ret
|
||||
|
||||
def __delattr__(self, name):
|
||||
context = self._cfgimpl_get_context()
|
||||
@ -781,8 +783,8 @@ class Config(_CommonConfig):
|
||||
__slots__ = ('__weakref__', '_impl_test', '_impl_name')
|
||||
|
||||
def __init__(self, descr, session_id=None, persistent=False,
|
||||
name=undefined, force_values=None, force_settings=None,
|
||||
_duplicate=False, mandatory_name=False, _force_store_values=True):
|
||||
force_values=None, force_settings=None,
|
||||
_duplicate=False, _force_store_values=True):
|
||||
""" Configuration option management master class
|
||||
|
||||
:param descr: describes the configuration schema
|
||||
@ -802,15 +804,9 @@ class Config(_CommonConfig):
|
||||
self._impl_settings = force_settings
|
||||
self._impl_values = Values(self, force_values)
|
||||
else:
|
||||
properties, permissives, values = get_storages(self, session_id, persistent)
|
||||
if name is undefined:
|
||||
name = 'config'
|
||||
if session_id is not None:
|
||||
name += session_id
|
||||
if mandatory_name and name is None:
|
||||
raise ValueError(_("name is mandatory for the config").format(name))
|
||||
if name is not None and not valid_name(name): # pragma: optional cover
|
||||
raise ValueError(_("invalid name: {0} for config").format(name))
|
||||
properties, permissives, values, session_id = get_storages(self, session_id, persistent)
|
||||
if not valid_name(session_id): # pragma: optional cover
|
||||
raise ValueError(_("invalid session ID: {0} for config").format(session_id))
|
||||
self._impl_settings = Settings(self, properties, permissives)
|
||||
self._impl_values = Values(self, values)
|
||||
super(Config, self).__init__(descr, weakref.ref(self))
|
||||
@ -819,7 +815,7 @@ class Config(_CommonConfig):
|
||||
self._impl_test = False
|
||||
if _duplicate is False and (force_settings is None or force_values is None):
|
||||
self._impl_build_all_caches(_force_store_values)
|
||||
self._impl_name = name
|
||||
self._impl_name = session_id
|
||||
|
||||
def impl_getname(self):
|
||||
return self._impl_name
|
||||
@ -832,7 +828,7 @@ class GroupConfig(_CommonConfig):
|
||||
__slots__ = ('__weakref__', '_impl_children', '_impl_name')
|
||||
|
||||
def __init__(self, children, session_id=None, persistent=False,
|
||||
_descr=None, name=undefined):
|
||||
_descr=None):
|
||||
if not isinstance(children, list):
|
||||
raise ValueError(_("groupconfig's children must be a list"))
|
||||
names = []
|
||||
@ -850,16 +846,14 @@ class GroupConfig(_CommonConfig):
|
||||
raise ConflictError(_('config name must be uniq in '
|
||||
'groupconfig for {0}').format(name))
|
||||
self._impl_children = children
|
||||
properties, permissives, values = get_storages(self, session_id, persistent)
|
||||
properties, permissives, values, session_id = get_storages(self, session_id, persistent)
|
||||
self._impl_settings = Settings(self, properties, permissives)
|
||||
self._impl_values = Values(self, values)
|
||||
super(GroupConfig, self).__init__(_descr, weakref.ref(self))
|
||||
self._impl_meta = None
|
||||
#undocumented option used only in test script
|
||||
self._impl_test = False
|
||||
if name is undefined:
|
||||
name = session_id
|
||||
self._impl_name = name
|
||||
self._impl_name = session_id
|
||||
|
||||
def cfgimpl_get_children(self):
|
||||
return self._impl_children
|
||||
@ -877,15 +871,19 @@ class GroupConfig(_CommonConfig):
|
||||
def set_value(self, path, value, _commit=True):
|
||||
"""Setattr not in current GroupConfig, but in each children
|
||||
"""
|
||||
ret = []
|
||||
for child in self._impl_children:
|
||||
if isinstance(child, MetaConfig):
|
||||
child.set_value(path, value, only_config=True, _commit=False)
|
||||
ret.extend(child.set_value(path, value, only_config=True, _commit=False))
|
||||
elif isinstance(child, GroupConfig):
|
||||
child.set_value(path, value, _commit=False)
|
||||
ret.extend(child.set_value(path, value, _commit=False))
|
||||
else:
|
||||
child.setattr(path, value, not_raises=True, _commit=False)
|
||||
childret = child.setattr(path, value, not_raises=True, _commit=False)
|
||||
if childret is not None:
|
||||
ret.append(childret)
|
||||
if _commit:
|
||||
self.cfgimpl_get_values()._p_.commit()
|
||||
return ret
|
||||
|
||||
|
||||
def find_firsts(self, byname=None, bypath=undefined, byoption=undefined,
|
||||
@ -953,7 +951,7 @@ class MetaConfig(GroupConfig):
|
||||
__slots__ = tuple()
|
||||
|
||||
def __init__(self, children, session_id=None, persistent=False,
|
||||
name=undefined, optiondescription=None):
|
||||
optiondescription=None):
|
||||
descr = None
|
||||
if optiondescription is not None:
|
||||
new_children = []
|
||||
@ -977,7 +975,7 @@ class MetaConfig(GroupConfig):
|
||||
child._impl_meta = weakref.ref(self)
|
||||
|
||||
super(MetaConfig, self).__init__(children, session_id, persistent,
|
||||
descr, name)
|
||||
descr)
|
||||
|
||||
def set_value(self, path, value, force_default=False,
|
||||
force_dont_change_value=False, force_default_if_same=False,
|
||||
@ -991,6 +989,7 @@ class MetaConfig(GroupConfig):
|
||||
'force_dont_change_value cannot be set with'
|
||||
' only_config'))
|
||||
return super(MetaConfig, self).set_value(path, value, _commit=_commit)
|
||||
ret = []
|
||||
if force_default or force_default_if_same or force_dont_change_value:
|
||||
if force_default and force_dont_change_value:
|
||||
raise ValueError(_('force_default and force_dont_change_value'
|
||||
@ -1005,18 +1004,40 @@ class MetaConfig(GroupConfig):
|
||||
else:
|
||||
child_value = child.getattr(path)
|
||||
if force_default or value == child_value:
|
||||
child.cfgimpl_get_values().reset(opt, path=path,
|
||||
validate=False,
|
||||
_setting_properties=setting_properties,
|
||||
_commit=False)
|
||||
childret = child.cfgimpl_get_values().reset(opt, path=path,
|
||||
validate=False,
|
||||
_setting_properties=setting_properties,
|
||||
_commit=False)
|
||||
if childret is not None:
|
||||
ret.append(childret)
|
||||
continue
|
||||
if force_dont_change_value:
|
||||
child_value = child.getattr(path, _setting_properties=setting_properties)
|
||||
if value != child_value:
|
||||
child.setattr(path, child_value, _commit=False)
|
||||
child_value = child.getattr(path, _setting_properties=setting_properties,
|
||||
returns_raise=True)
|
||||
if isinstance(child_value, Exception):
|
||||
ret.append(child_value)
|
||||
elif value != child_value:
|
||||
childret = child.setattr(path, child_value, _commit=False, not_raises=True)
|
||||
if childret is not None:
|
||||
ret.append(childret)
|
||||
|
||||
self.setattr(path, value, _commit=_commit)
|
||||
setret = self.setattr(path, value, _commit=_commit, not_raises=True)
|
||||
if setret is not None:
|
||||
ret.append(setret)
|
||||
return ret
|
||||
|
||||
def new_config(self, session_id=None, persistent=False, name=undefined):
|
||||
return Config(self._impl_descr, _duplicate=True, session_id=session_id, name=name,
|
||||
persistent=persistent, mandatory_name=True)
|
||||
def reset(self, path):
|
||||
opt = self.cfgimpl_get_description().impl_get_opt_by_path(path)
|
||||
setting_properties = self.cfgimpl_get_settings()._getproperties(read_write=False)
|
||||
for child in self._impl_children:
|
||||
child.cfgimpl_get_values().reset(opt, path=path,
|
||||
validate=False,
|
||||
_setting_properties=setting_properties,
|
||||
_commit=False)
|
||||
self.cfgimpl_get_values().reset(opt, path=path,
|
||||
validate=False,
|
||||
_setting_properties=setting_properties)
|
||||
|
||||
def new_config(self, session_id=None, persistent=False):
|
||||
return Config(self._impl_descr, session_id=session_id,
|
||||
persistent=persistent)
|
||||
|
@ -34,6 +34,8 @@ def display_list(lst, separator='and'):
|
||||
ret = str(ret)
|
||||
return ret
|
||||
else:
|
||||
if isinstance(lst, tuple):
|
||||
lst = list(lst)
|
||||
lst.sort()
|
||||
lst_ = []
|
||||
for l in lst[:-1]:
|
||||
|
@ -42,7 +42,7 @@ if sys.version_info[0] >= 3: # pragma: no cover
|
||||
|
||||
StorageBase = get_storages_option('base')
|
||||
submulti = 2
|
||||
name_regexp = re.compile(r'^[a-z][a-zA-Z\d\-_]*$')
|
||||
name_regexp = re.compile(r'^[a-z][a-zA-Z\d_]*$')
|
||||
forbidden_names = frozenset(['iter_all', 'iter_group', 'find', 'find_first',
|
||||
'make_dict', 'unwrap_from_path', 'read_only',
|
||||
'read_write', 'getowner', 'set_contexts'])
|
||||
|
@ -127,7 +127,7 @@ def get_storage(type_, session_id, persistent, test): # pragma: optional cover
|
||||
|
||||
def get_storages(context, session_id, persistent):
|
||||
def gen_id(config):
|
||||
return str(id(config)) + str(time()) + str(randint(0, 500))
|
||||
return 'c' + str(id(config)) + str(int(time())) + str(randint(0, 500))
|
||||
|
||||
if session_id is None:
|
||||
session_id = gen_id(context)
|
||||
@ -136,7 +136,7 @@ def get_storages(context, session_id, persistent):
|
||||
properties = imp.Properties(storage)
|
||||
permissives = imp.Permissives(storage)
|
||||
values = imp.Values(storage)
|
||||
return properties, permissives, values
|
||||
return properties, permissives, values, session_id
|
||||
|
||||
|
||||
def get_storages_option(type_):
|
||||
|
@ -93,7 +93,6 @@ class Storage(object):
|
||||
self.execute(permissives_table)
|
||||
|
||||
def commit(self):
|
||||
#print('ca commit')
|
||||
self._conn.commit()
|
||||
|
||||
def execute(self, sql, params=None, commit=True):
|
||||
|
@ -429,10 +429,12 @@ class Values(object):
|
||||
session=session, not_raises=not_raises,
|
||||
index=index)
|
||||
if props and not_raises:
|
||||
return
|
||||
return props
|
||||
err = opt.impl_validate(value, fake_context, display_warnings=False, force_index=index,
|
||||
setting_properties=_setting_properties)
|
||||
if err:
|
||||
if not_raises:
|
||||
return err
|
||||
raise err
|
||||
opt.impl_validate(value, fake_context, display_error=False,
|
||||
setting_properties=_setting_properties)
|
||||
|
Reference in New Issue
Block a user