Commit cbcdea71 authored by Sebastien Petitdemange's avatar Sebastien Petitdemange
Browse files

config: clean find_class.

Now you can define class and package for several objects.
parent 85dd8d34
Pipeline #7539 passed with stages
in 19 minutes and 54 seconds
......@@ -7,14 +7,14 @@
def find_class(cfg_node, base_path="bliss.controllers"):
klass_name = cfg_node.get_inherited("class")
klass_name, node = cfg_node.get_inherited_value_and_node("class")
if klass_name is None:
raise KeyError("class")
if "package" in cfg_node:
module_name = cfg_node["package"]
elif "module" in cfg_node:
module_name = "%s.%s" % (base_path, cfg_node["module"])
if "package" in node:
module_name = node["package"]
elif "module" in node:
module_name = "%s.%s" % (base_path, node["module"])
else:
# discover module and class name
module_name = "%s.%s" % (base_path, klass_name.lower())
......
......@@ -263,6 +263,15 @@ class Node(NodeDict):
else:
return None, None
def get_inherited_value_and_node(self, key):
"""
@see get_inherited
"""
value = self.get(key)
if value is None and self._parent:
return self._parent.get_inherited_value_and_node(key)
return value, self
def get_inherited(self, key):
"""
Returns the value for the given config key. If the key does not exist
......@@ -276,10 +285,7 @@ class Node(NodeDict):
object: value corresponding to the key or None if key is not found
in the Node tree
"""
value = self.get(key)
if value is None and self._parent:
return self._parent.get_inherited(key)
return value
return self.get_inherited_value_and_node(key)[0]
def pprint(self, indent=1, depth=None):
"""
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment