__getattr__ OD
This commit is contained in:
parent
2f40216fad
commit
8709386570
|
@ -120,8 +120,7 @@ def test_find_in_config():
|
|||
assert conf.find(byname='prop') == [conf.unwrap_from_path('gc.prop')]
|
||||
conf.read_write()
|
||||
raises(AttributeError, "assert conf.find(byname='prop')")
|
||||
assert conf.find(byname='prop', check_properties=False) == [conf.unwrap_from_path('gc.gc2.prop'), conf.unwrap_from_path('gc.prop')]
|
||||
#assert conf.find_first(byname='prop') == conf.unwrap_from_path('gc.prop')
|
||||
assert conf.find(byname='prop', check_properties=False) == [conf.unwrap_from_path('gc.prop'), conf.unwrap_from_path('gc.gc2.prop')]
|
||||
# combinaison of filters
|
||||
assert conf.find(bytype=BoolOption, byname='dummy') == [conf.unwrap_from_path('gc.dummy')]
|
||||
assert conf.find_first(bytype=BoolOption, byname='dummy') == conf.unwrap_from_path('gc.dummy')
|
||||
|
@ -134,7 +133,7 @@ def test_find_in_config():
|
|||
assert conf.gc.find_first(byname='bool', byvalue=False) == conf.unwrap_from_path('gc.gc2.bool')
|
||||
raises(AttributeError, "assert conf.gc.find_first(byname='bool', byvalue=True)")
|
||||
raises(AttributeError, "conf.gc.find(byname='wantref').first()")
|
||||
assert conf.gc.find(byname='prop', check_properties=False) == [conf.unwrap_from_path('gc.gc2.prop'), conf.unwrap_from_path('gc.prop')]
|
||||
assert conf.gc.find(byname='prop', check_properties=False) == [conf.unwrap_from_path('gc.prop'), conf.unwrap_from_path('gc.gc2.prop')]
|
||||
conf.read_only()
|
||||
assert conf.gc.find(byname='prop') == [conf.unwrap_from_path('gc.prop')]
|
||||
# not OptionDescription
|
||||
|
|
|
@ -320,9 +320,7 @@ class SubConfig(object):
|
|||
# if value and/or check_properties are set, need all avalaible option
|
||||
# If first one has no good value or not good property check second one
|
||||
# and so on
|
||||
#FIXME
|
||||
#only_first = first == True and value is None and check_properties is None
|
||||
only_first = first
|
||||
only_first = first is True and byvalue is None and check_properties is None
|
||||
options = self.cfgimpl_get_description().impl_get_options_paths(
|
||||
bytype, byname, _subpath, only_first)
|
||||
for path, option in options:
|
||||
|
|
|
@ -366,7 +366,7 @@ class Option(OnlyOption):
|
|||
#so _name is already set
|
||||
is_readonly = True
|
||||
#FIXME je n'aime pas ce except ...
|
||||
except:
|
||||
except KeyError:
|
||||
pass
|
||||
elif name != '_readonly':
|
||||
is_readonly = self.impl_is_readonly()
|
||||
|
@ -805,7 +805,6 @@ class SymLinkOption(OnlyOption):
|
|||
super(SymLinkOption, self)._impl_setstate(descr)
|
||||
|
||||
def impl_get_information(self, key, default=None):
|
||||
#FIXME ne devrait pas etre utile si ?
|
||||
return self._opt.impl_get_information(key, default)
|
||||
|
||||
|
||||
|
@ -1179,38 +1178,15 @@ class OptionDescription(BaseOption, StorageOptionDescription):
|
|||
self._group_type = groups.default
|
||||
|
||||
def impl_getrequires(self):
|
||||
#FIXME
|
||||
return self._requires
|
||||
|
||||
def impl_getdoc(self):
|
||||
return self.impl_get_information('doc')
|
||||
|
||||
def impl_validate(self, *args):
|
||||
#FIXME a voir ...
|
||||
"""usefull for OptionDescription"""
|
||||
pass
|
||||
|
||||
def __getattr__(self, name):
|
||||
try:
|
||||
if name.startswith('_') or name.startswith('impl_'):
|
||||
return object.__getattribute__(self, name)
|
||||
else:
|
||||
#FIXME regression ... devrait etre un query !
|
||||
for child in self._children:
|
||||
if child.impl_getname() == name:
|
||||
return child
|
||||
#convert to object
|
||||
#return session.query(child._type).filter_by(id=child.id).first()
|
||||
#return pouet#self._children[1][self._children[0].index(name)]
|
||||
except ValueError:
|
||||
pass
|
||||
raise AttributeError(_('unknown Option {0} '
|
||||
'in OptionDescription {1}'
|
||||
'').format(name, self.impl_getname()))
|
||||
|
||||
#def impl_getkey(self, config):
|
||||
# return tuple([child.impl_getkey(getattr(config, child.impl_getname()))
|
||||
# for child in self.impl_getchildren()])
|
||||
|
||||
def impl_getpaths(self, include_groups=False, _currpath=None):
|
||||
"""returns a list of all paths in self, recursively
|
||||
_currpath should not be provided (helps with recursion)
|
||||
|
@ -1288,7 +1264,6 @@ class OptionDescription(BaseOption, StorageOptionDescription):
|
|||
if init:
|
||||
self._readonly = True
|
||||
|
||||
|
||||
# ____________________________________________________________
|
||||
def impl_set_group_type(self, group_type):
|
||||
"""sets a given group object to an OptionDescription
|
||||
|
|
|
@ -382,8 +382,6 @@ class StorageOptionDescription(object):
|
|||
session.commit()
|
||||
|
||||
def impl_get_options_paths(self, bytype, byname, _subpath, only_first):
|
||||
#FIXME tester si 1er est un descr ...
|
||||
#FAIRE UN JOIN pour only_first
|
||||
sqlquery = session.query(Cache).filter_by(descr=self.id)
|
||||
if bytype is None:
|
||||
sqlquery = sqlquery.filter(not_(Cache.opt_type == 'OptionDescription'))
|
||||
|
@ -415,6 +413,16 @@ class StorageOptionDescription(object):
|
|||
ret.append((opt.path, option))
|
||||
return ret
|
||||
|
||||
def __getattr__(self, name):
|
||||
if name.startswith('_') or name.startswith('impl_'):
|
||||
return object.__getattribute__(self, name)
|
||||
ret = session.query(_Base).filter_by(_parent=self.id, _name=name).first()
|
||||
if ret is None:
|
||||
raise AttributeError(_('unknown Option {0} '
|
||||
'in OptionDescription {1}'
|
||||
'').format(name, self.impl_getname()))
|
||||
return ret
|
||||
|
||||
|
||||
class StorageBase(_Base):
|
||||
@declared_attr
|
||||
|
|
Loading…
Reference in New Issue