示例#1
0
    def instantiate(self, rack, tree):
        for stmt in tree.stmts:
            if isinstance(stmt, parser.Attr):
                try:
                    rack.set_attribute(stmt)
                except AttributeError:
                    self.diagram.set_attribute(stmt)
            elif isinstance(stmt, parser.RackItem):
                if stmt.number is None:
                    if len(rack.nodes) > 0:
                        item = rack.nodes[-1]
                        number = item.number + item.colheight
                    else:
                        number = 1
                else:
                    number = stmt.number

                item = RackItem(number, unquote(stmt.label))
                item.set_attributes(stmt.attrs)
                rack.nodes.append(item)
            elif isinstance(stmt, parser.Rack):
                _rack = Rack()
                self.diagram.racks.append(_rack)
                self.instantiate(_rack, stmt)
            elif isinstance(stmt, parser.AttrPlugin):
                self.diagram.set_plugin(stmt.name, stmt.attrs)
示例#2
0
文件: builder.py 项目: bithium/nwdiag
    def instantiate(self, rack, tree):
        for stmt in tree.stmts:
            if isinstance(stmt, parser.Attr):
                try:
                    rack.set_attribute(stmt)
                except AttributeError:
                    self.diagram.set_attribute(stmt)
            elif isinstance(stmt, parser.RackItem):
                if stmt.number is None:
                    if len(rack.nodes) > 0:
                        item = rack.nodes[-1]
                        number = item.number + item.colheight
                    else:
                        number = 1
                else:
                    number = stmt.number

                item = RackItem(number, unquote(stmt.label))
                item.set_attributes(stmt.attrs)
                rack.nodes.append(item)
            elif isinstance(stmt, parser.Rack):
                _rack = Rack()
                self.diagram.racks.append(_rack)
                self.instantiate(_rack, stmt)
            elif isinstance(stmt, parser.AttrPlugin):
                self.diagram.set_plugin(stmt.name, stmt.attrs)
示例#3
0
    def build(cls, tree):
        Rack.clear()
        RackItem.clear()
        Diagram.clear()

        return cls(tree).run()
示例#4
0
文件: builder.py 项目: bithium/nwdiag
    def build(cls, tree):
        Rack.clear()
        RackItem.clear()
        Diagram.clear()

        return cls(tree).run()