E5XML/MultiProjectReader.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 3656
441956d8fce5
child 3833
64b5f5fa3b00
permissions
-rw-r--r--

Continued renaming eric5 for PyQt5 to eric6.

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
3145
a9de05d4a22f # __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3058
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
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 from .Config import multiProjectFileFormatVersion
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 from .XMLStreamReaderBase import XMLStreamReaderBase
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 import Utilities
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
17
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 class MultiProjectReader(XMLStreamReaderBase):
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 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
21 """
3545
4a0bbb2d5457 Improved the multi project manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
22 supportedVersions = ["4.2", "5.0", "5.1"]
602
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 def __init__(self, device, multiProject):
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 Constructor
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 @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
29 @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
30 information into.
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 XMLStreamReaderBase.__init__(self, device)
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.multiProject = multiProject
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 self.version = ""
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 def readXML(self):
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 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
41 """
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 while not self.atEnd():
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 self.readNext()
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 if self.isStartElement():
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 if self.name() == "MultiProject":
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
46 self.version = self.attribute(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
47 "version",
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 multiProjectFileFormatVersion)
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 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
50 self.raiseUnsupportedFormatVersion(self.version)
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 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
52 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
53 elif self.name() == "Projects":
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 self.__readProjects()
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 else:
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 self.raiseUnexpectedStartTag(self.name())
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 self.showErrorMessage()
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 def __readProjects(self):
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 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
63 """
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 while not self.atEnd():
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 self.readNext()
3197
4103c8013c36 Added support for the categorisation of projects to multi projects and changed the multi project file format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
66 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
67 break
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 if self.isStartElement():
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 if self.name() == "Project":
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 self.__readProject()
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 else:
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 self.raiseUnexpectedStartTag(self.name())
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 def __readProject(self):
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 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
78 """
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 project = {}
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 project["master"] = self.toBool(self.attribute("isMaster", "False"))
3545
4a0bbb2d5457 Improved the multi project manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
82 uid = self.attribute("uid", "")
4a0bbb2d5457 Improved the multi project manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
83 if uid:
4a0bbb2d5457 Improved the multi project manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
84 project["uid"] = uid
4a0bbb2d5457 Improved the multi project manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
85 else:
4a0bbb2d5457 Improved the multi project manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
86 # upgrade from pre 5.1 format
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3545
diff changeset
87 from PyQt5.QtCore import QUuid
3545
4a0bbb2d5457 Improved the multi project manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
88 project["uid"] = QUuid.createUuid().toString()
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 while not self.atEnd():
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 self.readNext()
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 if self.isEndElement() and self.name() == "Project":
3197
4103c8013c36 Added support for the categorisation of projects to multi projects and changed the multi project file format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
93 if 'category' not in project:
4103c8013c36 Added support for the categorisation of projects to multi projects and changed the multi project file format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
94 # upgrade from 4.2 format
4103c8013c36 Added support for the categorisation of projects to multi projects and changed the multi project file format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
95 project["category"] = ""
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 self.multiProject.projects.append(project)
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 break
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 if self.isStartElement():
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 if self.name() == "ProjectName":
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 project["name"] = self.readElementText()
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 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
103 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
104 self.readElementText())
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 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
106 project["description"] = self.readElementText()
3197
4103c8013c36 Added support for the categorisation of projects to multi projects and changed the multi project file format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
107 elif self.name() == "ProjectCategory":
4103c8013c36 Added support for the categorisation of projects to multi projects and changed the multi project file format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
108 project["category"] = self.readElementText()
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 else:
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 self.raiseUnexpectedStartTag(self.name())

eric ide

mercurial