E5XML/TasksWriter.py

Mon, 25 Mar 2013 03:11:06 +0100

author
T.Rzepka <Tobias.Rzepka@gmail.com>
date
Mon, 25 Mar 2013 03:11:06 +0100
branch
Py2 comp.
changeset 2525
8b507a9a2d40
parent 2302
f29e9405c851
child 3057
10516539f238
permissions
-rw-r--r--

Script changes: Future import added, super calls modified and unicode behavior for str.

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

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

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

from __future__ import unicode_literals    # __IGNORE_WARNING__

import time

from E5Gui.E5Application import e5App

from .XMLStreamWriterBase import XMLStreamWriterBase
from .Config import tasksFileFormatVersion

import Preferences
import Utilities


class TasksWriter(XMLStreamWriterBase):
    """
    Class implementing the writer class for writing an XML tasks file.
    """
    def __init__(self, device, forProject=False, projectName=""):
        """
        Constructor
        
        @param device reference to the I/O device to write to (QIODevice)
        @param forProject flag indicating project related mode (boolean)
        @param projectName name of the project (string)
        """
        XMLStreamWriterBase.__init__(self, device)
        
        self.name = projectName
        self.forProject = forProject
        
    def writeXML(self):
        """
        Public method to write the XML to the file.
        """
        XMLStreamWriterBase.writeXML(self)
        
        self.writeDTD('<!DOCTYPE Tasks SYSTEM "Tasks-{0}.dtd">'.format(
            tasksFileFormatVersion))
        
        # add some generation comments
        if self.forProject:
            self.writeComment(" eric5 tasks file for project {0} ".format(self.name))
            if Preferences.getProject("XMLTimestamp"):
                self.writeComment(" Saved: {0} ".format(
                    time.strftime('%Y-%m-%d, %H:%M:%S')))
        else:
            self.writeComment(" eric5 tasks file ")
            self.writeComment(" Saved: {0} ".format(time.strftime('%Y-%m-%d, %H:%M:%S')))
        
        # add the main tag
        self.writeStartElement("Tasks")
        self.writeAttribute("version", tasksFileFormatVersion)
        
        # write the project scan filter
        if self.forProject:
            self.writeTextElement("ProjectScanFilter",
                e5App().getObject("TaskViewer").projectTasksScanFilter.strip())
        
        # do the tasks
        if self.forProject:
            tasks = e5App().getObject("TaskViewer").getProjectTasks()
        else:
            tasks = e5App().getObject("TaskViewer").getGlobalTasks()
        for task in tasks:
            self.writeStartElement("Task")
            self.writeAttribute("priority", str(task.priority))
            self.writeAttribute("completed", str(task.completed))
            self.writeAttribute("type", str(task.taskType))
            self.writeTextElement("Summary", task.summary.strip())
            self.writeTextElement("Description", task.description.strip())
            self.writeTextElement("Created",
                time.strftime("%Y-%m-%d, %H:%M:%S", time.localtime(task.created)))
            if task.filename:
                self.writeStartElement("Resource")
                self.writeTextElement("Filename",
                    Utilities.fromNativeSeparators(task.filename))
                self.writeTextElement("Linenumber", str(task.lineno))
                self.writeEndElement()
            self.writeEndElement()
        
        self.writeEndElement()
        self.writeEndDocument()

eric ide

mercurial