Exemplo n.º 1
0
    def load_xml(cls, file_name):
        """
        This method loads the port from XML file.

        Returns:

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

        port = Port()
        port.type = parser.getTagAttr(tag_name, "type")
        port.language = parser.getTagAttr(tag_name, "language")
        port.hint = parser.getTagAttr(tag_name, "hint")
        port.color = parser.getTagAttr(tag_name, "color")
        port.multiple = parser.getTagAttr(tag_name, "multiple")
        port.var_name = parser.getTagAttr(tag_name, "var_name")
        port.code = parser.getTag(tag_name).getTag("code").getText()

        if port.type == "":
            return None

        return port
    def test_load_save(self):
        port = Port()
        port.label = "test"
        port.hint = "test"

        result = PortPersistence.load_xml("/this file does not exist")
        self.assertEquals(result, None)

        result = PortPersistence.save_xml(port, "/etc/")
        self.assertEquals(result, False)

        result = PortPersistence.save_xml(port, "/impossible to create")
        self.assertEquals(result, False)

        result = PortPersistence.save_xml(port, "/tmp/")
        self.assertEquals(result, True)

        file_name = "/tmp/" + port.hint + ".xml"
        result = PortPersistence.load_xml(file_name)
        os.remove(file_name)

        port.type = ""
        result = PortPersistence.save_xml(port, "/tmp/")
        file_name = "/tmp/" + port.hint + ".xml"
        result = PortPersistence.load_xml(file_name)
        self.assertEquals(result, None)
        os.remove(file_name)

        code_template = self.create_code_template()
        CodeTemplatePersistence.save_xml(code_template, "/tmp/")
        file_name = "/tmp/" + code_template.name + ".xml"
        result = PortPersistence.load_xml(file_name)
        os.remove(file_name)
 def test_load_wrong_file(self):
     port = Port()
     port.hint = "test"
     PortPersistence.save_xml(port, path="/tmp/")
     file_name = "/tmp/" + port.hint + ".xml"
     result = CodeTemplatePersistence.load_xml(file_name)
     self.assertNotEquals(result, True)
     os.remove(file_name)
Exemplo n.º 4
0
 def get_element(self):
     port = Port()
     port.type = self.type.get_value()
     port.language = self.language.get_value()
     port.hint = self.hint.get_value()
     port.color = self.color.get_value()
     port.multiple = self.multiple.get_value()
     port.code = self.code.get_value()
     port.var_name = self.var_name.get_value()
     return port
 def __save(self):
     port = Port()
     port.type = self.type.get_value()
     port.language = self.language.get_value()
     port.hint = self.hint.get_value()
     port.color = self.color.get_value()
     port.multiple = self.multiple.get_value()
     port.code = self.code.get_value()
     port.var_name = self.var_name.get_value()
     self.port_manager.add_port(port)
Exemplo n.º 6
0
 def create_port(self):
     port = Port()
     port.type = "Test"
     port.language = "Test"
     port.hint = "Test"
     port.color = "#000"
     port.multiple = False
     port.file = None
     port.code = ""
     port.var_name = "$block[label]$_$block[id]$_$port[name]$"
     return port
    def test_load_wrong_diagram(self):
        port = Port()
        port.hint = "test"
        PortPersistence.save_xml(port, path="/tmp/")
        file_name = "/tmp/" + port.hint + ".xml"
        result = DiagramPersistence.load(file_name)
        self.assertNotEquals(result, True)

        diagram = self.create_full_diagram()
        diagram.file_name = file_name
        result = DiagramPersistence.load(diagram)
        self.assertNotEquals(result, True)
        os.remove(file_name)
Exemplo n.º 8
0
    def load(cls, file_name):
        """
        This method loads the port from XML file.

        Returns:

            * **Types** (:class:`boolean<boolean>`)
        """
        # load the port
        if os.path.exists(file_name) is False:
            return None

        data = ""
        port = Port()

        try:
            data_file = open(file_name, 'r')
            data = json.load(data_file)
            data_file.close()

            if data["data"] != "PORT":
                return None

            port = Port()
            port.type = data["type"]
            port.version = data["version"]
            port.type = data["type"]
            port.language = data["language"]
            port.hint = data["hint"]
            port.color = data["color"]
            port.multiple = bool(data["multiple"])
            port.var_name = data["var_name"]
            port.code = data["code"]
        except:
            return None

        if port.type == "":
            return None

        return port