E5XML/TasksReader.py

Sat, 05 Jul 2014 11:41:14 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 05 Jul 2014 11:41:14 +0200
changeset 3669
ac84ac3c0f05
parent 3178
f25fc1364c88
child 3990
5dd6edf8540a
child 4022
f5f42921717e
permissions
-rw-r--r--

Continued renaming eric5 for PyQt5 to eric6.

585
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
3160
209a07d7e401 Updated copyright for 2014.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3035
diff changeset
3 # Copyright (c) 2010 - 2014 Detlev Offenbach <detlev@die-offenbachs.de>
585
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a class for reading an XML tasks file.
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
3145
a9de05d4a22f # __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3060
diff changeset
10 from __future__ import unicode_literals
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
11
585
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 import time
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 from E5Gui.E5Application import e5App
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 from .Config import tasksFileFormatVersion
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 from .XMLStreamReaderBase import XMLStreamReaderBase
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
1819
cfcfd617216a Changed the tasks handling to allow for more fine grained task designations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
19 from Tasks.Task import Task
cfcfd617216a Changed the tasks handling to allow for more fine grained task designations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
20
585
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 import Utilities
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
23
585
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 class TasksReader(XMLStreamReaderBase):
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 Class for reading an XML tasks file.
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
1819
cfcfd617216a Changed the tasks handling to allow for more fine grained task designations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
28 supportedVersions = ["4.2", "5.0", "5.1"]
590
beb60b9b3d8d Added code to handle unsupported versions to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 589
diff changeset
29
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
30 def __init__(self, device, forProject=False, viewer=None):
585
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 """
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 Constructor
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 @param device reference to the I/O device to read from (QIODevice)
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 @param forProject flag indicating project related mode (boolean)
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 @param viewer reference to the task viewer (TaskViewer)
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 """
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 XMLStreamReaderBase.__init__(self, device)
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 self.viewer = viewer
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 self.forProject = forProject
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 if viewer:
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 self.viewer = viewer
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 else:
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 self.viewer = e5App().getObject("TaskViewer")
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 self.version = ""
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 def readXML(self):
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 """
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 Public method to read and parse the XML document.
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 """
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 while not self.atEnd():
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 self.readNext()
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 if self.isStartElement():
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 if self.name() == "Tasks":
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
58 self.version = self.attribute(
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
59 "version", tasksFileFormatVersion)
590
beb60b9b3d8d Added code to handle unsupported versions to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 589
diff changeset
60 if self.version not in self.supportedVersions:
beb60b9b3d8d Added code to handle unsupported versions to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 589
diff changeset
61 self.raiseUnsupportedFormatVersion(self.version)
585
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 elif self.name() == "Task":
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 self.__readTask()
960
64a6e66b4707 Added capability to the tasks viewer to ignore files based on a wildcard during a project tasks scan.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
64 elif self.name() == "ProjectScanFilter":
64a6e66b4707 Added capability to the tasks viewer to ignore files based on a wildcard during a project tasks scan.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
65 filter = self.readElementText()
64a6e66b4707 Added capability to the tasks viewer to ignore files based on a wildcard during a project tasks scan.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
66 if self.forProject:
64a6e66b4707 Added capability to the tasks viewer to ignore files based on a wildcard during a project tasks scan.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
67 self.viewer.projectTasksScanFilter = filter
589
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 587
diff changeset
68 else:
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 587
diff changeset
69 self.raiseUnexpectedStartTag(self.name())
585
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 self.showErrorMessage()
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 def __readTask(self):
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 """
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 Private method to read the task info.
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
77 task = {"summary": "",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
78 "priority": 1,
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
79 "completed": False,
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
80 "created": 0,
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
81 "filename": "",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
82 "linenumber": 0,
1819
cfcfd617216a Changed the tasks handling to allow for more fine grained task designations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
83 "type": Task.TypeTodo,
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
84 "description": "",
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
85 }
585
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 task["priority"] = int(self.attribute("priority", "1"))
592
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
87 task["completed"] = self.toBool(self.attribute("completed", "False"))
1819
cfcfd617216a Changed the tasks handling to allow for more fine grained task designations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
88 if self.version in ["4.2", "5.0"]:
cfcfd617216a Changed the tasks handling to allow for more fine grained task designations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
89 isBugfix = self.toBool(self.attribute("bugfix", "False"))
cfcfd617216a Changed the tasks handling to allow for more fine grained task designations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
90 if isBugfix:
cfcfd617216a Changed the tasks handling to allow for more fine grained task designations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
91 task["type"] = Task.TypeFixme
cfcfd617216a Changed the tasks handling to allow for more fine grained task designations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
92 else:
cfcfd617216a Changed the tasks handling to allow for more fine grained task designations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
93 task["type"] = int(self.attribute("type", str(Task.TypeTodo)))
585
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 while not self.atEnd():
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 self.readNext()
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 if self.isEndElement() and self.name() == "Task":
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
98 self.viewer.addTask(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
99 task["summary"], priority=task["priority"],
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
100 filename=task["filename"], lineno=task["linenumber"],
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
101 completed=task["completed"], _time=task["created"],
1819
cfcfd617216a Changed the tasks handling to allow for more fine grained task designations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
102 isProjectTask=self.forProject, taskType=task["type"],
2197
c4f24f8f34c0 Some harminisation of nomenclature in the various Task dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1819
diff changeset
103 description=task["description"])
585
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 break
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 if self.isStartElement():
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 if self.name() == "Summary":
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 task["summary"] = self.readElementText()
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 elif self.name() == "Description":
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 task["description"] = self.readElementText()
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 elif self.name() == "Created":
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
112 task["created"] = time.mktime(time.strptime(
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
113 self.readElementText(), "%Y-%m-%d, %H:%M:%S"))
589
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 587
diff changeset
114 elif self.name() == "Resource":
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 587
diff changeset
115 continue # handle but ignore this tag
585
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 elif self.name() == "Filename":
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 task["filename"] = \
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 Utilities.toNativeSeparators(self.readElementText())
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 elif self.name() == "Linenumber":
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 try:
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 task["linenumber"] = int(self.readElementText())
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 except ValueError:
f40889943c0a Migrated the tasks handler to tasks reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 pass
589
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 587
diff changeset
124 else:
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 587
diff changeset
125 self.raiseUnexpectedStartTag(self.name())

eric ide

mercurial