get_home_by_path is a public method

This commit is contained in:
Emmanuel Garette 2013-03-14 16:07:26 +01:00
parent 15beeda0f0
commit 9e81ae4737
2 changed files with 7 additions and 7 deletions

View File

@ -154,7 +154,7 @@ class Config(object):
self.__dict__[name] = value self.__dict__[name] = value
return return
if '.' in name: if '.' in name:
homeconfig, name = self._cfgimpl_get_home_by_path(name) homeconfig, name = self.cfgimpl_get_home_by_path(name)
return setattr(homeconfig, name, value) return setattr(homeconfig, name, value)
if type(getattr(self._cfgimpl_descr, name)) != SymLinkOption: if type(getattr(self._cfgimpl_descr, name)) != SymLinkOption:
self._validate(name, getattr(self._cfgimpl_descr, name)) self._validate(name, getattr(self._cfgimpl_descr, name))
@ -206,7 +206,7 @@ class Config(object):
# attribute access by passing a path, # attribute access by passing a path,
# for instance getattr(self, "creole.general.family.adresse_ip_eth0") # for instance getattr(self, "creole.general.family.adresse_ip_eth0")
if '.' in name: if '.' in name:
homeconfig, name = self._cfgimpl_get_home_by_path(name) homeconfig, name = self.cfgimpl_get_home_by_path(name)
return homeconfig._getattr(name, permissive) return homeconfig._getattr(name, permissive)
opt_or_descr = getattr(self._cfgimpl_descr, name) opt_or_descr = getattr(self._cfgimpl_descr, name)
# symlink options # symlink options
@ -248,7 +248,7 @@ class Config(object):
:returns: Option() :returns: Option()
""" """
if '.' in path: if '.' in path:
homeconfig, path = self._cfgimpl_get_home_by_path(path) homeconfig, path = self.cfgimpl_get_home_by_path(path)
return getattr(homeconfig._cfgimpl_descr, path) return getattr(homeconfig._cfgimpl_descr, path)
return getattr(self._cfgimpl_descr, path) return getattr(self._cfgimpl_descr, path)
@ -273,7 +273,7 @@ class Config(object):
candidates = [p for p in all_paths if p[-len(key_p):] == key_p] candidates = [p for p in all_paths if p[-len(key_p):] == key_p]
if len(candidates) == 1: if len(candidates) == 1:
name = '.'.join(candidates[0]) name = '.'.join(candidates[0])
homeconfig, name = self._cfgimpl_get_home_by_path(name) homeconfig, name = self.cfgimpl_get_home_by_path(name)
try: try:
getattr(homeconfig, name) getattr(homeconfig, name)
except MandatoryError: except MandatoryError:
@ -313,7 +313,7 @@ class Config(object):
raise e raise e
raise NotFoundError("option {0} not found in config".format(name)) raise NotFoundError("option {0} not found in config".format(name))
def _cfgimpl_get_home_by_path(self, path): def cfgimpl_get_home_by_path(self, path):
""":returns: tuple (config, name)""" """:returns: tuple (config, name)"""
path = path.split('.') path = path.split('.')
for step in path[:-1]: for step in path[:-1]:
@ -337,7 +337,7 @@ class Config(object):
# ______________________________________________________________________ # ______________________________________________________________________
# def cfgimpl_previous_value(self, path): # def cfgimpl_previous_value(self, path):
# "stores the previous value" # "stores the previous value"
# home, name = self._cfgimpl_get_home_by_path(path) # home, name = self.cfgimpl_get_home_by_path(path)
# # FIXME fucking name # # FIXME fucking name
# return home._cfgimpl_context._cfgimpl_values.previous_values[name] # return home._cfgimpl_context._cfgimpl_values.previous_values[name]

View File

@ -578,7 +578,7 @@ def apply_requires(opt, config, permissive=False):
raise RequirementRecursionError("malformed requirements " raise RequirementRecursionError("malformed requirements "
"imbrication detected for option: '{0}' " "imbrication detected for option: '{0}' "
"with requirement on: '{1}'".format(path, name)) "with requirement on: '{1}'".format(path, name))
homeconfig, shortname = rootconfig._cfgimpl_get_home_by_path(name) homeconfig, shortname = rootconfig.cfgimpl_get_home_by_path(name)
try: try:
value = homeconfig._getattr(shortname, permissive=True) value = homeconfig._getattr(shortname, permissive=True)
except PropertiesOptionError, err: except PropertiesOptionError, err: