Exemplo n.º 1
0
def _format_anim(
    tree: treelib.Tree, state: Mapping[str, stack.State]
) -> Iterable[Union[Tuple[str, str], str]]:  # pragma: no cover
    for node in tree.filter_nodes(lambda n: n.identifier in state):
        nid, data = node.identifier, node.data
        text = OP_TRANS[state[nid].status[0]]
        text += " " + node.tag
        text += " " + state[nid].status[-1]
        if "type" in data:
            text += " " + data["type"]
        node.tag = text
    base = str(tree).strip("\n")
    res: List[Union[Tuple[str, str], str]] = []
    for token in re.split(r"([A-Z_\S]+)", base):
        if token in {"UPDATE", "CREATE", "REPLACE", "DELETE"}:
            res.append(("progress", f"PENDING_{token}"))
        elif token in STATUS_TRANS["progress"]:
            res.append(("progress", token))
        elif token in STATUS_TRANS["failed"]:
            res.append(("failed", token))
        elif token in STATUS_TRANS["complete"]:
            res.append(("complete", token))
        elif token in STATUS_TRANS["other"]:
            res.append(("other", token))
        elif len(token.split(".")) == 3:
            res.append(("type", token))
        else:
            res.append(token)
    return res
Exemplo n.º 2
0
    def test_filter_nodes(self):
        """
        tests: Tree.filter_nodes
        Added by: William Rusnack
        """
        new_tree = Tree()

        self.assertEqual(tuple(new_tree.filter_nodes(lambda n: True)), ())

        nodes = list()
        nodes.append(new_tree.create_node('root_node'))
        nodes.append(new_tree.create_node('second', parent=new_tree.root))

        self.assertEqual(tuple(new_tree.filter_nodes(lambda n: False)), ())
        self.assertEqual(tuple(new_tree.filter_nodes(lambda n: n.is_root())), (nodes[0],))
        self.assertEqual(tuple(new_tree.filter_nodes(lambda n: not n.is_root())), (nodes[1],))
        self.assertTrue(set(new_tree.filter_nodes(lambda n: True)), set(nodes))
Exemplo n.º 3
0
def _format_base(tree: treelib.Tree, state: Mapping[str, stack.State]) -> str:
    for node in tree.filter_nodes(lambda n: n.identifier in state):
        nid, data = node.identifier, node.data
        status = state[nid].status[-1]
        color = None
        if status in STATUS_TRANS["progress"]:
            color = "blue"
        elif status in STATUS_TRANS["failed"]:
            color = "red"
        elif status in STATUS_TRANS["complete"]:
            color = "green"
        elif status in STATUS_TRANS["other"]:
            color = "yellow"
        text = OP_TRANS[state[nid].status[0]]
        text += " " + node.tag
        text += " " + click.style(status, fg=color)
        if "type" in data:
            text += " " + click.style(data["type"], dim=True)
        node.tag = text
    return str(tree).strip("\n")
Exemplo n.º 4
0
        inner_bags = get_inner_bags(split_line[1])

        existing_bags = find_existing_bag(baggage_claim, outer_bag)
        if (len(existing_bags) > 0):
            for bag in existing_bags:
                for i in inner_bags:
                    baggage_claim.create_node(i, parent=bag.identifier)

        else:
            outer_bag_node = baggage_claim.create_node(outer_bag,
                                                       parent='baggage claim')
            for i in inner_bags:
                inner_existing = find_existing_top_level_bag(baggage_claim, i)
                print(f'inner_existing {inner_existing}')
                if (len(inner_existing) > 0):
                    #tree.move(node, new_parent)
                    baggage_claim.move_node(inner_existing[0].identifier,
                                            outer_bag_node.identifier)
                # if inner already exists
                # move existing
                else:
                    baggage_claim.create_node(i,
                                              parent=outer_bag_node.identifier)

    baggage_claim.show()
    shiny = list(
        baggage_claim.filter_nodes(lambda n: n.tag == 'shiny gold bag'))
    print(f'shiny gold bags: {len(shiny)}')
    for child in baggage_claim.children('baggage claim'):
        pass
        # print(f'{child.tag} {baggage_claim.children(child.identifier)[0]}')