當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。