api: add function path() to get path of an option

This commit is contained in:
Emmanuel Garette 2018-04-11 07:53:11 +02:00
parent 54cb73c2cc
commit a1bb6370ca
1 changed files with 31 additions and 26 deletions

View File

@ -162,7 +162,7 @@ class CommonTiramisu(TiramisuHelp):
self.subconfig) self.subconfig)
self.config_bag.option = option self.config_bag.option = option
if self.config_bag.setting_properties: if self.config_bag.setting_properties:
self.config_bag.config.cfgimpl_get_settings().validate_properties(self.path, self.config_bag.config.cfgimpl_get_settings().validate_properties(self._path,
self.index, self.index,
self.config_bag) self.config_bag)
if self.index is not None: if self.index is not None:
@ -188,7 +188,7 @@ class CommonTiramisuOption(CommonTiramisu):
index=None, index=None,
subconfig=None, subconfig=None,
config_bag=None): config_bag=None):
self.path = path self._path = path
self.index = index self.index = index
self.config_bag = config_bag self.config_bag = config_bag
self._name = name self._name = name
@ -263,6 +263,11 @@ class TiramisuOptionOption(CommonTiramisuOption):
self._get_option() self._get_option()
return self._name return self._name
def path(self):
"""get option path"""
self._get_option()
return self._path
@count @count
def _default(self): def _default(self):
"""get default value for an option (not for optiondescription)""" """get default value for an option (not for optiondescription)"""
@ -335,7 +340,7 @@ 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._get_option()
return self.values.getowner(self.path, return self.values.getowner(self._path,
self.index, self.index,
self.config_bag) self.config_bag)
@ -343,7 +348,7 @@ class TiramisuOptionOwner(CommonTiramisuOption):
def isdefault(self): def isdefault(self):
"""is option has defaut value""" """is option has defaut value"""
self._get_option() self._get_option()
return self.values.is_default_owner(self.path, return self.values.is_default_owner(self._path,
self.index, self.index,
self.config_bag) self.config_bag)
@ -359,7 +364,7 @@ class TiramisuOptionOwner(CommonTiramisuOption):
except AttributeError: except AttributeError:
owners.addowner(owner) owners.addowner(owner)
obj_owner = getattr(owners, owner) obj_owner = getattr(owners, owner)
self.values.setowner(self.path, self.values.setowner(self._path,
self.index, self.index,
obj_owner, obj_owner,
self.config_bag) self.config_bag)
@ -390,7 +395,7 @@ class TiramisuOptionProperty(CommonTiramisuOption):
self._get_option() self._get_option()
if apply_requires: if apply_requires:
self._test_slave_index() self._test_slave_index()
properties = self.settings.getproperties(self.path, properties = self.settings.getproperties(self._path,
self.index, self.index,
self.config_bag, self.config_bag,
apply_requires) apply_requires)
@ -405,11 +410,11 @@ class TiramisuOptionProperty(CommonTiramisuOption):
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)))
props = self.settings.getproperties(self.path, props = self.settings.getproperties(self._path,
None, None,
self.config_bag, self.config_bag,
apply_requires=False) apply_requires=False)
self.settings.setproperties(self.path, self.settings.setproperties(self._path,
props | {prop}, props | {prop},
self.config_bag) self.config_bag)
@ -417,11 +422,11 @@ 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() self._get_option()
props = self.settings.getproperties(self.path, props = self.settings.getproperties(self._path,
self.index, self.index,
self.config_bag, self.config_bag,
apply_requires=False) apply_requires=False)
self.settings.setproperties(self.path, self.settings.setproperties(self._path,
props - {prop}, props - {prop},
self.config_bag) self.config_bag)
@ -430,7 +435,7 @@ class TiramisuOptionProperty(CommonTiramisuOption):
"""reset all personalised properties""" """reset all personalised properties"""
self._get_option() self._get_option()
self.settings.reset(self.config_bag.option, self.settings.reset(self.config_bag.option,
self.path, self._path,
self.config_bag) self.config_bag)
@ -459,7 +464,7 @@ class TiramisuOptionPermissive(CommonTiramisuOption):
if TIRAMISU_VERSION == 2: if TIRAMISU_VERSION == 2:
args = [self.setting_properties, self._path] args = [self.setting_properties, self._path]
else: else:
args = [self._get_option(), self.path] args = [self._get_option(), self._path]
return self.settings.getpermissive(*args) return self.settings.getpermissive(*args)
@count @count
@ -474,7 +479,7 @@ class TiramisuOptionPermissive(CommonTiramisuOption):
config_bag=self.config_bag, config_bag=self.config_bag,
permissive=permissives) permissive=permissives)
else: else:
path = self.path path = self._path
opt = self._get_option() opt = self._get_option()
self.settings.setpermissive(opt=opt, self.settings.setpermissive(opt=opt,
path=path, path=path,
@ -535,12 +540,12 @@ class TiramisuOptionValue(CommonTiramisuOption):
if isinstance(value, list): if isinstance(value, list):
while undefined in value: while undefined in value:
idx = value.index(undefined) idx = value.index(undefined)
value[idx] = values.getdefaultvalue(self.path, value[idx] = values.getdefaultvalue(self._path,
idx, idx,
self.config_bag) self.config_bag)
else: else:
if value == undefined: if value == undefined:
value = values.getdefaultvalue(self.path, value = values.getdefaultvalue(self._path,
self.index, self.index,
self.config_bag) self.config_bag)
self.subconfig.setattr(self._name, self.subconfig.setattr(self._name,
@ -552,7 +557,7 @@ 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() self._get_option()
self.config_bag.config.delattr(self.path, self.config_bag.config.delattr(self._path,
index, index,
self.config_bag) self.config_bag)
@ -561,7 +566,7 @@ class TiramisuOptionValue(CommonTiramisuOption):
"""reset value for a value""" """reset value for a value"""
self._get_option() self._get_option()
self._test_slave_index() self._test_slave_index()
self.config_bag.config.delattr(self.path, self.config_bag.config.delattr(self._path,
self.index, self.index,
self.config_bag) self.config_bag)
@ -569,9 +574,9 @@ class TiramisuOptionValue(CommonTiramisuOption):
def _len(self): def _len(self):
"""length of slave option (only for slave option)""" """length of slave option (only for slave option)"""
self._get_option() self._get_option()
subconfig_path = self.path.rsplit('.', 1)[0] subconfig_path = self._path.rsplit('.', 1)[0]
if self.config_bag.setting_properties is not None: if self.config_bag.setting_properties is not None:
self.config_bag.config.cfgimpl_get_settings().validate_properties(self.path, self.config_bag.config.cfgimpl_get_settings().validate_properties(self._path,
self.index, self.index,
self.config_bag) self.config_bag)
config_bag = self.config_bag.copy('nooption') config_bag = self.config_bag.copy('nooption')
@ -613,7 +618,7 @@ class TiramisuOption(CommonTiramisu):
self._name = name self._name = name
self.subconfig = subconfig self.subconfig = subconfig
self.path = path self._path = path
self.index = index self.index = index
self.config_bag = config_bag self.config_bag = config_bag
self.registers = {} self.registers = {}
@ -622,7 +627,7 @@ class TiramisuOption(CommonTiramisu):
def __getattr__(self, subfunc): def __getattr__(self, subfunc):
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._path,
self.index, self.index,
self.subconfig, self.subconfig,
self.config_bag) self.config_bag)
@ -644,7 +649,7 @@ class TiramisuOption(CommonTiramisu):
withoption=None, withoption=None,
fullpath=False): fullpath=False):
"""return dict with path as key and value for an optiondescription (only for optiondescription)""" """return dict with path as key and value for an optiondescription (only for optiondescription)"""
return self.config_bag.config.getattr(self.path, return self.config_bag.config.getattr(self._path,
None, None,
self.config_bag).make_dict(config_bag=self.config_bag, self.config_bag).make_dict(config_bag=self.config_bag,
flatten=flatten, flatten=flatten,
@ -662,7 +667,7 @@ class TiramisuOption(CommonTiramisu):
for path in self.config_bag.config.find(byname=name, for path in self.config_bag.config.find(byname=name,
byvalue=value, byvalue=value,
bytype=None, bytype=None,
_subpath=self.path, _subpath=self._path,
config_bag=self.config_bag): config_bag=self.config_bag):
config_bag = self.config_bag.copy('nooption') config_bag = self.config_bag.copy('nooption')
subconfig, name = config_bag.config.cfgimpl_get_home_by_path(path, subconfig, name = config_bag.config.cfgimpl_get_home_by_path(path,
@ -688,12 +693,12 @@ class TiramisuOption(CommonTiramisu):
group_type=None): group_type=None):
"""list options in an optiondescription (only for optiondescription)""" """list options in an optiondescription (only for optiondescription)"""
if type == 'optiondescription': if type == 'optiondescription':
return self.config_bag.config.getattr(self.path, return self.config_bag.config.getattr(self._path,
None, None,
self.config_bag self.config_bag
).iter_groups(self.config_bag, group_type) ).iter_groups(self.config_bag, group_type)
elif type == 'all': elif type == 'all':
return self.config_bag.config.getattr(self.path, return self.config_bag.config.getattr(self._path,
None, None,
self.config_bag self.config_bag
).cfgimpl_get_children(self.config_bag) ).cfgimpl_get_children(self.config_bag)
@ -899,7 +904,7 @@ class TiramisuContextOption(TiramisuContext):
for path in self.config_bag.config.find(byname=name, for path in self.config_bag.config.find(byname=name,
byvalue=value, byvalue=value,
bytype=None, bytype=None,
#_subpath=self.path, #_subpath=self._path,
config_bag=self.config_bag): config_bag=self.config_bag):
config_bag = self.config_bag.copy('nooption') config_bag = self.config_bag.copy('nooption')
subconfig, name = config_bag.config.cfgimpl_get_home_by_path(path, subconfig, name = config_bag.config.cfgimpl_get_home_by_path(path,