Ejemplo n.º 1
0
    def save_xml(cls, block, path=None):
        """
        This method save the block in user space.

        Returns:

            * **Types** (:class:`boolean<boolean>`)
        """

        block.source = "xml"
        parser = XMLParser()
        main = parser.addTag(tag_name)
        parser.setTagAttr(tag_name, 'type', block.type)
        parser.setTagAttr(tag_name, 'language', block.language)
        parser.setTagAttr(tag_name, 'extension', block.extension)

        parser.setTagAttr(tag_name, 'help', block.help)
        parser.setTagAttr(tag_name, 'label', block.label)
        parser.setTagAttr(tag_name, 'color', block.color)
        parser.setTagAttr(tag_name, 'group', block.group)
        parser.setTagAttr(tag_name, 'maxIO', block.maxIO)

        parser.setTagAttr(tag_name, 'codes', block.codes)

        parser.appendToTag(tag_name, 'properties')
        for key in block.properties:
            parser.appendToTag('properties', 'property', value=key)

        parser.appendToTag(tag_name, 'ports')
        for port in block.ports:
            parser.appendToTag('ports',
                               'port',
                               conn_type=port.conn_type,
                               name_=port.name,
                               label=port.label,
                               type_=port.type)

        if (path is not None) and not Persistence.create_dir(path):
            return False

        if (path is None) and (block.file is not None):
            path = block.file
        elif (path is not None):
            file_name = block.label
            path = os.path.join(path, file_name + '.xml')
        else:
            return False

        parser.setTagAttr(tag_name, 'file', path)

        try:
            block_file = file(path, 'w')
            block_file.write(parser.getXML())
            block_file.close()
        except IOError as e:
            return False
        return True
Ejemplo n.º 2
0
    def save(cls, block):
        """
        This method save the block in user space.

        Returns:

            * **Types** (:class:`boolean<boolean>`)
        """
        from mosaicode.system import System
        block.source = "xml"
        parser = XMLParser()
        main = parser.addTag(tag_name)
        parser.setTagAttr(tag_name, 'type', block.type)
        parser.setTagAttr(tag_name, 'language', block.language)
        parser.setTagAttr(tag_name, 'framework', block.framework)

        parser.setTagAttr(tag_name, 'label', block.label)
        parser.setTagAttr(tag_name, 'group', block.group)
        parser.setTagAttr(tag_name, 'color', block.color)
        parser.setTagAttr(tag_name, 'help', block.help)
        parser.setTagAttr(tag_name, 'source', block.source)

        count = 0
        for code in block.codes:
            parser.appendToTag(tag_name, 'code' + str(count)).string = str(
                block.codes[count])
            count = count + 1

        parser.appendToTag(tag_name, 'properties')
        for key in block.properties:
            parser.appendToTag('properties', 'property', value=key)

        parser.appendToTag(tag_name, 'in_ports')
        for key in block.in_ports:
            parser.appendToTag('in_ports', 'port', value=key)

        parser.appendToTag(tag_name, 'out_ports')
        for key in block.out_ports:
            parser.appendToTag('out_ports', 'port', value=key)

        try:
            data_dir = System.get_user_dir() + "/extensions/"
            data_dir = data_dir + block.language + "/" + block.framework + "/"
            if not os.path.isdir(data_dir):
                try:
                    os.makedirs(data_dir)
                except:
                    pass
            file_name = data_dir + block.type + ".xml"
            block_file = file(os.path.expanduser(file_name), 'w')
            block_file.write(parser.getXML())
            block_file.close()
        except IOError as e:
            return False
        return True
Ejemplo n.º 3
0
    def save_xml(cls, block, path):
        """
        This method save the block in user space.

        Returns:

            * **Types** (:class:`boolean<boolean>`)
        """

        block.source = "xml"
        parser = XMLParser()
        main = parser.addTag(tag_name)
        parser.setTagAttr(tag_name,'type', block.type)
        parser.setTagAttr(tag_name,'language', block.language)
        parser.setTagAttr(tag_name,'framework', block.framework)

        parser.setTagAttr(tag_name,'label', block.label)
        parser.setTagAttr(tag_name,'group', block.group)
        parser.setTagAttr(tag_name,'color', block.color)
        parser.setTagAttr(tag_name,'help', block.help)

        for code in block.codes:
            parser.appendToTag(tag_name, code, value=block.codes[code])

        parser.appendToTag(tag_name, 'properties')
        for key in block.properties:
            parser.appendToTag('properties', 'property', value=key)

        parser.appendToTag(tag_name, 'ports')
        for port in block.ports:
            parser.appendToTag('ports', 'port',
                conn_type=port.conn_type,
                name_=port.name,
                label=port.label,
                type_=port.type)

        if not Persistence.create_dir(path):
            return False
        try:
            file_name = path + block.type + ".xml"
            block_file = file(os.path.expanduser(file_name), 'w')
            block_file.write(parser.getXML())
            block_file.close()
        except IOError as e:
            return False
        return True
Ejemplo n.º 4
0
class TestXMLParser(TestCase):
    def setUp(self):
        """Do the test basic setup."""
        source = None
        fromString = False
        fromTag = False
        self.xml_parser = XMLParser(source, fromString, fromTag)

        source = FILES_INPUT + "And.mscd"
        fromString = False
        fromTag = False
        self.xml_parser = XMLParser(source, fromString, fromTag)

        # source = FILES_INPUT + "And.mscd"
        # fromString = True
        # fromTag = False
        # self.xml_parser = XMLParser(source, fromString, fromTag)
        #
        # source = "TESTE"
        # fromString = True
        # fromTag = False
        # self.xml_parser = XMLParser(source, fromString, fromTag)
        #
        # source = "TESTE"
        # fromString = False
        # fromTag = True
        # self.xml_parser = XMLParser(source, fromString, fromTag)
        #
        # source = "TESTE"
        # fromString = True
        # fromTag = True
        # self.xml_parser = XMLParser(source, fromString, fromTag)

    # ----------------------------------------------------------------------
    def test_getTagAttr(self):
        self.xml_parser.tag = "property"
        self.xml_parser.attr = "key"
        self.assertIsNotNone(
            self.xml_parser.getTagAttr(self.xml_parser.tag,
                                       self.xml_parser.attr))

        #tag = None
        #attr = None
        #self.assertIsNotNone(self.xml_parser.getTagAttr(tag, attr))

    # ----------------------------------------------------------------------
    def test_setTagAttr(self):
        tag = "position"
        attr = "x"
        self.assertIsNone(self.xml_parser.setTagAttr(tag, attr, 10))

    # ----------------------------------------------------------------------
    def test_getAttr(self):
        #tag = "position"
        attr = "position"
        self.assertIsNotNone(self.xml_parser.getAttr(attr))
        #self.assertEqual(10, self.xml_parser.setTagAttr(attr))

    # ----------------------------------------------------------------------
    def test_setAttr(self):
        attr = "to_block"
        self.assertIsNone(self.xml_parser.setAttr(attr, 10))

    # ----------------------------------------------------------------------
    def test_getChildTagAttr(self):
        parent = "block"
        child = "position"
        attr = "x"
        self.assertIsNotNone(
            self.xml_parser.getChildTagAttr(parent, child, attr))

    # ----------------------------------------------------------------------
    def test_setChildTagAttr(self):
        parent = "block"
        child = "position"
        attr = "x"
        value = 10
        self.assertIsNone(
            self.xml_parser.setChildTagAttr(parent, child, attr, value))

    # ----------------------------------------------------------------------
    def test_getChildTags(self):
        child = "position"
        self.assertIsNotNone(self.xml_parser.getChildTags(child))
        child = "block"
        self.assertIsNotNone(self.xml_parser.getChildTags(child))

    # ----------------------------------------------------------------------
    def test_addTag(self):
        tagName = "position"
        self.assertIsNotNone(self.xml_parser.addTag(tagName))

    # ----------------------------------------------------------------------
    def test_appendToTag(self):
        tagParent = "position"
        tagChild = "x"
        self.assertIsNotNone(self.xml_parser.appendToTag(tagParent, tagChild))

    # ----------------------------------------------------------------------
    def test_appendToLastTag(self):
        tagParent = "position"
        tagChild = "x"
        self.assertIsNotNone(
            self.xml_parser.appendToLastTag(tagParent, tagChild))

    # ----------------------------------------------------------------------
    def test_getXML(self):
        self.assertIsNotNone(self.xml_parser.getXML())

    # ----------------------------------------------------------------------
    def test_getTagXML(self):
        tagName = "position"
        tag = self.xml_parser.addTag(tagName)
        self.assertIsNotNone(self.xml_parser.getTagXML(tag))

    # ----------------------------------------------------------------------
    def test_getTag(self):
        tagName = "position"
        tag = self.xml_parser.addTag(tagName)
        self.assertIsNone(self.xml_parser.getTag(tag))
        tag = "ABC"
        self.assertIsNone(self.xml_parser.getTag(tag))
        tag = "position"
        self.assertIsNotNone(self.xml_parser.getTag(tag))

    # ----------------------------------------------------------------------
    def test_getTagChild(self):
        parent = "block"
        child = "position"
        self.assertIsNotNone(self.xml_parser.getTagChild(parent, child))

    # ----------------------------------------------------------------------
    def test_getTagContent(self):
        self.assertIsNotNone(self.xml_parser.getTagContent())

    # ----------------------------------------------------------------------
    def test_getTagChildren(self):
        self.assertIsNotNone(self.xml_parser.getTagChildren())

    # ----------------------------------------------------------------------
    def test_getText(self):
        self.assertIsNotNone(self.xml_parser.getText())

    # ----------------------------------------------------------------------
    def test_prettify(self):
        self.assertIsNotNone(self.xml_parser.prettify())