E5XML/MultiProjectReader.py

Sat, 11 Jan 2014 15:33:07 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 11 Jan 2014 15:33:07 +0100
branch
5_4_x
changeset 3198
8c9eb883b2a0
parent 3160
209a07d7e401
permissions
-rw-r--r--

Fixed an issue in the multi project XML reader.

602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
3160
209a07d7e401 Updated copyright for 2014.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
3 # Copyright (c) 2010 - 2014 Detlev Offenbach <detlev@die-offenbachs.de>
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a class for reading an XML multi project file.
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from .Config import multiProjectFileFormatVersion
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 from .XMLStreamReaderBase import XMLStreamReaderBase
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 import Utilities
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
15
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 class MultiProjectReader(XMLStreamReaderBase):
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 """
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 Class for reading an XML multi project file.
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 """
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 supportedVersions = ["4.2"]
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 def __init__(self, device, multiProject):
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 Constructor
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 @param device reference to the I/O device to read from (QIODevice)
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 @param multiProject Reference to the multi project object to store the
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 information into.
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 """
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 XMLStreamReaderBase.__init__(self, device)
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 self.multiProject = multiProject
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 self.version = ""
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 def readXML(self):
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 """
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 Public method to read and parse the XML document.
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 while not self.atEnd():
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 self.readNext()
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 if self.isStartElement():
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 if self.name() == "MultiProject":
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
44 self.version = self.attribute(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
45 "version",
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 multiProjectFileFormatVersion)
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 if self.version not in self.supportedVersions:
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 self.raiseUnsupportedFormatVersion(self.version)
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 elif self.name() == "Description":
605
9c7527ecbf6e Removed code to encode and decode newlines from XML stream reader and writer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 602
diff changeset
50 self.multiProject.description = self.readElementText()
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 elif self.name() == "Projects":
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 self.__readProjects()
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 else:
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 self.raiseUnexpectedStartTag(self.name())
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 self.showErrorMessage()
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 def __readProjects(self):
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 """
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 Private method to read the project infos.
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 """
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 while not self.atEnd():
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 self.readNext()
3198
8c9eb883b2a0 Fixed an issue in the multi project XML reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
64 if self.isEndElement() and self.name() == "Projects":
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 break
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 if self.isStartElement():
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 if self.name() == "Project":
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 self.__readProject()
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 else:
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 self.raiseUnexpectedStartTag(self.name())
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 def __readProject(self):
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 """
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 Private method to read the project info.
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 """
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 project = {}
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 project["master"] = self.toBool(self.attribute("isMaster", "False"))
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 while not self.atEnd():
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 self.readNext()
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 if self.isEndElement() and self.name() == "Project":
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 self.multiProject.projects.append(project)
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 break
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 if self.isStartElement():
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 if self.name() == "ProjectName":
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 project["name"] = self.readElementText()
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 elif self.name() == "ProjectFile":
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
91 project["file"] = Utilities.toNativeSeparators(
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
92 self.readElementText())
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 elif self.name() == "ProjectDescription":
605
9c7527ecbf6e Removed code to encode and decode newlines from XML stream reader and writer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 602
diff changeset
94 project["description"] = self.readElementText()
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 else:
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 self.raiseUnexpectedStartTag(self.name())

eric ide

mercurial