E5XML/MultiProjectWriter.py

Fri, 10 Sep 2010 08:54:33 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 10 Sep 2010 08:54:33 +0200
changeset 580
45c38566b001
parent 411
99409cddaaa9
child 602
2f32aef5cc67
permissions
-rw-r--r--

Implemented the plug-in repository reader.

# -*- coding: utf-8 -*-

# Copyright (c) 2008 - 2010 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing the writer class for writing an XML multi project file.
"""

import time

from .XMLWriterBase import XMLWriterBase
from .Config import multiProjectFileFormatVersion

import Preferences
import Utilities

class MultiProjectWriter(XMLWriterBase):
    """
    Class implementing the writer class for writing an XML project file.
    """
    def __init__(self, multiProject, file, multiProjectName):
        """
        Constructor
        
        @param multiProject Reference to the multi project object
        @param file open file (like) object for writing
        @param projectName name of the project (string)
        """
        XMLWriterBase.__init__(self, file)
        
        self.name = multiProjectName
        self.multiProject = multiProject
    
    def writeXML(self):
        """
        Public method to write the XML to the file.
        """
        XMLWriterBase.writeXML(self)
        
        self._write('<!DOCTYPE MultiProject SYSTEM "MultiProject-{0}.dtd">'\
            .format(multiProjectFileFormatVersion))
        
        # add some generation comments
        self._write("<!-- eric5 multi project file for multi project {0} -->"\
            .format(self.name))
        if Preferences.getMultiProject("XMLTimestamp"):
            self._write("<!-- Saved: {0} -->".format(time.strftime('%Y-%m-%d, %H:%M:%S')))
            self._write("<!-- Copyright (C) {0} -->".format(time.strftime('%Y')))
        
        # add the main tag
        self._write('<MultiProject version="{0}">'.format(multiProjectFileFormatVersion))
        
        # do description
        self._write("  <Description>{0}</Description>".format(
            self.escape(self.encodedNewLines(self.multiProject.description))))
        
        # do the projects
        self._write("  <Projects>")
        for project in self.multiProject.getProjects():
            self._write('    <Project isMaster="{0}">'.format(project['master']))
            self._write("      <ProjectName>{0}</ProjectName>".format(
                self.escape(project['name'])))
            self._write("      <ProjectFile>{0}</ProjectFile>".format(
                Utilities.fromNativeSeparators(project['file'])))
            self._write("      <ProjectDescription>{0}</ProjectDescription>".format(
                self.escape(self.encodedNewLines(project['name']))))
            self._write("    </Project>")
        self._write("  </Projects>")
        
        self._write("</MultiProject>", newline = False)

eric ide

mercurial