<reponame>vecin2/em_automation
from jinja2 import Template


class TreeDrawer(object):
    def __init__(self):
        self.draw = ""

    def get_drawer(self, node):
        """Return the visitor function for this node or `None` if no visitor
        exists for this node.  In that case the generic visit function is
        used instead.
        """
        method = "draw_" + node.__class__.__name__
        return getattr(self, method, None)

    def draw_Include(self, node):
        return "Include(" + node.template.value + ")"

    def draw_Filter(self, node):
        return "Filter(" + node.name + ")"

    def draw_node(self, node):
        draw_func = self.get_drawer(node)
        if draw_func is not None:
            return draw_func(node)
        return self.generic_draw(node)

    def generic_draw(self, node):
        return str(node)

    def visit(self, node):
        self.generic_visit(node, "+--")

    def print_node(self, node):
        self.visit(node)
        print(self.draw)

    def generic_visit(self, node, spacer):
        self.draw += spacer + self.draw_node(node) + "\n"
        spacer = "    " + spacer
        for node in node.iter_child_nodes():
            self.generic_visit(node, spacer)

from jinja2 import Template


class TreeDrawer(object):
    def __init__(self):
        self.draw = ""

    def get_drawer(self, node):
        """Return the visitor function for this node or `None` if no visitor
        exists for this node.  In that case the generic visit function is
        used instead.
        """
        method = "draw_" + node.__class__.__name__
        return getattr(self, method, None)

    def draw_Include(self, node):
        return "Include(" + node.template.value + ")"

    def draw_Filter(self, node):
        return "Filter(" + node.name + ")"

    def draw_node(self, node):
        draw_func = self.get_drawer(node)
        if draw_func is not None:
            return draw_func(node)
        return self.generic_draw(node)

    def generic_draw(self, node):
        return str(node)

    def visit(self, node):
        self.generic_visit(node, "+--")

    def print_node(self, node):
        self.visit(node)
        print(self.draw)

    def generic_visit(self, node, spacer):
        self.draw += spacer + self.draw_node(node) + "\n"
        spacer = "    " + spacer
        for node in node.iter_child_nodes():
            self.generic_visit(node, spacer)
Return the visitor function for this node or `None` if no visitor         exists for this node.  In that case the generic visit function is         used instead.