remove extra _get_option
This commit is contained in:
parent
81666b6303
commit
a1cb60237a
1 changed files with 45 additions and 47 deletions
|
@ -146,11 +146,12 @@ class CommonTiramisuOption(CommonTiramisu):
|
|||
self.option_bag = option_bag
|
||||
self._name = name
|
||||
self.subconfig = subconfig
|
||||
self._get_option()
|
||||
if config_bag is not None and self.slave_need_index:
|
||||
self._test_slave_index()
|
||||
|
||||
def _test_slave_index(self) -> None:
|
||||
option = self._get_option()
|
||||
option = self.option_bag.option
|
||||
if not option.impl_is_optiondescription():
|
||||
if self.index is None and option.impl_is_master_slaves('slave'):
|
||||
raise APIError('index must be set with a slave option')
|
||||
|
@ -171,86 +172,88 @@ class TiramisuOptionOption(CommonTiramisuOption):
|
|||
|
||||
def get(self):
|
||||
"""get Tiramisu option"""
|
||||
return self._get_option()
|
||||
return self.option_bag.option
|
||||
|
||||
def _ismulti(self):
|
||||
"""test if option could have multi value"""
|
||||
option = self._get_option()
|
||||
option = self.option_bag.option
|
||||
return option.impl_is_multi()
|
||||
|
||||
def _issubmulti(self):
|
||||
"""test if option could have submulti value"""
|
||||
option = self._get_option()
|
||||
option = self.option_bag.option
|
||||
return option.impl_is_submulti()
|
||||
|
||||
def ismasterslaves(self):
|
||||
"""test if option is a master or a slave"""
|
||||
option = self._get_option()
|
||||
option = self.option_bag.option
|
||||
return option.impl_is_master_slaves()
|
||||
|
||||
def _ismaster(self):
|
||||
"""test if option is a master"""
|
||||
option = self._get_option()
|
||||
option = self.option_bag.option
|
||||
return option.impl_is_master_slaves('master')
|
||||
|
||||
def _isslave(self):
|
||||
"""test if option is a slave"""
|
||||
option = self._get_option()
|
||||
option = self.option_bag.option
|
||||
return option.impl_is_master_slaves('slave')
|
||||
|
||||
def doc(self):
|
||||
"""get option document"""
|
||||
option = self._get_option()
|
||||
option = self.option_bag.option
|
||||
return option.impl_get_display_name()
|
||||
|
||||
def name(self):
|
||||
"""get option name"""
|
||||
self._get_option()
|
||||
option = self.option_bag.option
|
||||
return self._name
|
||||
|
||||
def path(self) -> str:
|
||||
"""get option path"""
|
||||
self._get_option()
|
||||
option = self.option_bag.option
|
||||
return self._path
|
||||
|
||||
def _default(self):
|
||||
"""get default value for an option (not for optiondescription)"""
|
||||
option = self._get_option()
|
||||
option = self.option_bag.option
|
||||
return option.impl_getdefault()
|
||||
|
||||
def _defaultmulti(self):
|
||||
"""get default value when added a value for a multi option (not for optiondescription)"""
|
||||
option = self._get_option()
|
||||
option = self.option_bag.option
|
||||
return option.impl_getdefault_multi()
|
||||
|
||||
def has_dependency(self, self_is_dep=True):
|
||||
"""test if option has dependency"""
|
||||
option = self._get_option()
|
||||
option = self.option_bag.option
|
||||
return option.impl_has_dependency(self_is_dep)
|
||||
|
||||
def _consistencies(self):
|
||||
"""get consistencies for an option (not for optiondescription)"""
|
||||
option = self._get_option()
|
||||
option = self.option_bag.option
|
||||
return option.get_consistencies()
|
||||
|
||||
def _callbacks(self):
|
||||
"""get callbacks for an option (not for optiondescription)"""
|
||||
option = self._get_option()
|
||||
option = self.option_bag.option
|
||||
return option.impl_get_callback()
|
||||
|
||||
def requires(self):
|
||||
"""get requires for an option"""
|
||||
option = self._get_option()
|
||||
option = self.option_bag.option
|
||||
return option.impl_getrequires()
|
||||
|
||||
def __getattr__(self, name: str) -> Callable:
|
||||
if not self._get_option().impl_is_optiondescription():
|
||||
option = self.option_bag.option
|
||||
if not option.impl_is_optiondescription():
|
||||
return getattr(self, '_' + name)
|
||||
raise APIError(_('{} is unknown').format(name))
|
||||
|
||||
def isoptiondescription(self):
|
||||
"""test if option is an optiondescription"""
|
||||
return self._get_option().impl_is_optiondescription()
|
||||
option = self.option_bag.option
|
||||
return option.impl_is_optiondescription()
|
||||
|
||||
|
||||
class TiramisuOptionOwner(CommonTiramisuOption):
|
||||
|
@ -275,20 +278,17 @@ class TiramisuOptionOwner(CommonTiramisuOption):
|
|||
|
||||
def get(self):
|
||||
"""get owner for a specified option"""
|
||||
option = self._get_option()
|
||||
option = self.option_bag.option
|
||||
return self.values.getowner(self.option_bag)
|
||||
|
||||
def isdefault(self):
|
||||
"""is option has defaut value"""
|
||||
self._get_option()
|
||||
option = self.option_bag.option
|
||||
return self.values.is_default_owner(self.option_bag)
|
||||
|
||||
def set(self, owner):
|
||||
"""get owner for a specified option"""
|
||||
self._get_option()
|
||||
if TIRAMISU_VERSION == 2:
|
||||
if owner in ['default', 'forced', 'meta']:
|
||||
raise ConfigError()
|
||||
option = self.option_bag.option
|
||||
try:
|
||||
obj_owner = getattr(owners, owner)
|
||||
except AttributeError:
|
||||
|
@ -321,7 +321,7 @@ class TiramisuOptionProperty(CommonTiramisuOption):
|
|||
|
||||
def get(self, apply_requires=True):
|
||||
"""get properties for an option"""
|
||||
self._get_option()
|
||||
option = self.option_bag.option
|
||||
if apply_requires:
|
||||
self._test_slave_index()
|
||||
else:
|
||||
|
@ -331,7 +331,7 @@ class TiramisuOptionProperty(CommonTiramisuOption):
|
|||
|
||||
def add(self, prop):
|
||||
"""add new property for an option"""
|
||||
self._get_option()
|
||||
option = self.option_bag.option
|
||||
if prop in FORBIDDEN_SET_PROPERTIES:
|
||||
raise ConfigError(_('cannot add this property: "{0}"').format(
|
||||
' '.join(prop)))
|
||||
|
@ -343,7 +343,7 @@ class TiramisuOptionProperty(CommonTiramisuOption):
|
|||
|
||||
def pop(self, prop):
|
||||
"""remove new property for an option"""
|
||||
self._get_option()
|
||||
option = self.option_bag.option
|
||||
props = self.settings.getproperties(self.option_bag,
|
||||
apply_requires=False)
|
||||
self.settings.setproperties(self._path,
|
||||
|
@ -352,7 +352,7 @@ class TiramisuOptionProperty(CommonTiramisuOption):
|
|||
|
||||
def reset(self):
|
||||
"""reset all personalised properties"""
|
||||
self._get_option()
|
||||
option = self.option_bag.option
|
||||
self.settings.reset(self.option_bag)
|
||||
|
||||
|
||||
|
@ -379,15 +379,12 @@ class TiramisuOptionPermissive(CommonTiramisuOption):
|
|||
|
||||
def get(self):
|
||||
"""get permissives value"""
|
||||
if TIRAMISU_VERSION == 2:
|
||||
args = [self.setting_properties, self._path]
|
||||
else:
|
||||
args = [self._get_option(), self._path]
|
||||
return self.settings.getpermissive(*args)
|
||||
option = self.option_bag.option
|
||||
return self.settings.getpermissive(option, self._path)
|
||||
|
||||
def set(self, permissives):
|
||||
"""set permissives value"""
|
||||
self._get_option()
|
||||
option = self.option_bag.option
|
||||
self.settings.setpermissive(self.option_bag,
|
||||
permissives=permissives)
|
||||
|
||||
|
@ -403,15 +400,17 @@ class TiramisuOptionInformation(CommonTiramisuOption):
|
|||
|
||||
def get(self, name, default=undefined):
|
||||
"""get information for a key name"""
|
||||
option = self._get_option()
|
||||
option = self.option_bag.option
|
||||
return option.impl_get_information(name, default)
|
||||
|
||||
def set(self, name, value):
|
||||
"""set information for a key name"""
|
||||
#FIXME ?
|
||||
self.config_bag.context.impl_set_information(name, value)
|
||||
|
||||
def reset(self, name):
|
||||
"""remove information for a key name"""
|
||||
#FIXME ?
|
||||
self.config_bag.context.impl_del_information(name)
|
||||
|
||||
|
||||
|
@ -421,14 +420,14 @@ class TiramisuOptionValue(CommonTiramisuOption):
|
|||
|
||||
def get(self):
|
||||
"""get option's value"""
|
||||
self._get_option()
|
||||
option = self.option_bag.option
|
||||
self._test_slave_index()
|
||||
return self.subconfig.getattr(self._name,
|
||||
self.option_bag)
|
||||
|
||||
def set(self, value):
|
||||
"""set a value for a specified option"""
|
||||
self._get_option()
|
||||
option = self.option_bag.option
|
||||
self._test_slave_index()
|
||||
values = self.config_bag.context.cfgimpl_get_values()
|
||||
if isinstance(value, list):
|
||||
|
@ -448,7 +447,6 @@ class TiramisuOptionValue(CommonTiramisuOption):
|
|||
|
||||
def _pop(self, index):
|
||||
"""pop value for a master option (only for master option)"""
|
||||
self._get_option()
|
||||
if self.option_bag.option.impl_is_symlinkoption():
|
||||
raise TypeError(_("can't delete a SymLinkOption"))
|
||||
self.config_bag.context.cfgimpl_get_values().reset_master(index,
|
||||
|
@ -457,13 +455,12 @@ class TiramisuOptionValue(CommonTiramisuOption):
|
|||
|
||||
def reset(self):
|
||||
"""reset value for a value"""
|
||||
self._get_option()
|
||||
self._test_slave_index()
|
||||
self.subconfig.delattr(self.option_bag)
|
||||
|
||||
def _len_master(self):
|
||||
"""length of master option (only for slave option)"""
|
||||
option = self._get_option()
|
||||
option = self.option_bag.option
|
||||
# for example if index is None
|
||||
if '_length' not in vars(self):
|
||||
self._length = self.subconfig.cfgimpl_get_length()
|
||||
|
@ -471,28 +468,29 @@ class TiramisuOptionValue(CommonTiramisuOption):
|
|||
|
||||
def _len_slave(self):
|
||||
"""length of slave option (only for slave option)"""
|
||||
option = self._get_option()
|
||||
option = self.option_bag.option
|
||||
# for example if index is None
|
||||
if '_length' not in vars(self):
|
||||
self._length = self.subconfig.cfgimpl_get_length_slave(self.option_bag)
|
||||
return self._length
|
||||
|
||||
def __getattr__(self, name: str) -> Callable:
|
||||
if name == 'list' and isinstance(self._get_option(), ChoiceOption):
|
||||
option = self.option_bag.option
|
||||
if name == 'list' and isinstance(option, ChoiceOption):
|
||||
return self._list
|
||||
elif name == 'pop' and self._get_option().impl_is_master_slaves('master'):
|
||||
elif name == 'pop' and option.impl_is_master_slaves('master'):
|
||||
return self._pop
|
||||
elif name == 'len':
|
||||
if self._get_option().impl_is_master_slaves('slave'):
|
||||
if option.impl_is_master_slaves('slave'):
|
||||
return self._len_slave
|
||||
if self._get_option().impl_is_master_slaves('master'):
|
||||
if option.impl_is_master_slaves('master'):
|
||||
return self._len_master
|
||||
raise APIError(_('{} is unknown').format(name))
|
||||
|
||||
def _list(self):
|
||||
"""all values available for an option (only for choiceoption)"""
|
||||
self._get_option()
|
||||
return self._get_option().impl_get_values(self.option_bag)
|
||||
option = self.option_bag.option
|
||||
return option.impl_get_values(self.option_bag)
|
||||
|
||||
|
||||
def registers(registers: Dict[str, type], prefix: str) -> None:
|
||||
|
|
Loading…
Reference in a new issue