Exemple #1
0
    def load(cls, file_name):
        """
        This method loads the block from XML file.

        Returns:

            * **Types** (:class:`boolean<boolean>`)
        """
        if os.path.exists(file_name) is False:
            return
        parser = XMLParser(file_name)

        if parser.getTag(tag_name) is None:
            return None

        block = BlockModel()

        block.type = parser.getTagAttr(tag_name, "type")
        block.language = parser.getTagAttr(tag_name, "language")
        block.framework = parser.getTagAttr(tag_name, "framework")

        block.label = parser.getTagAttr(tag_name, "label")
        block.group = parser.getTagAttr(tag_name, "group")
        block.color = parser.getTagAttr(tag_name, "color")
        block.help = parser.getTagAttr(tag_name, "help")
        block.source = parser.getTagAttr(tag_name, "source")

        count = 0
        for code in block.codes:
            block.codes[count] = parser.getTag(tag_name).getTag(
                "code" + str(count)).getText()
            count = count + 1

        props = parser.getTag(tag_name).getTag("properties").getChildTags(
            "property")
        for prop in props:
            block.properties.append(ast.literal_eval(prop.getAttr("value")))

        in_ports = parser.getTag(tag_name).getTag("in_ports").getChildTags(
            "port")
        for port in in_ports:
            block.in_ports.append(ast.literal_eval(port.getAttr("value")))

        out_ports = parser.getTag(tag_name).getTag("out_ports").getChildTags(
            "port")
        for port in out_ports:
            block.out_ports.append(ast.literal_eval(port.getAttr("value")))

        if block.type == "mosaicode.model.blockmodel":
            return None
        return block
Exemple #2
0
    def load_xml(cls, file_name):
        """
        This method loads the block from XML file.

        Returns:

            * **Types** (:class:`boolean<boolean>`)
        """
        if os.path.exists(file_name) is False:
            return None
        parser = XMLParser(file_name)

        if parser.getTag(tag_name) is None:
            return None

        block = BlockModel()

        block.type = parser.getTagAttr(tag_name, "type")
        block.language = parser.getTagAttr(tag_name, "language")
        block.framework = parser.getTagAttr(tag_name, "framework")

        block.label = parser.getTagAttr(tag_name, "label")
        block.group = parser.getTagAttr(tag_name, "group")
        block.color = parser.getTagAttr(tag_name, "color")
        block.help = parser.getTagAttr(tag_name, "help")

        for code in block.codes:
            block.codes[code] = parser.getTag(tag_name).getTag(code).getText()

        props = parser.getTag(tag_name).getTag(
                    "properties").getChildTags("property")
        for prop in props:
            block.properties.append(ast.literal_eval(prop.getAttr("value")))

        ports = parser.getTag(tag_name).getTag("ports").getChildTags("port")
        for port in ports:
            dict_port = {}
            dict_port["type"]= str(port.getAttr("type_"))
            dict_port["name"]= str(port.getAttr("name_"))
            dict_port["label"]= str(port.getAttr("label"))
            dict_port["conn_type"]= str(port.getAttr("conn_type"))
            block.ports.append(dict_port)

        if block.type == "mosaicode.model.blockmodel":
            return None
        return block