In make_dict check PropertyConfigError for OptionDescription

Begin work's on MetaConfig
This commit is contained in:
Emmanuel Garette 2013-04-24 11:47:01 +02:00
parent f0ef1734f4
commit f28288fbba

View File

@ -299,8 +299,11 @@ class SubConfig(object):
def _make_sub_dict(self, opt, path, pathsvalues, _currpath, flatten):
if isinstance(opt, OptionDescription):
pathsvalues += getattr(self, path).make_dict(flatten,
_currpath + path.split('.'))
try:
pathsvalues += getattr(self, path).make_dict(flatten,
_currpath + path.split('.'))
except PropertiesOptionError:
pass # this just a hidden or disabled option
else:
try:
value = self._getattr(opt._name)
@ -366,7 +369,7 @@ class Config(SubConfig):
return None
def _find(self, bytype, byname, byvalue, first, type_='option',
_subpath=None):
_subpath=None, check_properties=True):
"""
convenience method for finding an option that lives only in the subtree
@ -426,10 +429,12 @@ class Config(SubConfig):
if not _filter_by_value():
continue
#remove option with propertyerror, ...
try:
value = getattr(self, path)
except PropertiesOptionError: # a property restricts the access of the value
continue
if check_properties:
try:
value = getattr(self, path)
except PropertiesOptionError:
# a property restricts the access of the value
continue
if not _filter_by_type():
continue
#if not _filter_by_attrs():
@ -450,6 +455,48 @@ class Config(SubConfig):
return find_results
class MetaConfig(object):
__slots__ = ('_children')
def __init__(self, children):
if not isinstance(children, list):
raise ValueError(_("metaconfig's children must be a list"))
descr = None
for child in children:
if not isinstance(child, Config):
raise ValueError(_("metaconfig's children must be Config, not {0}"
"".format(type(Config))))
if descr is None:
descr = child.cfgimpl_get_description()
elif descr is child.cfgimpl_get_description():
raise ValueError(_('all config in MetaConfig must have same '
'optiondescription'))
self._children = children
def _find(self, bytype, byname, byvalue, first, type_):
if type_ not in ('option', 'path'):
raise ValueError(_('unknown type_ type {0} for _find'
'').format(type_))
#all children have same optiondescription, search in first one's
return self._children[0]._find(bytype, byname, byvalue, first=first,
type_=type_, check_properties=False)
def find(self, bytype=None, byname=None, byvalue=None, type_='option'):
return self._find(bytype, byname, byvalue, type_, first=False)
def find_first(self, bytype=None, byname=None, byvalue=None,
type_='option'):
return self._find(bytype, byname, byvalue, type_, first=True)
def __setattr__(self, name, value):
for child in self._children:
try:
setattr(child, name, value)
except PropertiesOptionError:
pass
def mandatory_warnings(config):
"""convenience function to trace Options that are mandatory and
where no value has been set