simplify api
This commit is contained in:
parent
a1cb60237a
commit
fdbb0d83ff
1 changed files with 29 additions and 55 deletions
|
@ -109,19 +109,20 @@ class CommonTiramisu(TiramisuHelp):
|
||||||
option = self.option_bag.option
|
option = self.option_bag.option
|
||||||
if option is None:
|
if option is None:
|
||||||
option = self.subconfig.cfgimpl_get_description().impl_getchild(self._name,
|
option = self.subconfig.cfgimpl_get_description().impl_getchild(self._name,
|
||||||
self.config_bag,
|
self.option_bag.config_bag,
|
||||||
self.subconfig)
|
self.subconfig)
|
||||||
self.option_bag.set_option(option,
|
self.option_bag.set_option(option,
|
||||||
self._path,
|
self.option_bag.path,
|
||||||
self.index,
|
self.option_bag.index,
|
||||||
self.config_bag)
|
self.option_bag.config_bag)
|
||||||
if self.index is not None:
|
index = self.option_bag.index
|
||||||
|
if index is not None:
|
||||||
if option.impl_is_optiondescription() or not option.impl_is_master_slaves('slave'):
|
if option.impl_is_optiondescription() or not option.impl_is_master_slaves('slave'):
|
||||||
raise APIError('index must be set only with a slave option')
|
raise APIError('index must be set only with a slave option')
|
||||||
self._length = self.subconfig.cfgimpl_get_length_slave(self.option_bag)
|
self._length = self.subconfig.cfgimpl_get_length_slave(self.option_bag)
|
||||||
if self.index >= self._length:
|
if index >= self._length:
|
||||||
raise SlaveError(_('index "{}" is higher than the master length "{}" '
|
raise SlaveError(_('index "{}" is higher than the master length "{}" '
|
||||||
'for option "{}"').format(self.index,
|
'for option "{}"').format(index,
|
||||||
self._length,
|
self._length,
|
||||||
option.impl_get_display_name()))
|
option.impl_get_display_name()))
|
||||||
if not self.allow_optiondescription and option.impl_is_optiondescription():
|
if not self.allow_optiondescription and option.impl_is_optiondescription():
|
||||||
|
@ -135,27 +136,21 @@ class CommonTiramisuOption(CommonTiramisu):
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
name: str,
|
name: str,
|
||||||
path: str,
|
|
||||||
index: int,
|
|
||||||
subconfig: Union[Config, SubConfig],
|
subconfig: Union[Config, SubConfig],
|
||||||
config_bag: ConfigBag,
|
|
||||||
option_bag: OptionBag) -> None:
|
option_bag: OptionBag) -> None:
|
||||||
self._path = path
|
|
||||||
self.index = index
|
|
||||||
self.config_bag = config_bag
|
|
||||||
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()
|
self._get_option()
|
||||||
if config_bag is not None and self.slave_need_index:
|
if option_bag.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.option_bag.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.option_bag.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')
|
||||||
elif self.index is not None and not option.impl_is_master_slaves('slave'):
|
elif self.option_bag.index is not None and not option.impl_is_master_slaves('slave'):
|
||||||
raise APIError('index must be set only with a slave option')
|
raise APIError('index must be set only with a slave option')
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
|
@ -206,13 +201,11 @@ class TiramisuOptionOption(CommonTiramisuOption):
|
||||||
|
|
||||||
def name(self):
|
def name(self):
|
||||||
"""get option name"""
|
"""get option name"""
|
||||||
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"""
|
||||||
option = self.option_bag.option
|
return self.option_bag.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)"""
|
||||||
|
@ -246,7 +239,7 @@ class TiramisuOptionOption(CommonTiramisuOption):
|
||||||
|
|
||||||
def __getattr__(self, name: str) -> Callable:
|
def __getattr__(self, name: str) -> Callable:
|
||||||
option = self.option_bag.option
|
option = self.option_bag.option
|
||||||
if not option.impl_is_optiondescription():
|
if not option.impl_is_optiondescription() and not name.startswith('_'):
|
||||||
return getattr(self, '_' + name)
|
return getattr(self, '_' + name)
|
||||||
raise APIError(_('{} is unknown').format(name))
|
raise APIError(_('{} is unknown').format(name))
|
||||||
|
|
||||||
|
@ -261,20 +254,13 @@ class TiramisuOptionOwner(CommonTiramisuOption):
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
name: str,
|
name: str,
|
||||||
path: str,
|
|
||||||
index: int,
|
|
||||||
subconfig: Union[Config, SubConfig],
|
subconfig: Union[Config, SubConfig],
|
||||||
config_bag: ConfigBag,
|
|
||||||
option_bag: OptionBag) -> None:
|
option_bag: OptionBag) -> None:
|
||||||
|
|
||||||
super().__init__(name,
|
super().__init__(name,
|
||||||
path,
|
|
||||||
index,
|
|
||||||
subconfig,
|
subconfig,
|
||||||
config_bag,
|
|
||||||
option_bag)
|
option_bag)
|
||||||
if config_bag:
|
self.values = self.option_bag.config_bag.context.cfgimpl_get_values()
|
||||||
self.values = self.config_bag.context.cfgimpl_get_values()
|
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
"""get owner for a specified option"""
|
"""get owner for a specified option"""
|
||||||
|
@ -305,19 +291,13 @@ class TiramisuOptionProperty(CommonTiramisuOption):
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
name: str,
|
name: str,
|
||||||
path: str,
|
|
||||||
index: int,
|
|
||||||
subconfig: Union[Config, SubConfig],
|
subconfig: Union[Config, SubConfig],
|
||||||
config_bag: ConfigBag,
|
|
||||||
option_bag: OptionBag) -> None:
|
option_bag: OptionBag) -> None:
|
||||||
super().__init__(name,
|
super().__init__(name,
|
||||||
path,
|
|
||||||
index,
|
|
||||||
subconfig,
|
subconfig,
|
||||||
config_bag,
|
|
||||||
option_bag)
|
option_bag)
|
||||||
if config_bag:
|
if option_bag.config_bag:
|
||||||
self.settings = config_bag.context.cfgimpl_get_settings()
|
self.settings = option_bag.config_bag.context.cfgimpl_get_settings()
|
||||||
|
|
||||||
def get(self, apply_requires=True):
|
def get(self, apply_requires=True):
|
||||||
"""get properties for an option"""
|
"""get properties for an option"""
|
||||||
|
@ -337,7 +317,7 @@ class TiramisuOptionProperty(CommonTiramisuOption):
|
||||||
' '.join(prop)))
|
' '.join(prop)))
|
||||||
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.option_bag.path,
|
||||||
props | {prop},
|
props | {prop},
|
||||||
self.option_bag)
|
self.option_bag)
|
||||||
|
|
||||||
|
@ -346,7 +326,7 @@ class TiramisuOptionProperty(CommonTiramisuOption):
|
||||||
option = self.option_bag.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.option_bag.path,
|
||||||
props - {prop},
|
props - {prop},
|
||||||
self.option_bag)
|
self.option_bag)
|
||||||
|
|
||||||
|
@ -363,24 +343,18 @@ class TiramisuOptionPermissive(CommonTiramisuOption):
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
name: str,
|
name: str,
|
||||||
path: str,
|
|
||||||
index: int,
|
|
||||||
subconfig: Union[Config, SubConfig],
|
subconfig: Union[Config, SubConfig],
|
||||||
config_bag: ConfigBag,
|
|
||||||
option_bag: OptionBag) -> None:
|
option_bag: OptionBag) -> None:
|
||||||
super().__init__(name,
|
super().__init__(name,
|
||||||
path,
|
|
||||||
index,
|
|
||||||
subconfig,
|
subconfig,
|
||||||
config_bag,
|
|
||||||
option_bag)
|
option_bag)
|
||||||
if config_bag:
|
if option_bag.config_bag:
|
||||||
self.settings = config_bag.context.cfgimpl_get_settings()
|
self.settings = option_bag.config_bag.context.cfgimpl_get_settings()
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
"""get permissives value"""
|
"""get permissives value"""
|
||||||
option = self.option_bag.option
|
option = self.option_bag.option
|
||||||
return self.settings.getpermissive(option, self._path)
|
return self.settings.getpermissive(option, self.option_bag.path)
|
||||||
|
|
||||||
def set(self, permissives):
|
def set(self, permissives):
|
||||||
"""set permissives value"""
|
"""set permissives value"""
|
||||||
|
@ -429,7 +403,7 @@ class TiramisuOptionValue(CommonTiramisuOption):
|
||||||
"""set a value for a specified option"""
|
"""set a value for a specified option"""
|
||||||
option = self.option_bag.option
|
option = self.option_bag.option
|
||||||
self._test_slave_index()
|
self._test_slave_index()
|
||||||
values = self.config_bag.context.cfgimpl_get_values()
|
values = self.option_bag.config_bag.context.cfgimpl_get_values()
|
||||||
if isinstance(value, list):
|
if isinstance(value, list):
|
||||||
while undefined in value:
|
while undefined in value:
|
||||||
idx = value.index(undefined)
|
idx = value.index(undefined)
|
||||||
|
@ -437,7 +411,7 @@ class TiramisuOptionValue(CommonTiramisuOption):
|
||||||
option_bag.set_option(self.option_bag.option,
|
option_bag.set_option(self.option_bag.option,
|
||||||
self.option_bag.path,
|
self.option_bag.path,
|
||||||
idx,
|
idx,
|
||||||
self.config_bag)
|
self.option_bag.config_bag)
|
||||||
value[idx] = values.getdefaultvalue(option_bag)
|
value[idx] = values.getdefaultvalue(option_bag)
|
||||||
else:
|
else:
|
||||||
if value == undefined:
|
if value == undefined:
|
||||||
|
@ -449,9 +423,9 @@ class TiramisuOptionValue(CommonTiramisuOption):
|
||||||
"""pop value for a master option (only for master option)"""
|
"""pop value for a master option (only for master 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.option_bag.config_bag.context.cfgimpl_get_values().reset_master(index,
|
||||||
self.option_bag,
|
self.option_bag,
|
||||||
self.subconfig)
|
self.subconfig)
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
"""reset value for a value"""
|
"""reset value for a value"""
|
||||||
|
@ -519,16 +493,16 @@ class TiramisuOption(CommonTiramisu):
|
||||||
self.option_bag = option_bag
|
self.option_bag = option_bag
|
||||||
else:
|
else:
|
||||||
self.option_bag = OptionBag()
|
self.option_bag = OptionBag()
|
||||||
|
self.option_bag.path = self._path
|
||||||
|
self.option_bag.index = self.index
|
||||||
|
self.option_bag.config_bag = self.config_bag
|
||||||
if not self.registers:
|
if not self.registers:
|
||||||
registers(self.registers, self.__class__.__name__)
|
registers(self.registers, self.__class__.__name__)
|
||||||
|
|
||||||
def __getattr__(self, subfunc: str) -> Any:
|
def __getattr__(self, subfunc: str) -> Any:
|
||||||
if subfunc in self.registers:
|
if subfunc in self.registers:
|
||||||
return self.registers[subfunc](self._name,
|
return self.registers[subfunc](self._name,
|
||||||
self._path,
|
|
||||||
self.index,
|
|
||||||
self.subconfig,
|
self.subconfig,
|
||||||
self.config_bag,
|
|
||||||
self.option_bag)
|
self.option_bag)
|
||||||
elif self._get_option().impl_is_optiondescription():
|
elif self._get_option().impl_is_optiondescription():
|
||||||
return getattr(self, '_' + subfunc)
|
return getattr(self, '_' + subfunc)
|
||||||
|
|
Loading…
Reference in a new issue