提交 414e5391 编写于 作者: L Lukáš Doktor

tree: Wrap environment into custom container

The node environment is about to be expanded, let's wrap the values into
a custom object to contain all the necessary information and allow easy
extensibility.
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 e2dae9ed
......@@ -172,7 +172,7 @@ class MuxPlugin(object):
env = set()
for node in variant["variant"]:
for key, value in node.environment.iteritems():
origin = node.environment_origin[key].path
origin = node.environment.origin[key].path
env.add(("%s:%s" % (origin, key), str(value)))
if not env:
continue
......
......@@ -41,6 +41,21 @@ import os
from . import output
class TreeEnvironment(dict):
""" TreeNode environment with values, origins and filters """
def __init__(self):
super(TreeEnvironment, self).__init__() # values
self.origin = {} # origins of the values
def copy(self):
cpy = TreeEnvironment()
cpy.update(self)
cpy.origin = self.origin.copy()
return cpy
class TreeNode(object):
"""
......@@ -57,7 +72,6 @@ class TreeNode(object):
self.parent = parent
self.children = []
self._environment = None
self.environment_origin = {}
for child in children:
self.add_child(child)
......@@ -175,9 +189,7 @@ class TreeNode(object):
""" Get node environment (values + preceding envs) """
if self._environment is None:
self._environment = (self.parent.environment.copy()
if self.parent else {})
self.environment_origin = (self.parent.environment_origin.copy()
if self.parent else {})
if self.parent else TreeEnvironment())
for key, value in self.value.iteritems():
if isinstance(value, list):
if (key in self._environment and
......@@ -187,7 +199,7 @@ class TreeNode(object):
self._environment[key] = value
else:
self._environment[key] = value
self.environment_origin[key] = self
self._environment.origin[key] = self
return self._environment
def set_environment_dirty(self):
......
......@@ -289,7 +289,7 @@ class AvocadoParam(object):
:raise KeyError: When value is not certain (multiple matches)
"""
leaves = self._get_leaves(path)
ret = [(leaf.environment[key], leaf.environment_origin[key])
ret = [(leaf.environment[key], leaf.environment.origin[key])
for leaf in leaves
if key in leaf.environment]
if not ret:
......@@ -310,7 +310,7 @@ class AvocadoParam(object):
"""
for leaf in self._leaves:
for key, value in leaf.environment.iteritems():
yield (leaf.environment_origin[key].path, key, value)
yield (leaf.environment.origin[key].path, key, value)
class Varianter(object):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册