option.dict => value.dict
This commit is contained in:
105
tiramisu/api.py
105
tiramisu/api.py
@ -403,16 +403,17 @@ class TiramisuOptionInformation(CommonTiramisuOption):
|
||||
|
||||
class TiramisuOptionValue(CommonTiramisuOption):
|
||||
"""manager option's value"""
|
||||
allow_optiondescription = True
|
||||
slave_need_index = False
|
||||
|
||||
def get(self):
|
||||
def _o_get(self):
|
||||
"""get option's value"""
|
||||
option = self.option_bag.option
|
||||
self._test_slave_index()
|
||||
return self.subconfig.getattr(self._name,
|
||||
self.option_bag)
|
||||
|
||||
def set(self, value):
|
||||
def _o_set(self, value):
|
||||
"""set a value for a specified option"""
|
||||
option = self.option_bag.option
|
||||
self._test_slave_index()
|
||||
@ -432,7 +433,7 @@ class TiramisuOptionValue(CommonTiramisuOption):
|
||||
self.subconfig.setattr(value,
|
||||
self.option_bag)
|
||||
|
||||
def _pop(self, index):
|
||||
def _m_pop(self, index):
|
||||
"""pop value for a master option (only for master option)"""
|
||||
if self.option_bag.option.impl_is_symlinkoption():
|
||||
raise TypeError(_("can't delete a SymLinkOption"))
|
||||
@ -440,12 +441,12 @@ class TiramisuOptionValue(CommonTiramisuOption):
|
||||
self.option_bag,
|
||||
self.subconfig)
|
||||
|
||||
def reset(self):
|
||||
def _o_reset(self):
|
||||
"""reset value for a value"""
|
||||
self._test_slave_index()
|
||||
self.subconfig.delattr(self.option_bag)
|
||||
|
||||
def _len_master(self):
|
||||
def _m_len_master(self):
|
||||
"""length of master option (only for slave option)"""
|
||||
option = self.option_bag.option
|
||||
# for example if index is None
|
||||
@ -453,7 +454,7 @@ class TiramisuOptionValue(CommonTiramisuOption):
|
||||
self._length = self.subconfig.cfgimpl_get_length()
|
||||
return self._length
|
||||
|
||||
def _len_slave(self):
|
||||
def _s_len_slave(self):
|
||||
"""length of slave option (only for slave option)"""
|
||||
option = self.option_bag.option
|
||||
# for example if index is None
|
||||
@ -463,22 +464,49 @@ class TiramisuOptionValue(CommonTiramisuOption):
|
||||
|
||||
def __getattr__(self, name: str) -> Callable:
|
||||
option = self.option_bag.option
|
||||
if name == 'list' and isinstance(option, ChoiceOption):
|
||||
return self._list
|
||||
if name.startswith('_'):
|
||||
# not a valid function
|
||||
pass
|
||||
elif name == 'list' and isinstance(option, ChoiceOption):
|
||||
return self._c_list
|
||||
elif name == 'pop' and option.impl_is_master_slaves('master'):
|
||||
return self._pop
|
||||
return self._m_pop
|
||||
elif name == 'len':
|
||||
if option.impl_is_master_slaves('slave'):
|
||||
return self._len_slave
|
||||
return self._s_len_slave
|
||||
if option.impl_is_master_slaves('master'):
|
||||
return self._len_master
|
||||
return self._m_len_master
|
||||
elif name == 'dict' and option.impl_is_optiondescription():
|
||||
return self._od_dict
|
||||
elif not option.impl_is_optiondescription():
|
||||
return getattr(self, '_o_' + name)
|
||||
raise APIError(_('{} is unknown').format(name))
|
||||
|
||||
def _list(self):
|
||||
def _c_list(self):
|
||||
"""all values available for an option (only for choiceoption)"""
|
||||
option = self.option_bag.option
|
||||
return option.impl_get_values(self.option_bag)
|
||||
|
||||
def _od_dict(self,
|
||||
flatten=False,
|
||||
withvalue=undefined,
|
||||
withoption=None,
|
||||
fullpath=False):
|
||||
"""return dict with path as key and value (only for optiondescription)"""
|
||||
self._get_option()
|
||||
name = self.option_bag.option.impl_getname()
|
||||
subconfig = self.subconfig.get_subconfig(name,
|
||||
self.option_bag)
|
||||
config_bag = self.option_bag.config_bag
|
||||
if config_bag.properties and 'warnings' in config_bag.properties:
|
||||
config_bag = config_bag.copy()
|
||||
config_bag.properties = config_bag.properties - {'warnings'}
|
||||
return subconfig.make_dict(config_bag=config_bag,
|
||||
flatten=flatten,
|
||||
fullpath=fullpath,
|
||||
withoption=withoption,
|
||||
withvalue=withvalue)
|
||||
|
||||
|
||||
def registers(registers: Dict[str, type], prefix: str) -> None:
|
||||
for module_name in globals().keys():
|
||||
@ -521,25 +549,6 @@ class TiramisuOption(CommonTiramisu):
|
||||
return getattr(self, '_' + subfunc)
|
||||
raise APIError(_('please specify a valid sub function ({})').format(subfunc))
|
||||
|
||||
def dict(self,
|
||||
flatten=False,
|
||||
withvalue=undefined,
|
||||
withoption=None,
|
||||
fullpath=False):
|
||||
"""return dict with path as key and value (only for optiondescription)"""
|
||||
self._get_option()
|
||||
if not self.config_bag.properties:
|
||||
config_bag = self.config_bag
|
||||
else:
|
||||
config_bag = self.config_bag.copy()
|
||||
config_bag.properties = self.config_bag.properties - {'warnings'}
|
||||
return config_bag.context.get_subconfig(self._path,
|
||||
self.option_bag).make_dict(config_bag=config_bag,
|
||||
flatten=flatten,
|
||||
fullpath=fullpath,
|
||||
withoption=withoption,
|
||||
withvalue=withvalue)
|
||||
|
||||
def _find(self,
|
||||
name: str,
|
||||
value=undefined,
|
||||
@ -714,6 +723,23 @@ class TiramisuContextValue(TiramisuContext):
|
||||
self.config_bag.context.reset(path,
|
||||
self.config_bag)
|
||||
|
||||
def dict(self,
|
||||
flatten=False,
|
||||
withvalue=undefined,
|
||||
withoption=None,
|
||||
fullpath=False):
|
||||
"""return dict with path as key and value"""
|
||||
if not self.config_bag.properties:
|
||||
config_bag = self.config_bag
|
||||
else:
|
||||
config_bag = self.config_bag.copy()
|
||||
config_bag.properties = self.config_bag.properties - {'warnings'}
|
||||
return config_bag.context.make_dict(config_bag,
|
||||
flatten=flatten,
|
||||
fullpath=fullpath,
|
||||
withoption=withoption,
|
||||
withvalue=withvalue)
|
||||
|
||||
def exportation(self):
|
||||
"""export all values"""
|
||||
return self.config_bag.context.cfgimpl_get_values()._p_.exportation()
|
||||
@ -974,23 +1000,6 @@ class TiramisuContextConfig(TiramisuContext):
|
||||
raise APIError(_('{} is unknown').format(name))
|
||||
raise APIError(_('{} is unknown').format(name))
|
||||
|
||||
def dict(self,
|
||||
flatten=False,
|
||||
withvalue=undefined,
|
||||
withoption=None,
|
||||
fullpath=False):
|
||||
"""return dict with path as key and value"""
|
||||
if not self.config_bag.properties:
|
||||
config_bag = self.config_bag
|
||||
else:
|
||||
config_bag = self.config_bag.copy()
|
||||
config_bag.properties = self.config_bag.properties - {'warnings'}
|
||||
return config_bag.context.make_dict(config_bag,
|
||||
flatten=flatten,
|
||||
fullpath=fullpath,
|
||||
withoption=withoption,
|
||||
withvalue=withvalue)
|
||||
|
||||
|
||||
class TiramisuDispatcher:
|
||||
pass
|
||||
|
Reference in New Issue
Block a user