In make_dict check PropertyConfigError for OptionDescription
Begin work's on MetaConfig
This commit is contained in:
parent
f0ef1734f4
commit
f28288fbba
|
@ -299,8 +299,11 @@ class SubConfig(object):
|
||||||
|
|
||||||
def _make_sub_dict(self, opt, path, pathsvalues, _currpath, flatten):
|
def _make_sub_dict(self, opt, path, pathsvalues, _currpath, flatten):
|
||||||
if isinstance(opt, OptionDescription):
|
if isinstance(opt, OptionDescription):
|
||||||
pathsvalues += getattr(self, path).make_dict(flatten,
|
try:
|
||||||
_currpath + path.split('.'))
|
pathsvalues += getattr(self, path).make_dict(flatten,
|
||||||
|
_currpath + path.split('.'))
|
||||||
|
except PropertiesOptionError:
|
||||||
|
pass # this just a hidden or disabled option
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
value = self._getattr(opt._name)
|
value = self._getattr(opt._name)
|
||||||
|
@ -366,7 +369,7 @@ class Config(SubConfig):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _find(self, bytype, byname, byvalue, first, type_='option',
|
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
|
convenience method for finding an option that lives only in the subtree
|
||||||
|
|
||||||
|
@ -426,10 +429,12 @@ class Config(SubConfig):
|
||||||
if not _filter_by_value():
|
if not _filter_by_value():
|
||||||
continue
|
continue
|
||||||
#remove option with propertyerror, ...
|
#remove option with propertyerror, ...
|
||||||
try:
|
if check_properties:
|
||||||
value = getattr(self, path)
|
try:
|
||||||
except PropertiesOptionError: # a property restricts the access of the value
|
value = getattr(self, path)
|
||||||
continue
|
except PropertiesOptionError:
|
||||||
|
# a property restricts the access of the value
|
||||||
|
continue
|
||||||
if not _filter_by_type():
|
if not _filter_by_type():
|
||||||
continue
|
continue
|
||||||
#if not _filter_by_attrs():
|
#if not _filter_by_attrs():
|
||||||
|
@ -450,6 +455,48 @@ class Config(SubConfig):
|
||||||
return find_results
|
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):
|
def mandatory_warnings(config):
|
||||||
"""convenience function to trace Options that are mandatory and
|
"""convenience function to trace Options that are mandatory and
|
||||||
where no value has been set
|
where no value has been set
|
||||||
|
|
Loading…
Reference in New Issue