Exemplo n.º 1
0
    def save(cls, port):
        """
        This method save the port in user space.

        Returns:

            * **Types** (:class:`boolean<boolean>`)
        """
        from harpia.system import System
        port.source = "xml"
        parser = XMLParser()
        parser.addTag('HarpiaPort')

        parser.setTagAttr('HarpiaPort','type', port.type)
        parser.setTagAttr('HarpiaPort','language', port.language)
        parser.setTagAttr('HarpiaPort','label', port.label)
        parser.setTagAttr('HarpiaPort','color', port.color)
        parser.setTagAttr('HarpiaPort','multiple', port.multiple)
        parser.setTagAttr('HarpiaPort','source', port.source)
        parser.appendToTag('HarpiaPort','code').string = str(port.code)

        count = 0
        for code in port.input_codes:
            parser.appendToTag('HarpiaPort', 'input_code' + \
                        str(count)).string = str(port.input_codes[count])
            parser.appendToTag('HarpiaPort', 'output_code' + \
                        str(count)).string = str(port.output_codes[count])
            count = count + 1


        try:
            data_dir = System.get_user_dir() + "/extensions/"
            data_dir = data_dir + port.language + "/ports/"
            if not os.path.isdir(data_dir):
                try:
                    os.makedirs(data_dir)
                except:
                    pass
            file_name = data_dir + port.type + ".xml"
            port_file = file(os.path.expanduser(file_name), 'w')
            port_file.write(parser.prettify())
            port_file.close()
        except IOError as e:
            return False
        return True
Exemplo n.º 2
0
    def save(cls, prefs):
        """
        This method save the diagram.

        Returns:

            * **Types** (:class:`boolean<boolean>`)
        """
        parser = XMLParser()
        parser.addTag('HarpiaProperties')
        parser.setTagAttr('HarpiaProperties','default_directory',
                prefs.default_directory)
        parser.setTagAttr('HarpiaProperties','default_filename',
                prefs.default_filename)
        parser.setTagAttr('HarpiaProperties','grid', prefs.grid)
        parser.setTagAttr('HarpiaProperties','width', prefs.width)
        parser.setTagAttr('HarpiaProperties','height', prefs.height)
        parser.setTagAttr('HarpiaProperties','hpaned_work_area',
                prefs.hpaned_work_area)
        parser.setTagAttr('HarpiaProperties','vpaned_bottom',
                prefs.vpaned_bottom)
        parser.setTagAttr('HarpiaProperties','vpaned_left',
                prefs.vpaned_left)

        parser.appendToTag('HarpiaProperties', 'recent_files')
        for key in prefs.recent_files:
            parser.appendToTag('recent_files', 'name', value=key)

        try:
            from harpia.system import System
            file_name = System.get_user_dir() + "/" + prefs.conf_file_path
            confFile = file(os.path.expanduser(file_name), 'w')
            confFile.write(parser.prettify())
            confFile.close()
        except IOError as e:
            return False
        return True
Exemplo n.º 3
0
    def save(cls, code_template):
        """
        This method save the code_template in user space.

        Returns:

            * **Types** (:class:`boolean<boolean>`)
        """
        from harpia.system import System
        code_template.source = "xml"
        parser = XMLParser()
        parser.addTag('HarpiaCodeTemplate')
        parser.setTagAttr('HarpiaCodeTemplate','name', code_template.name)
        parser.setTagAttr('HarpiaCodeTemplate','type', code_template.type)
        parser.setTagAttr('HarpiaCodeTemplate','description', code_template.description)
        parser.setTagAttr('HarpiaCodeTemplate','language', code_template.language)
        parser.setTagAttr('HarpiaCodeTemplate','extension', code_template.extension)
        parser.setTagAttr('HarpiaCodeTemplate','source', code_template.source)
        parser.appendToTag('HarpiaCodeTemplate','command').string = str(code_template.command)
        parser.appendToTag('HarpiaCodeTemplate','code').string = str(code_template.code)

        try:
            data_dir = System.get_user_dir() + "/extensions/"
            data_dir = data_dir + code_template.language + "/"
            if not os.path.isdir(data_dir):
                try:
                    os.makedirs(data_dir)
                except:
                    pass
            file_name = data_dir + code_template.type + ".xml"
            code_template_file = file(os.path.expanduser(file_name), 'w')
            code_template_file.write(parser.prettify())
            code_template_file.close()
        except IOError as e:
            return False
        return True
Exemplo n.º 4
0
    def save(cls, diagram):
        """
        This method save a file.

        Returns:

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

        parser = XMLParser()
        parser.addTag('harpia')
        parser.appendToTag('harpia', 'version', value=System.VERSION)
        parser.appendToTag('harpia', 'zoom', value=diagram.zoom)
        parser.appendToTag('harpia', 'language', value=diagram.language)

        parser.appendToTag('harpia', 'blocks')
        for block_id in diagram.blocks:
            block_type = diagram.blocks[block_id].type
            pos = diagram.blocks[block_id].get_position()
            parser.appendToTag('blocks', 'block', type=block_type, id=block_id)
            parser.appendToLastTag('block', 'position', x=pos[0], y=pos[1])
            props = diagram.blocks[block_id].get_properties()
            for prop in props:
                parser.appendToLastTag('block',
                                       'property',
                                       key=str(prop["name"]),
                                       value=str(prop["value"])
                                       )

        parser.appendToTag('harpia', 'connections')
        for connector in diagram.connectors:
            parser.appendToTag('connections', 'connection',
                               from_block=connector.source.id,
                               from_out=int(connector.source_port) + 1,
                               to_block=connector.sink.id,
                               to_in=int(connector.sink_port) + 1)

        try:
            save_file = open(str(diagram.file_name), "w")
            save_file.write(parser.prettify())
            save_file.close()
        except IOError as e:
            System.log(e.strerror)
            return False, e.strerror

        diagram.set_modified(False)
        return True, "Success"