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