tiramisu/tiramisu/config.py

1191 lines
51 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2018-01-26 07:33:47 +01:00
# Copyright (C) 2012-2018 Team tiramisu (see AUTHORS for all contributors)
#
2013-09-22 22:33:09 +02:00
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
2013-09-22 22:33:09 +02:00
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
2013-09-22 22:33:09 +02:00
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
2012-10-05 16:00:07 +02:00
# The original `Config` design model is unproudly borrowed from
# the rough pypy's guys: http://codespeak.net/svn/pypy/dist/pypy/config/
# the whole pypy projet is under MIT licence
# ____________________________________________________________
2013-09-23 22:55:54 +02:00
"options handler global entry point"
import weakref
2017-07-08 15:59:56 +02:00
from time import time
from copy import copy
2015-04-18 22:53:45 +02:00
2017-12-19 23:11:45 +01:00
from .error import PropertiesOptionError, ConfigError, ConflictError, SlaveError
from .option.syndynoptiondescription import SynDynOptionDescription
2018-01-01 21:32:39 +01:00
from .option.masterslave import MasterSlaves
2017-12-19 23:11:45 +01:00
from .option.baseoption import BaseOption, valid_name
from .setting import ConfigBag, groups, Settings, undefined
from .storage import get_storages, get_default_values_storages
2017-11-12 14:33:05 +01:00
from .value import Values # , Multi
from .i18n import _
2013-02-22 11:09:17 +01:00
class SubConfig(object):
2013-09-23 22:55:54 +02:00
"""Sub configuration management entry.
Tree if OptionDescription's responsability. SubConfig are generated
on-demand. A Config is also a SubConfig.
Root Config is call context below
"""
2017-11-12 14:33:05 +01:00
__slots__ = ('_impl_context',
'_impl_descr',
'_impl_path',
'_impl_length')
def __init__(self,
descr,
context,
2017-12-19 23:11:45 +01:00
config_bag,
2017-11-12 14:33:05 +01:00
subpath=None):
2012-10-05 16:00:07 +02:00
""" Configuration option management master class
2013-02-19 11:24:17 +01:00
2012-10-05 16:00:07 +02:00
:param descr: describes the configuration schema
:type descr: an instance of ``option.OptionDescription``
2013-02-07 16:20:21 +01:00
:param context: the current root config
:type context: `Config`
:type subpath: `str` with the path name
2012-10-05 16:00:07 +02:00
"""
# main option description
2014-06-19 23:22:39 +02:00
error = False
2017-12-19 23:11:45 +01:00
if descr is not None and (not isinstance(descr, (BaseOption, SynDynOptionDescription)) or not descr.impl_is_optiondescription()):
2014-06-19 23:22:39 +02:00
error = True
if error:
raise TypeError(_('descr must be an optiondescription, not {0}'
2017-11-12 14:33:05 +01:00
).format(type(descr)))
self._impl_descr = descr
# sub option descriptions
2014-06-19 23:22:39 +02:00
if not isinstance(context, weakref.ReferenceType): # pragma: optional cover
raise ValueError('context must be a Weakref')
self._impl_context = context
self._impl_path = subpath
2018-01-03 21:07:51 +01:00
if descr is not None and \
2017-12-19 23:11:45 +01:00
descr.impl_get_group_type() == groups.master:
2017-12-02 22:53:57 +01:00
master = descr.getmaster()
2017-12-19 23:11:45 +01:00
masterpath = master.impl_getname()
mconfig_bag = config_bag.copy('nooption')
mconfig_bag.option = master
value = self.getattr(masterpath,
None,
mconfig_bag)
2017-12-02 22:53:57 +01:00
self._impl_length = len(value)
def cfgimpl_get_length(self):
2018-03-24 22:37:48 +01:00
return self._impl_length
2017-11-20 17:01:36 +01:00
def reset_one_option_cache(self,
values,
settings,
resetted_opts,
opt,
path):
2017-12-13 22:15:34 +01:00
2017-11-20 17:01:36 +01:00
opt.reset_cache(opt,
path,
values,
settings,
2018-04-03 21:15:58 +02:00
resetted_opts)
2017-11-20 17:01:36 +01:00
for woption in opt._get_dependencies(self):
option = woption()
2017-12-13 22:15:34 +01:00
option_path = option.impl_getpath(self)
2018-04-03 21:15:58 +02:00
if option_path in resetted_opts:
continue
2017-11-20 17:01:36 +01:00
self.reset_one_option_cache(values,
settings,
resetted_opts,
option,
option_path)
del option
2017-11-13 22:45:53 +01:00
2017-07-08 15:59:56 +02:00
def cfgimpl_reset_cache(self,
only_expired=False,
opt=None,
2017-09-17 15:55:32 +02:00
path=None,
resetted_opts=None):
2017-07-08 15:59:56 +02:00
"""reset all settings in cache
:param only_expired: if True reset only expired cached values
:type only_expired: boolean
"""
if resetted_opts is None:
2017-12-19 23:11:45 +01:00
resetted_opts = []
context = self._cfgimpl_get_context()
2017-11-20 17:01:36 +01:00
values = context.cfgimpl_get_values()
settings = context.cfgimpl_get_settings()
if not None in (opt, path):
2018-04-03 21:15:58 +02:00
if path not in resetted_opts:
2017-11-13 22:45:53 +01:00
self.reset_one_option_cache(values,
settings,
resetted_opts,
opt,
2017-11-20 17:01:36 +01:00
path)
elif only_expired:
2017-12-13 22:15:34 +01:00
# reset cache for expired cache value ony
datetime = int(time())
values._p_.reset_expired_cache(datetime)
settings._p_.reset_expired_cache(datetime)
2017-07-08 15:59:56 +02:00
else:
2017-12-13 22:15:34 +01:00
values._p_.reset_all_cache()
settings._p_.reset_all_cache()
2013-02-07 16:20:21 +01:00
2017-11-12 14:33:05 +01:00
def cfgimpl_get_home_by_path(self,
path,
2017-12-19 23:11:45 +01:00
config_bag):
2012-10-05 16:00:07 +02:00
""":returns: tuple (config, name)"""
path = path.split('.')
for step in path[:-1]:
2017-12-19 23:11:45 +01:00
sconfig_bag = config_bag.copy('nooption')
self = self.getattr(step,
2017-12-19 23:11:45 +01:00
None,
sconfig_bag)
2018-01-03 21:07:51 +01:00
if not isinstance(self, SubConfig):
raise AttributeError(_('unknown option {}').format(path[-1]))
return self, path[-1]
2012-10-05 16:00:07 +02:00
# ______________________________________________________________________
2017-11-23 16:56:14 +01:00
def iter_groups(self,
2018-01-01 21:32:39 +01:00
config_bag,
group_type=None):
2012-11-20 17:14:58 +01:00
"""iteration on groups objects only.
All groups are returned if `group_type` is `None`, otherwise the groups
can be filtered by categories (families, or whatever).
2013-02-21 17:07:00 +01:00
2012-12-10 14:38:25 +01:00
:param group_type: if defined, is an instance of `groups.GroupType`
or `groups.MasterGroupType` that lives in
2013-02-07 16:20:21 +01:00
`setting.groups`
2012-11-20 17:14:58 +01:00
"""
if group_type is not None and not isinstance(group_type,
2014-06-19 23:22:39 +02:00
groups.GroupType): # pragma: optional cover
raise TypeError(_("unknown group_type: {0}").format(group_type))
2017-12-19 23:11:45 +01:00
for child in self.cfgimpl_get_description().impl_getchildren(config_bag):
2014-06-19 23:22:39 +02:00
if child.impl_is_optiondescription():
2018-01-01 21:32:39 +01:00
nconfig_bag = config_bag.copy('nooption')
nconfig_bag.option = child
2012-11-06 15:19:36 +01:00
try:
if group_type is None or (group_type is not None and
child.impl_get_group_type()
2013-05-02 11:34:57 +02:00
== group_type):
2014-06-19 23:22:39 +02:00
name = child.impl_getname()
2017-11-13 22:45:53 +01:00
yield name, self.getattr(name,
2018-01-01 21:32:39 +01:00
None,
nconfig_bag)
2014-06-19 23:22:39 +02:00
except PropertiesOptionError: # pragma: optional cover
2012-12-06 18:14:57 +01:00
pass
2018-01-01 21:32:39 +01:00
def cfgimpl_get_children(self,
config_bag):
2018-01-01 21:32:39 +01:00
context = self._cfgimpl_get_context()
for opt in self.cfgimpl_get_description().impl_getchildren(config_bag):
nconfig_bag = config_bag.copy('nooption')
nconfig_bag.option = opt
name = opt.impl_getname()
2018-01-05 23:32:00 +01:00
if nconfig_bag.setting_properties is not None:
2018-03-12 11:58:49 +01:00
subpath = self._get_subpath(name)
2018-01-05 23:32:00 +01:00
try:
context.cfgimpl_get_settings().validate_properties(subpath,
None,
nconfig_bag)
except PropertiesOptionError:
continue
yield name
2018-01-01 21:32:39 +01:00
2012-10-05 16:00:07 +02:00
# ______________________________________________________________________
2013-04-03 12:20:26 +02:00
2017-11-29 23:25:34 +01:00
# def __str__(self):
# "Config's string representation"
# lines = []
# for name, grp in self.iter_groups():
# lines.append("[{0}]".format(name))
# for name, value in self:
# try:
# lines.append("{0} = {1}".format(name, value))
# except UnicodeEncodeError: # pragma: optional cover
# lines.append("{0} = {1}".format(name,
# value.encode(default_encoding)))
# return '\n'.join(lines)
#
# __repr__ = __str__
2012-11-28 10:14:16 +01:00
def _cfgimpl_get_context(self):
"""context could be None, we need to test it
context is None only if all reference to `Config` object is deleted
(for example we delete a `Config` and we manipulate a reference to
old `SubConfig`, `Values`, `Multi` or `Settings`)
"""
context = self._impl_context()
2014-06-19 23:22:39 +02:00
if context is None: # pragma: optional cover
raise ConfigError(_('the context does not exist anymore'))
return context
2013-05-02 11:34:57 +02:00
2017-01-06 21:01:24 +01:00
def cfgimpl_get_context(self):
return self._cfgimpl_get_context()
2013-05-02 11:34:57 +02:00
def cfgimpl_get_description(self):
2014-06-19 23:22:39 +02:00
if self._impl_descr is None: # pragma: optional cover
2013-08-20 12:08:02 +02:00
raise ConfigError(_('no option description found for this config'
2013-09-30 16:22:08 +02:00
' (may be GroupConfig)'))
2013-05-02 11:34:57 +02:00
else:
return self._impl_descr
2013-05-02 11:34:57 +02:00
def cfgimpl_get_settings(self):
return self._cfgimpl_get_context()._impl_settings
2013-05-02 11:34:57 +02:00
def cfgimpl_get_values(self):
return self._cfgimpl_get_context()._impl_values
2013-05-02 11:34:57 +02:00
2017-11-12 14:33:05 +01:00
def setattr(self,
name,
2017-12-19 23:11:45 +01:00
index,
2017-11-12 14:33:05 +01:00
value,
2017-12-19 23:11:45 +01:00
config_bag,
2017-11-12 14:33:05 +01:00
_commit=True):
2016-01-25 15:57:34 +01:00
2014-06-19 23:22:39 +02:00
if name.startswith('_impl_'):
2017-11-12 14:33:05 +01:00
return object.__setattr__(self,
name,
value)
2017-07-11 22:31:58 +02:00
context = self._cfgimpl_get_context()
2014-06-19 23:22:39 +02:00
if '.' in name: # pragma: optional cover
2018-01-03 21:07:51 +01:00
# when set_value
self, name = self.cfgimpl_get_home_by_path(name,
config_bag)
2017-12-27 15:48:49 +01:00
if config_bag.option is None:
config_bag.option = self.cfgimpl_get_description().impl_getchild(name,
config_bag,
self)
if config_bag.option.impl_is_optiondescription() or \
isinstance(config_bag.option, SynDynOptionDescription):
2017-12-30 18:52:35 +01:00
raise ConfigError(_("can't assign to an OptionDescription")) # pragma: optional cover
2017-12-27 15:48:49 +01:00
elif config_bag.option.impl_is_symlinkoption():
2017-12-30 18:52:35 +01:00
raise ConfigError(_("can't assign to a SymLinkOption"))
2014-06-19 23:22:39 +02:00
else:
2017-12-27 15:48:49 +01:00
path = self._get_subpath(name)
2017-12-19 23:11:45 +01:00
if config_bag.setting_properties:
2017-12-27 15:48:49 +01:00
context.cfgimpl_get_settings().validate_properties(path,
index,
config_bag)
2018-01-01 21:32:39 +01:00
self.cfgimpl_get_description().impl_validate_value(config_bag.option,
value,
self)
2017-12-27 15:48:49 +01:00
return context.cfgimpl_get_values().setvalue(path,
index,
value,
config_bag,
_commit)
2013-05-02 11:34:57 +02:00
2017-11-12 14:33:05 +01:00
def delattr(self,
name,
2017-12-19 23:11:45 +01:00
index,
config_bag):
2017-11-12 14:33:05 +01:00
if '.' in name: # pragma: optional cover
self, name = self.cfgimpl_get_home_by_path(name,
2017-12-19 23:11:45 +01:00
config_bag)
if config_bag.option is None:
config_bag.option = self.cfgimpl_get_description().impl_getchild(name,
config_bag,
self)
option = config_bag.option
if option.impl_is_optiondescription() or isinstance(option, SynDynOptionDescription):
2017-11-12 14:33:05 +01:00
raise TypeError(_("can't delete an OptionDescription")) # pragma: optional cover
2017-12-19 23:11:45 +01:00
elif option.impl_is_symlinkoption():
2017-12-04 20:05:36 +01:00
raise TypeError(_("can't delete a SymLinkOption"))
2017-11-28 22:42:30 +01:00
subpath = self._get_subpath(name)
values = self.cfgimpl_get_values()
if index is not None:
2017-12-19 23:11:45 +01:00
if option.impl_is_master_slaves('master'):
2017-11-28 22:42:30 +01:00
values.reset_master(self,
subpath,
index,
2017-12-19 23:11:45 +01:00
config_bag)
elif option.impl_is_master_slaves('slave'):
2018-03-24 22:37:48 +01:00
length = self.cfgimpl_get_length()
if index >= length:
raise SlaveError(_('index "{}" is higher than the master length "{}" '
'for option "{}"').format(index,
length,
option.impl_get_display_name()))
2017-12-19 23:11:45 +01:00
values.reset_slave(subpath,
2017-11-28 22:42:30 +01:00
index,
2017-12-19 23:11:45 +01:00
config_bag)
2017-11-28 22:42:30 +01:00
else:
raise ValueError(_("can delete value with index only with a master or a slave"))
else:
2017-12-19 23:11:45 +01:00
values.reset(subpath,
config_bag)
2014-06-19 23:22:39 +02:00
def _get_subpath(self, name):
if self._impl_path is None:
subpath = name
else:
subpath = self._impl_path + '.' + name
return subpath
2017-11-12 14:33:05 +01:00
def getattr(self,
name,
2017-12-19 23:11:45 +01:00
index,
config_bag,
2017-12-23 10:40:41 +01:00
returns_option=False,
iter_slave=False):
2013-05-02 11:34:57 +02:00
"""
attribute notation mechanism for accessing the value of an option
:param name: attribute name
:return: option's value if name is an option name, OptionDescription
otherwise
"""
if '.' in name:
2017-11-28 22:42:30 +01:00
self, name = self.cfgimpl_get_home_by_path(name,
2017-12-19 23:11:45 +01:00
config_bag)
2017-11-28 22:42:30 +01:00
context = self._cfgimpl_get_context()
2017-12-19 23:11:45 +01:00
option = config_bag.option
if option is None:
option = self.cfgimpl_get_description().impl_getchild(name,
config_bag,
self)
config_bag.option = option
2017-12-04 20:05:36 +01:00
if option.impl_is_symlinkoption():
2017-11-28 22:42:30 +01:00
if returns_option is True:
return option
2017-12-19 23:11:45 +01:00
opt = option.impl_getopt()
path = context.cfgimpl_get_description().impl_get_path_by_opt(opt)
sconfig_bag = config_bag.copy('nooption')
sconfig_bag.ori_option = option
sconfig_bag.option = opt
2017-11-28 22:42:30 +01:00
return context.getattr(path,
2017-12-19 23:11:45 +01:00
index,
sconfig_bag)
2017-11-28 22:42:30 +01:00
subpath = self._get_subpath(name)
2017-12-19 23:11:45 +01:00
if config_bag.setting_properties:
self.cfgimpl_get_settings().validate_properties(subpath,
index,
config_bag)
2017-11-28 22:42:30 +01:00
if option.impl_is_optiondescription():
if returns_option is True:
return option
return SubConfig(option,
self._impl_context,
2017-12-19 23:11:45 +01:00
config_bag,
2017-11-28 22:42:30 +01:00
subpath)
if option.impl_is_master_slaves('slave'):
2017-12-23 10:40:41 +01:00
if index is None and not iter_slave:
2018-03-24 22:37:48 +01:00
raise SlaveError(_('index is mandatory for the slave "{}"'
2017-11-28 22:42:30 +01:00
'').format(subpath))
length = self.cfgimpl_get_length()
2017-12-23 10:40:41 +01:00
if index is not None and index >= length:
2018-01-01 21:32:39 +01:00
raise SlaveError(_('index "{}" is higher than the master length "{}" '
2017-12-30 18:31:56 +01:00
'for option "{}"').format(index,
2017-11-28 22:42:30 +01:00
length,
2017-12-19 23:11:45 +01:00
option.impl_get_display_name()))
slave_len = self.cfgimpl_get_values()._p_.get_max_length(subpath)
if slave_len > length:
2017-12-30 18:31:56 +01:00
raise SlaveError(_('slave option "{}" has higher length "{}" than the master length "{}"'
2017-12-19 23:11:45 +01:00
'').format(option.impl_get_display_name(),
slave_len,
length,
subpath))
2017-11-28 22:42:30 +01:00
elif index:
2018-03-24 22:37:48 +01:00
raise SlaveError(_('index is forbidden for the not slave "{}"'
2017-11-28 22:42:30 +01:00
'').format(subpath))
2017-12-23 10:40:41 +01:00
if option.impl_is_master_slaves('slave') and index is None:
value = []
length = self.cfgimpl_get_length()
for idx in range(length):
config_bag.properties = None
value.append(self.getattr(name,
idx,
config_bag))
else:
value = self.cfgimpl_get_values().get_cached_value(subpath,
index,
config_bag)
2017-12-19 23:11:45 +01:00
if config_bag.validate_properties:
self.cfgimpl_get_settings().validate_mandatory(subpath,
index,
value,
config_bag)
#FIXME utiliser le config_bag !
2017-10-22 09:48:08 +02:00
if returns_option is True:
return option
2017-12-19 23:11:45 +01:00
return value
2013-04-03 12:20:26 +02:00
2017-11-23 16:56:14 +01:00
def find(self,
2017-12-19 23:11:45 +01:00
config_bag,
2017-11-23 16:56:14 +01:00
bytype=None,
byname=None,
byvalue=undefined,
2017-12-19 23:11:45 +01:00
type_='option'):
2013-04-04 11:24:00 +02:00
"""
finds a list of options recursively in the config
:param bytype: Option class (BoolOption, StrOption, ...)
:param byname: filter by Option.impl_getname()
2013-04-04 11:24:00 +02:00
:param byvalue: filter by the option's value
:returns: list of matching Option objects
"""
2017-11-23 16:56:14 +01:00
return self._cfgimpl_get_context()._find(bytype,
byname,
byvalue,
2017-12-19 23:11:45 +01:00
config_bag,
first=False,
type_=type_,
2017-12-19 23:11:45 +01:00
_subpath=self.cfgimpl_get_path(False))
2013-04-03 12:20:26 +02:00
2017-11-23 16:56:14 +01:00
def find_first(self,
2017-12-19 23:11:45 +01:00
config_bag,
2017-11-23 16:56:14 +01:00
bytype=None,
byname=None,
byvalue=undefined,
type_='option',
2017-12-19 23:11:45 +01:00
raise_if_not_found=True):
2013-04-04 11:24:00 +02:00
"""
finds an option recursively in the config
:param bytype: Option class (BoolOption, StrOption, ...)
:param byname: filter by Option.impl_getname()
2013-04-04 11:24:00 +02:00
:param byvalue: filter by the option's value
:returns: list of matching Option objects
"""
2017-11-23 16:56:14 +01:00
return self._cfgimpl_get_context()._find(bytype,
byname,
byvalue,
2017-12-19 23:11:45 +01:00
config_bag,
2017-11-23 16:56:14 +01:00
first=True,
type_=type_,
_subpath=self.cfgimpl_get_path(False),
2017-12-19 23:11:45 +01:00
raise_if_not_found=raise_if_not_found)
2017-11-23 16:56:14 +01:00
def _find(self,
bytype,
byname,
byvalue,
2017-12-19 23:11:45 +01:00
config_bag,
2017-11-23 16:56:14 +01:00
first,
type_='option',
_subpath=None,
raise_if_not_found=True,
only_path=undefined,
2017-12-19 23:11:45 +01:00
only_option=undefined):
2013-05-02 11:34:57 +02:00
"""
convenience method for finding an option that lives only in the subtree
:param first: return only one option if True, a list otherwise
:return: find list or an exception if nothing has been found
"""
2017-12-19 23:11:45 +01:00
def _filter_by_value(sconfig_bag):
if byvalue is undefined:
2013-05-02 11:34:57 +02:00
return True
2017-11-13 22:45:53 +01:00
try:
2017-11-23 16:56:14 +01:00
value = self.getattr(path,
2017-12-19 23:11:45 +01:00
None,
sconfig_bag)
2017-11-13 22:45:53 +01:00
except PropertiesOptionError:
return False
if isinstance(value, list):
2016-01-03 21:18:52 +01:00
return byvalue in value
else:
return value == byvalue
2013-05-02 11:34:57 +02:00
2014-06-19 23:22:39 +02:00
if type_ not in ('option', 'path', 'value'): # pragma: optional cover
2013-08-20 12:08:02 +02:00
raise ValueError(_('unknown type_ type {0}'
'for _find').format(type_))
2013-05-02 11:34:57 +02:00
find_results = []
2017-12-19 23:11:45 +01:00
# if value and/or validate_properties are set, need all avalaible option
2014-02-01 16:26:23 +01:00
# If first one has no good value or not good property check second one
# and so on
2017-07-21 18:03:34 +02:00
only_first = first is True and byvalue is undefined and \
2017-12-19 23:11:45 +01:00
config_bag.validate_properties is False
if only_path is not undefined:
options = [(only_path, only_option)]
else:
2017-11-23 16:56:14 +01:00
options = self.cfgimpl_get_description().impl_get_options_paths(bytype,
byname,
_subpath,
only_first,
2017-12-19 23:11:45 +01:00
config_bag)
2014-02-01 16:26:23 +01:00
for path, option in options:
2017-12-19 23:11:45 +01:00
sconfig_bag = config_bag.copy('nooption')
sconfig_bag.option = option
if not _filter_by_value(sconfig_bag):
2013-05-02 11:34:57 +02:00
continue
#remove option with propertyerror, ...
2017-12-19 23:11:45 +01:00
if config_bag.validate_properties:
2017-11-13 22:45:53 +01:00
try:
2017-11-23 16:56:14 +01:00
self.unwrap_from_path(path,
2017-12-19 23:11:45 +01:00
config_bag)
2018-01-03 21:07:51 +01:00
self.cfgimpl_get_settings().validate_properties(path,
None,
config_bag)
2017-11-13 22:45:53 +01:00
except PropertiesOptionError:
continue
2013-05-02 11:34:57 +02:00
if type_ == 'value':
2017-11-23 16:56:14 +01:00
retval = self.getattr(path,
2017-12-19 23:11:45 +01:00
None,
config_bag)
2013-05-02 11:34:57 +02:00
elif type_ == 'path':
retval = path
elif type_ == 'option':
retval = option
if first:
return retval
else:
find_results.append(retval)
2017-11-23 16:56:14 +01:00
return self._find_return_results(find_results,
raise_if_not_found)
2017-11-23 16:56:14 +01:00
def _find_return_results(self,
find_results,
raise_if_not_found):
2014-06-19 23:22:39 +02:00
if find_results == []: # pragma: optional cover
2015-12-31 18:20:36 +01:00
if raise_if_not_found:
2013-08-20 12:08:02 +02:00
raise AttributeError(_("no option found in config"
" with these criteria"))
2013-05-02 11:34:57 +02:00
else:
return find_results
2017-11-12 14:33:05 +01:00
def make_dict(self,
2017-12-19 23:11:45 +01:00
config_bag,
2017-11-12 14:33:05 +01:00
flatten=False,
_currpath=None,
withoption=None,
withvalue=undefined,
fullpath=False):
"""exports the whole config into a `dict`, for example:
2017-11-20 17:01:36 +01:00
>>> print(cfg.make_dict())
2013-05-23 17:51:50 +02:00
{'od2.var4': None, 'od2.var5': None, 'od2.var6': None}
2013-05-23 17:51:50 +02:00
:param flatten: returns a dict(name=value) instead of a dict(path=value)
::
2017-11-20 17:01:36 +01:00
>>> print(cfg.make_dict(flatten=True))
2013-05-23 17:51:50 +02:00
{'var5': None, 'var4': None, 'var6': None}
2013-05-23 17:51:50 +02:00
:param withoption: returns the options that are present in the very same
`OptionDescription` than the `withoption` itself::
2017-11-20 17:01:36 +01:00
>>> print(cfg.make_dict(withoption='var1'))
2013-08-20 12:08:02 +02:00
{'od2.var4': None, 'od2.var5': None,
'od2.var6': None,
'od2.var1': u'value',
'od1.var1': None,
'od1.var3': None,
'od1.var2': None}
2013-05-23 17:51:50 +02:00
:param withvalue: returns the options that have the value `withvalue`
::
2017-11-20 17:01:36 +01:00
>>> print(c.make_dict(withoption='var1',
withvalue=u'value'))
2013-08-20 12:08:02 +02:00
{'od2.var4': None,
'od2.var5': None,
'od2.var6': None,
2013-05-23 17:51:50 +02:00
'od2.var1': u'value'}
2013-05-23 14:55:52 +02:00
:returns: dict of Option's name (or path) and values
"""
2013-04-04 11:24:00 +02:00
pathsvalues = []
if _currpath is None:
_currpath = []
2014-06-19 23:22:39 +02:00
if withoption is None and withvalue is not undefined: # pragma: optional cover
2013-05-02 11:34:57 +02:00
raise ValueError(_("make_dict can't filtering with value without "
"option"))
2018-03-24 22:37:48 +01:00
context = self._cfgimpl_get_context()
2013-04-04 11:24:00 +02:00
if withoption is not None:
2017-11-12 14:33:05 +01:00
for path in context._find(bytype=None,
byname=withoption,
byvalue=withvalue,
first=False,
type_='path',
_subpath=self.cfgimpl_get_path(False),
2017-12-19 23:11:45 +01:00
config_bag=config_bag):
2013-04-04 11:24:00 +02:00
path = '.'.join(path.split('.')[:-1])
2017-11-12 14:33:05 +01:00
opt = context.unwrap_from_path(path,
2017-12-19 23:11:45 +01:00
config_bag)
sconfig_bag = config_bag.copy('nooption')
sconfig_bag.option = opt
2014-06-19 23:22:39 +02:00
mypath = self.cfgimpl_get_path()
2013-04-04 11:24:00 +02:00
if mypath is not None:
if mypath == path:
withoption = None
withvalue = undefined
2013-04-04 11:24:00 +02:00
break
else:
tmypath = mypath + '.'
2014-06-19 23:22:39 +02:00
if not path.startswith(tmypath): # pragma: optional cover
2013-04-14 12:01:32 +02:00
raise AttributeError(_('unexpected path {0}, '
2013-05-02 11:34:57 +02:00
'should start with {1}'
'').format(path, mypath))
2013-04-04 11:24:00 +02:00
path = path[len(tmypath):]
2017-12-19 23:11:45 +01:00
self._make_sub_dict(path,
2017-11-23 16:56:14 +01:00
pathsvalues,
_currpath,
flatten,
2017-12-19 23:11:45 +01:00
sconfig_bag,
2017-01-06 21:01:24 +01:00
fullpath=fullpath)
2013-04-04 11:24:00 +02:00
#withoption can be set to None below !
if withoption is None:
2018-03-24 22:37:48 +01:00
for opt in self.cfgimpl_get_description().impl_getchildren(config_bag, context):
2017-12-19 23:11:45 +01:00
sconfig_bag = config_bag.copy('nooption')
sconfig_bag.option = opt
path = opt.impl_getname()
2017-12-19 23:11:45 +01:00
self._make_sub_dict(path,
2017-11-23 16:56:14 +01:00
pathsvalues,
_currpath,
flatten,
2017-12-19 23:11:45 +01:00
sconfig_bag,
2017-01-06 21:01:24 +01:00
fullpath=fullpath)
2013-04-04 11:24:00 +02:00
if _currpath == []:
options = dict(pathsvalues)
return options
return pathsvalues
2017-11-23 16:56:14 +01:00
def _make_sub_dict(self,
2017-12-13 22:15:34 +01:00
name,
2017-11-23 16:56:14 +01:00
pathsvalues,
_currpath,
flatten,
2017-12-19 23:11:45 +01:00
config_bag,
2017-11-23 16:56:14 +01:00
fullpath=False):
2017-11-13 22:45:53 +01:00
try:
2017-12-19 23:11:45 +01:00
option = config_bag.option
2017-11-28 22:42:30 +01:00
if not option.impl_is_optiondescription() and option.impl_is_master_slaves('slave'):
ret = []
length = self.cfgimpl_get_length()
if length:
for idx in range(length):
2017-12-19 23:11:45 +01:00
config_bag.properties = None
2017-12-13 22:15:34 +01:00
ret.append(self.getattr(name,
2017-12-19 23:11:45 +01:00
idx,
config_bag))
elif config_bag.setting_properties:
2017-12-13 22:15:34 +01:00
path = self._get_subpath(name)
2017-12-19 23:11:45 +01:00
self.cfgimpl_get_settings().validate_properties(path,
None,
config_bag)
2017-11-28 22:42:30 +01:00
else:
2017-12-13 22:15:34 +01:00
ret = self.getattr(name,
2017-12-19 23:11:45 +01:00
None,
config_bag)
2017-11-28 22:42:30 +01:00
except PropertiesOptionError:
2017-11-13 22:45:53 +01:00
pass
2016-01-03 21:18:52 +01:00
else:
2017-11-28 22:42:30 +01:00
if option.impl_is_optiondescription():
2017-12-19 23:11:45 +01:00
pathsvalues += ret.make_dict(config_bag,
2017-11-28 22:42:30 +01:00
flatten=flatten,
2017-12-13 22:15:34 +01:00
_currpath=_currpath + [name],
2017-11-28 22:42:30 +01:00
fullpath=fullpath)
2014-02-04 21:14:30 +01:00
else:
2013-04-04 11:24:00 +02:00
if flatten:
2017-11-28 22:42:30 +01:00
name = option.impl_getname()
elif fullpath:
#FIXME
#root_path = self.cfgimpl_get_path()
#if root_path is None:
# name = opt.impl_getname()
#else:
# name = '.'.join([root_path, opt.impl_getname()])
name = self._get_subpath(name)
2013-04-04 11:24:00 +02:00
else:
2017-12-13 22:15:34 +01:00
name = '.'.join(_currpath + [name])
2017-11-28 22:42:30 +01:00
pathsvalues.append((name, ret))
2013-04-03 12:20:26 +02:00
2017-11-23 16:56:14 +01:00
def cfgimpl_get_path(self,
dyn=True):
2013-05-02 11:34:57 +02:00
descr = self.cfgimpl_get_description()
2014-06-19 23:22:39 +02:00
if not dyn and descr.impl_is_dynoptiondescription():
context_descr = self._cfgimpl_get_context().cfgimpl_get_description()
2017-11-23 16:56:14 +01:00
return context_descr.impl_get_path_by_opt(descr.impl_getopt())
2014-06-19 23:22:39 +02:00
return self._impl_path
2013-04-03 12:20:26 +02:00
2013-09-30 16:22:08 +02:00
class _CommonConfig(SubConfig):
"abstract base class for the Config, GroupConfig and the MetaConfig"
2017-12-19 23:11:45 +01:00
__slots__ = ('_impl_values',
'_impl_settings',
'_impl_meta',
'_impl_test')
2013-04-03 12:20:26 +02:00
2017-11-23 16:56:14 +01:00
def _impl_build_all_caches(self,
force_store_values):
2015-05-03 09:56:03 +02:00
descr = self.cfgimpl_get_description()
if not descr.impl_already_build_caches():
2017-09-17 15:55:32 +02:00
descr._build_cache_option()
descr._build_cache(self)
2017-11-23 16:56:14 +01:00
descr.impl_build_force_store_values(self,
force_store_values)
2017-11-12 14:33:05 +01:00
def unwrap_from_path(self,
path,
2017-12-19 23:11:45 +01:00
config_bag):
2013-04-03 12:20:26 +02:00
"""convenience method to extract and Option() object from the Config()
and it is **fast**: finds the option directly in the appropriate
namespace
:returns: Option()
"""
if '.' in path:
2017-10-22 09:48:08 +02:00
self, path = self.cfgimpl_get_home_by_path(path,
2017-12-19 23:11:45 +01:00
config_bag)
2017-11-29 23:25:34 +01:00
option = self.cfgimpl_get_description().impl_getchild(path,
2017-12-19 23:11:45 +01:00
config_bag,
2017-12-02 22:53:57 +01:00
self)
2017-12-19 23:11:45 +01:00
if not config_bag.validate_properties:
2017-11-13 22:45:53 +01:00
return option
2017-11-12 14:33:05 +01:00
else:
2017-12-04 20:05:36 +01:00
if option.impl_is_symlinkoption():
true_option = option.impl_getopt()
true_path = true_option.impl_getpath(self._cfgimpl_get_context())
self, path = self.cfgimpl_get_context().cfgimpl_get_home_by_path(true_path,
2017-12-19 23:11:45 +01:00
config_bag)
config_bag.option = true_option
2017-12-04 20:05:36 +01:00
else:
true_path = path
2017-12-19 23:11:45 +01:00
config_bag.option = option
2017-12-04 20:05:36 +01:00
return option
2013-04-03 12:20:26 +02:00
2014-06-19 23:22:39 +02:00
def cfgimpl_get_path(self, dyn=True):
2013-04-04 11:24:00 +02:00
return None
2013-04-03 12:20:26 +02:00
2013-05-02 11:34:57 +02:00
def cfgimpl_get_meta(self):
2013-09-30 16:22:08 +02:00
if self._impl_meta is not None:
return self._impl_meta()
# information
def impl_set_information(self, key, value):
"""updates the information's attribute
:param key: information's key (ex: "help", "doc"
:param value: information's value (ex: "the help string")
"""
self._impl_values.set_information(key, value)
def impl_get_information(self, key, default=undefined):
"""retrieves one information's item
:param key: the item string (ex: "help")
"""
return self._impl_values.get_information(key, default)
def impl_del_information(self, key, raises=True):
self._impl_values.del_information(key, raises)
2013-09-22 20:57:52 +02:00
def __getstate__(self):
2017-07-21 18:46:11 +02:00
raise NotImplementedError()
2012-10-12 11:35:07 +02:00
2017-11-12 14:33:05 +01:00
def _gen_fake_values(self):
2017-11-23 16:56:14 +01:00
fake_config = Config(self._impl_descr,
persistent=False,
2017-07-16 10:57:43 +02:00
force_values=get_default_values_storages(),
2015-05-03 09:56:03 +02:00
force_settings=self.cfgimpl_get_settings())
2017-11-12 14:33:05 +01:00
fake_config.cfgimpl_get_values()._p_.importation(self.cfgimpl_get_values()._p_.exportation(fake=True))
2015-04-18 22:53:45 +02:00
return fake_config
2017-11-23 16:56:14 +01:00
def duplicate(self,
session_id=None,
force_values=None,
force_settings=None):
config = Config(self._impl_descr,
_duplicate=True,
session_id=session_id,
force_values=force_values,
2017-07-16 10:57:43 +02:00
force_settings=force_settings)
2017-11-12 14:33:05 +01:00
config.cfgimpl_get_values()._p_.importation(self.cfgimpl_get_values()._p_.exportation())
config.cfgimpl_get_settings()._p_.importation(self.cfgimpl_get_settings(
)._p_.exportation())
config.cfgimpl_get_settings()._pp_.importation(self.cfgimpl_get_settings(
)._pp_.exportation())
2015-07-24 17:54:10 +02:00
return config
2013-09-30 16:22:08 +02:00
# ____________________________________________________________
class Config(_CommonConfig):
"main configuration management entry"
__slots__ = ('__weakref__', '_impl_test', '_impl_name')
2013-09-30 16:22:08 +02:00
def __init__(self,
descr,
session_id=None,
persistent=False,
force_values=None,
force_settings=None,
_duplicate=False,
_force_store_values=True):
2013-09-30 16:22:08 +02:00
""" Configuration option management master class
:param descr: describes the configuration schema
:type descr: an instance of ``option.OptionDescription``
:param context: the current root config
:type context: `Config`
:param session_id: session ID is import with persistent Config to
retrieve good session
:type session_id: `str`
:param persistent: if persistent, don't delete storage when leaving
:type persistent: `boolean`
"""
2017-12-19 23:11:45 +01:00
self._impl_meta = None
2018-01-01 21:32:39 +01:00
if isinstance(descr, MasterSlaves):
raise ConfigError(_('cannot set MasterSlaves object has root optiondescription'))
if force_settings is not None and force_values is not None:
2017-07-16 10:57:43 +02:00
if isinstance(force_settings, tuple):
self._impl_settings = Settings(self,
force_settings[0],
force_settings[1])
2017-07-16 10:57:43 +02:00
else:
self._impl_settings = force_settings
self._impl_values = Values(self,
force_values)
else:
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),
2017-12-19 23:11:45 +01:00
ConfigBag(self),
None)
2015-05-03 09:56:03 +02:00
#undocumented option used only in test script
self._impl_test = False
if _duplicate is False and (force_settings is None or force_values is None):
2017-07-11 22:31:58 +02:00
self._impl_build_all_caches(_force_store_values)
self._impl_name = session_id
2013-09-30 16:22:08 +02:00
def impl_getname(self):
return self._impl_name
def impl_getsessionid(self):
return self._impl_values._p_._storage.session_id
2013-09-30 16:22:08 +02:00
class GroupConfig(_CommonConfig):
__slots__ = ('__weakref__',
'_impl_children',
'_impl_name')
2012-10-12 11:35:07 +02:00
def __init__(self,
children,
session_id=None,
persistent=False,
_descr=None):
2013-09-17 09:02:10 +02:00
if not isinstance(children, list):
raise ValueError(_("groupconfig's children must be a list"))
names = []
for child in children:
if not isinstance(child,
_CommonConfig):
raise ValueError(_("groupconfig's children must be Config, MetaConfig or GroupConfig"))
name_ = child._impl_name
names.append(name_)
if len(names) != len(set(names)):
for idx in xrange(1, len(names) + 1):
name = names.pop(0)
if name in names:
raise ConflictError(_('config name must be uniq in '
'groupconfig for {0}').format(name))
2013-09-17 09:02:10 +02:00
self._impl_children = children
properties, permissives, values, session_id = get_storages(self,
session_id,
persistent)
self._impl_settings = Settings(self,
properties,
permissives)
2013-09-17 09:02:10 +02:00
self._impl_values = Values(self, values)
2018-01-03 21:07:51 +01:00
self._impl_meta = None
super(GroupConfig, self).__init__(_descr,
weakref.ref(self),
2018-01-03 21:07:51 +01:00
ConfigBag(self),
None)
2013-09-30 16:22:08 +02:00
#undocumented option used only in test script
self._impl_test = False
self._impl_name = session_id
2013-09-17 09:02:10 +02:00
def cfgimpl_get_children(self):
return self._impl_children
2013-08-20 12:08:02 +02:00
def cfgimpl_reset_cache(self,
only_expired=False,
2017-07-08 15:59:56 +02:00
opt=None,
2017-09-17 15:55:32 +02:00
path=None,
2017-12-19 23:11:45 +01:00
resetted_opts=None):
if resetted_opts is None:
resetted_opts = []
2017-07-08 15:59:56 +02:00
if isinstance(self, MetaConfig):
super(GroupConfig, self).cfgimpl_reset_cache(only_expired=only_expired,
opt=opt,
path=path,
resetted_opts=copy(resetted_opts))
2013-09-17 09:02:10 +02:00
for child in self._impl_children:
child.cfgimpl_reset_cache(only_expired=only_expired,
opt=opt,
path=path,
resetted_opts=copy(resetted_opts))
2013-02-22 11:09:17 +01:00
2018-01-03 21:07:51 +01:00
def set_value(self,
path,
index,
value,
config_bag,
only_config=False,
_commit=True):
2013-09-30 16:22:08 +02:00
"""Setattr not in current GroupConfig, but in each children
"""
ret = []
2013-09-17 09:02:10 +02:00
for child in self._impl_children:
2018-01-03 21:07:51 +01:00
try:
if isinstance(child, GroupConfig):
ret.extend(child.set_value(path,
index,
value,
config_bag,
only_config=only_config,
_commit=False))
else:
nconfig_bag = config_bag.copy('nooption')
child.setattr(path,
index,
value,
nconfig_bag,
_commit=False)
2018-01-03 23:33:35 +01:00
except PropertiesOptionError as err:
ret.append(PropertiesOptionError(str(err), err.proptype))
except (ValueError, SlaveError) as err:
2018-01-03 21:07:51 +01:00
ret.append(err)
2017-07-16 23:11:12 +02:00
if _commit:
self.cfgimpl_get_values()._p_.commit()
return ret
2017-07-16 23:11:12 +02:00
def find_firsts(self,
2018-01-03 21:07:51 +01:00
config_bag,
byname=None,
bypath=undefined,
byoption=undefined,
byvalue=undefined,
raise_if_not_found=True,
2018-01-03 21:07:51 +01:00
_sub=False):
2013-09-30 16:22:08 +02:00
"""Find first not in current GroupConfig, but in each children
"""
2013-09-17 09:02:10 +02:00
ret = []
#if MetaConfig, all children have same OptionDescription in context
#so search only one time the option for all children
if bypath is undefined and byname is not None and \
isinstance(self,
MetaConfig):
bypath = self._find(bytype=None,
byvalue=undefined,
byname=byname,
first=True,
2018-01-03 21:07:51 +01:00
config_bag=config_bag,
type_='path',
2015-12-31 18:20:36 +01:00
raise_if_not_found=raise_if_not_found)
byname = None
byoption = self.cfgimpl_get_description().impl_get_opt_by_path(bypath)
2013-09-17 09:02:10 +02:00
for child in self._impl_children:
2018-01-03 21:07:51 +01:00
nconfig_bag = config_bag.copy('nooption')
nconfig_bag.option = child
2015-12-31 18:20:36 +01:00
if isinstance(child, GroupConfig):
ret.extend(child.find_firsts(byname=byname,
bypath=bypath,
2015-12-31 18:20:36 +01:00
byoption=byoption,
byvalue=byvalue,
2018-01-03 21:07:51 +01:00
config_bag=config_bag,
2015-12-31 18:20:36 +01:00
raise_if_not_found=False,
_sub=True))
elif child._find(None,
byname,
byvalue,
first=True,
type_='path',
2018-01-03 21:07:51 +01:00
config_bag=config_bag,
raise_if_not_found=False,
only_path=bypath,
only_option=byoption):
2015-12-31 18:20:36 +01:00
ret.append(child)
if _sub:
return ret
else:
return GroupConfig(self._find_return_results(ret,
raise_if_not_found))
2013-05-02 11:34:57 +02:00
2018-01-03 21:07:51 +01:00
def impl_getname(self):
return self._impl_name
# def __str__(self):
# ret = ''
# for child in self._impl_children:
# ret += "({0})\n".format(child._impl_name)
# if self._impl_descr is not None:
# ret += super(GroupConfig, self).__str__()
# return ret
#
# __repr__ = __str__
2017-07-21 18:03:34 +02:00
2017-11-23 16:56:14 +01:00
def getconfig(self,
name):
for child in self._impl_children:
if name == child.impl_getname():
return child
2017-11-23 16:56:14 +01:00
raise ConfigError(_('unknown config {}').format(name))
2014-11-10 23:15:08 +01:00
2013-09-30 16:22:08 +02:00
class MetaConfig(GroupConfig):
__slots__ = tuple()
def __init__(self,
children,
session_id=None,
persistent=False,
optiondescription=None,
_force_store_values=True):
2013-09-30 16:22:08 +02:00
descr = None
2017-07-11 22:31:58 +02:00
if optiondescription is not None:
new_children = []
for child_session_id in children:
new_children.append(Config(optiondescription,
persistent=persistent,
session_id=child_session_id,
_force_store_values=_force_store_values))
2017-07-11 22:31:58 +02:00
children = new_children
2013-09-30 16:22:08 +02:00
for child in children:
if not isinstance(child, _CommonConfig):
raise TypeError(_("metaconfig's children "
"should be config, not {0}"
).format(type(child)))
if child.cfgimpl_get_meta() is not None:
raise ValueError(_("child has already a metaconfig's"))
if descr is None:
descr = child.cfgimpl_get_description()
elif not descr is child.cfgimpl_get_description():
raise ValueError(_('all config in metaconfig must '
'have the same optiondescription'))
child._impl_meta = weakref.ref(self)
super(MetaConfig, self).__init__(children,
session_id,
persistent,
descr)
def set_value(self,
path,
2018-01-03 21:07:51 +01:00
index,
value,
2018-01-03 21:07:51 +01:00
config_bag,
force_default=False,
force_dont_change_value=False,
force_default_if_same=False,
only_config=False,
_commit=True):
"""only_config: could be set if you want modify value in all Config included in
this MetaConfig
"""
if only_config:
if force_default or force_default_if_same or force_dont_change_value:
raise ValueError(_('force_default, force_default_if_same or '
'force_dont_change_value cannot be set with'
' only_config'))
return super(MetaConfig, self).set_value(path,
2018-01-03 21:07:51 +01:00
index,
value,
2018-01-03 21:07:51 +01:00
config_bag,
only_config=only_config,
_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'
' cannot be set together'))
opt = self.cfgimpl_get_description().impl_get_opt_by_path(path)
for child in self._impl_children:
2018-01-03 21:07:51 +01:00
nconfig_bag = config_bag.copy('nooption')
nconfig_bag.option = opt
if force_default_if_same:
if not child.cfgimpl_get_values()._p_.hasvalue(path):
child_value = undefined
else:
child_value = child.getattr(path,
None,
nconfig_bag)
if force_default or (force_default_if_same and value == child_value):
child.cfgimpl_get_values().reset(path,
nconfig_bag,
_commit=False)
continue
if force_dont_change_value:
2018-01-03 21:07:51 +01:00
try:
child_value = child.getattr(path,
None,
nconfig_bag)
if value != child_value:
child.setattr(path,
None,
child_value,
nconfig_bag,
_commit=False)
except (PropertiesOptionError, ValueError, SlaveError) as err:
ret.append(err)
nconfig_bag = config_bag.copy('nooption')
try:
self.setattr(path,
index,
value,
nconfig_bag,
_commit=_commit)
except (PropertiesOptionError, ValueError, SlaveError) as err:
ret.append(err)
return ret
2017-07-08 15:59:56 +02:00
2018-01-03 21:07:51 +01:00
def reset(self, path, config_bag):
#FIXME not working with DynSymLinkOption
#FIXME fonctionne avec sous metaconfig ??
opt = self.cfgimpl_get_description().impl_get_opt_by_path(path)
2018-01-03 21:07:51 +01:00
config_bag.option = opt
config_bag.validate = False
for child in self._impl_children:
2018-01-03 21:07:51 +01:00
sconfig_bag = config_bag.copy('nooption')
sconfig_bag.option = opt
child.cfgimpl_get_values().reset(path,
sconfig_bag,
_commit=False)
2018-01-03 21:07:51 +01:00
self.cfgimpl_get_values().reset(path,
config_bag)
def new_config(self,
session_id,
persistent=False):
config = Config(self._impl_descr,
session_id=session_id,
2017-07-21 18:03:34 +02:00
persistent=persistent)
if config._impl_name in [child._impl_name for child in self._impl_children]: # pragma: no cover
raise ConflictError(_('config name must be uniq in '
'groupconfig for {0}').format(config._impl_name))
config._impl_meta = weakref.ref(self)
self._impl_children.append(config)
return config