本文整理汇总了Python中anytree.PreOrderIter方法的典型用法代码示例。如果您正苦于以下问题:Python anytree.PreOrderIter方法的具体用法?Python anytree.PreOrderIter怎么用?Python anytree.PreOrderIter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anytree
的用法示例。
在下文中一共展示了anytree.PreOrderIter方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_preorder
# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import PreOrderIter [as 别名]
def test_preorder():
"""PreOrderIter."""
f = Node("f")
b = Node("b", parent=f)
a = Node("a", parent=b)
d = Node("d", parent=b)
c = Node("c", parent=d)
e = Node("e", parent=d)
g = Node("g", parent=f)
i = Node("i", parent=g)
h = Node("h", parent=i)
eq_(list(PreOrderIter(f)), [f, b, a, d, c, e, g, i, h])
eq_(list(PreOrderIter(f, maxlevel=0)), [])
eq_(list(PreOrderIter(f, maxlevel=3)), [f, b, a, d, g, i])
eq_(list(PreOrderIter(f, filter_=lambda n: n.name not in ('e', 'g'))), [f, b, a, d, c, i, h])
eq_(list(PreOrderIter(f, stop=lambda n: n.name == 'd')), [f, b, a, g, i, h])
it = PreOrderIter(f)
eq_(next(it), f)
eq_(next(it), b)
eq_(list(it), [a, d, c, e, g, i, h])
示例2: setup
# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import PreOrderIter [as 别名]
def setup(self, tree=None):
""" Due to multiprocessing limitations, the setup is
run separately from the constructor
"""
diag_images = []
for node in PreOrderIter(self.root):
node.setup()
if node._params is not None:
self.all_params[node.strpath] = node._params
if tree is not None:
tree.add(node._params)
self.node_dict[node.strpath] = node
diag_images.extend(
(
node.strpath + "/" + imname
for imname in node.diagnostic_image_options
)
)
self.all_params["diagnostics"] = Parametrized(
name="tracking/diagnostics",
params=dict(image=Param("unprocessed", ["unprocessed"] + diag_images)),
tree=tree,
)
self.all_params["reset"] = Parametrized(
name="tracking/reset",
params=dict(reset=Param(False, gui="button")),
tree=tree,
)
示例3: __iter_nodes
# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import PreOrderIter [as 别名]
def __iter_nodes(self, indent, nodenamefunc, nodeattrfunc):
for node in PreOrderIter(self.node, maxlevel=self.maxlevel):
nodename = nodenamefunc(node)
nodeattr = nodeattrfunc(node)
nodeattr = " [%s]" % nodeattr if nodeattr is not None else ""
yield '%s"%s"%s;' % (indent, DotExporter.esc(nodename), nodeattr)
示例4: __iter_edges
# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import PreOrderIter [as 别名]
def __iter_edges(self, indent, nodenamefunc, edgeattrfunc, edgetypefunc):
maxlevel = self.maxlevel - 1 if self.maxlevel else None
for node in PreOrderIter(self.node, maxlevel=maxlevel):
nodename = nodenamefunc(node)
for child in node.children:
childname = nodenamefunc(child)
edgeattr = edgeattrfunc(node, child)
edgetype = edgetypefunc(node, child)
edgeattr = " [%s]" % edgeattr if edgeattr is not None else ""
yield '%s"%s" %s "%s"%s;' % (indent, DotExporter.esc(nodename), edgetype,
DotExporter.esc(childname), edgeattr)
示例5: test_pre_order_iter
# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import PreOrderIter [as 别名]
def test_pre_order_iter():
"""Pre-Order Iterator."""
f = Node("f")
b = Node("b", parent=f)
a = Node("a", parent=b)
d = Node("d", parent=b)
c = Node("c", parent=d)
e = Node("e", parent=d)
g = Node("g", parent=f)
i = Node("i", parent=g)
h = Node("h", parent=i)
result = [node.name for node in PreOrderIter(f)]
expected = ['f', 'b', 'a', 'd', 'c', 'e', 'g', 'i', 'h']
eq_(result, expected)
示例6: clean_not_flagged
# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import PreOrderIter [as 别名]
def clean_not_flagged(self, top):
'''remove any node not flagged and clean flags'''
cnt = 0
for node in anytree.PreOrderIter(top):
if node.type != self.TYPE_FILE and node.type != self.TYPE_DIR:
continue
if self._clean(node):
cnt += 1
return cnt
示例7: get_build_tree
# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import PreOrderIter [as 别名]
def get_build_tree(buildconfigs):
"""
Analyze build configurations to find which builds are 'linked'.
Linked builds are those which output to an ImageStream that another BuildConfig then
uses as its 'from' image.
Returns a list of lists where item 0 in each list is the parent build and the items following
it are all child build configs that will be fired at some point after the parent completes
"""
bcs_using_input_image = {}
bc_creating_output_image = {None: None}
node_for_bc = {}
for bc in buildconfigs:
bc_name = bc["metadata"]["name"]
node_for_bc[bc_name] = Node(bc_name)
# look up output image
if traverse_keys(bc, ["spec", "output", "to", "kind"], "").lower() == "imagestreamtag":
output_image = bc["spec"]["output"]["to"]["name"]
bc_creating_output_image[output_image] = bc_name
# look up input image
for trigger in traverse_keys(bc, ["spec", "triggers"], []):
if trigger.get("type", "").lower() == "imagechange":
input_image = get_input_image(bc, trigger)
if input_image not in bcs_using_input_image:
bcs_using_input_image[input_image] = []
bcs_using_input_image[input_image].append(bc_name)
# attach each build to its parent build
for input_image, bc_names in bcs_using_input_image.items():
for bc_name in bc_names:
parent_bc = bc_creating_output_image.get(input_image)
if parent_bc:
node_for_bc[bc_name].parent = node_for_bc[parent_bc]
rendered_trees = []
root_nodes = [n for _, n in node_for_bc.items() if n.is_root]
for root_node in root_nodes:
for pre, _, node in RenderTree(root_node):
rendered_trees.append(f" {pre}{node.name}")
if rendered_trees:
log.info("build config tree:\n\n%s", "\n".join(rendered_trees))
return [[node.name for node in PreOrderIter(root_node)] for root_node in root_nodes]
示例8: test_symlink
# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import PreOrderIter [as 别名]
def test_symlink():
root = Node("root")
s0 = Node("sub0", parent=root)
s0b = Node("sub0B", parent=s0)
s0a = Node("sub0A", parent=s0)
s1 = Node("sub1", parent=root, foo=4)
s1a = Node("sub1A", parent=s1)
s1b = Node("sub1B", parent=s1)
s1c = Node("sub1C", parent=s1)
s1ca = Node("sub1Ca", parent=s1c)
ln = SymlinkNode(s1, parent=root, blub=17)
l0 = Node("l0", parent=ln)
eq_(root.parent, None)
eq_(root.children, tuple([s0, s1, ln]))
eq_(s0.parent, root)
eq_(s0.children, tuple([s0b, s0a]))
eq_(s0b.parent, s0)
eq_(s0b.children, tuple())
eq_(s0a.parent, s0)
eq_(s0a.children, tuple())
eq_(s1.parent, root)
eq_(s1.children, tuple([s1a, s1b, s1c]))
eq_(s1.foo, 4)
eq_(s1a.parent, s1)
eq_(s1a.children, tuple())
eq_(s1b.parent, s1)
eq_(s1b.children, tuple())
eq_(s1c.parent, s1)
eq_(s1c.children, tuple([s1ca]))
eq_(s1ca.parent, s1c)
eq_(s1ca.children, tuple())
eq_(ln.parent, root)
eq_(ln.children, tuple([l0]))
eq_(ln.foo, 4)
eq_(s1.blub, 17)
eq_(ln.blub, 17)
ln.bar = 9
eq_(ln.bar, 9)
eq_(s1.bar, 9)
result = [node.name for node in PreOrderIter(root)]
eq_(result, ['root', 'sub0', 'sub0B', 'sub0A', 'sub1', 'sub1A', 'sub1B', 'sub1C', 'sub1Ca', 'sub1', 'l0'])
result = [node.name for node in PostOrderIter(root)]
eq_(result, ['sub0B', 'sub0A', 'sub0', 'sub1A', 'sub1B', 'sub1Ca', 'sub1C', 'sub1', 'l0', 'sub1', 'root'])