当前位置: 首页>>代码示例>>Python>>正文


Python anytree.PreOrderIter方法代码示例

本文整理汇总了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]) 
开发者ID:c0fec0de,项目名称:anytree,代码行数:24,代码来源:test_iterators.py

示例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,
        ) 
开发者ID:portugueslab,项目名称:stytra,代码行数:31,代码来源:pipelines.py

示例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) 
开发者ID:c0fec0de,项目名称:anytree,代码行数:8,代码来源:dotexporter.py

示例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) 
开发者ID:c0fec0de,项目名称:anytree,代码行数:13,代码来源:dotexporter.py

示例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) 
开发者ID:c0fec0de,项目名称:anytree,代码行数:17,代码来源:test_node.py

示例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 
开发者ID:deadc0de6,项目名称:catcli,代码行数:11,代码来源:noder.py

示例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] 
开发者ID:bsquizz,项目名称:ocdeployer,代码行数:49,代码来源:utils.py

示例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']) 
开发者ID:c0fec0de,项目名称:anytree,代码行数:51,代码来源:test_node_symlink.py


注:本文中的anytree.PreOrderIter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。