eric6/E5XML/MultiProjectReader.py

Sun, 02 Feb 2020 11:04:32 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 02 Feb 2020 11:04:32 +0100
changeset 7380
c99320e859ca
parent 7360
9190402e4505
child 7780
41420f82c0ac
permissions
-rw-r--r--

Fixed an issue related to showing the application name in the menu bar of Gnome desktop under Wayland.

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
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
3 # Copyright (c) 2010 - 2020 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
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
10
3833
64b5f5fa3b00 Changed multi project files to contain relative paths to the contained project files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3656
diff changeset
11 import os
64b5f5fa3b00 Changed multi project files to contain relative paths to the contained project files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3656
diff changeset
12
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 from .Config import multiProjectFileFormatVersion
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 from .XMLStreamReaderBase import XMLStreamReaderBase
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 import Utilities
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
18
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 class MultiProjectReader(XMLStreamReaderBase):
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 """
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 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
22 """
3545
4a0bbb2d5457 Improved the multi project manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
23 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
24
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 def __init__(self, device, multiProject):
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 Constructor
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 @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
30 @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
31 information into.
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 """
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 XMLStreamReaderBase.__init__(self, device)
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 self.multiProject = multiProject
3833
64b5f5fa3b00 Changed multi project files to contain relative paths to the contained project files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3656
diff changeset
36 self.path = os.path.dirname(device.fileName())
602
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 self.version = ""
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 def readXML(self):
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 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
43 """
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 while not self.atEnd():
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 self.readNext()
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 if self.isStartElement():
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 if self.name() == "MultiProject":
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
48 self.version = self.attribute(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
49 "version",
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 multiProjectFileFormatVersion)
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 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
52 self.raiseUnsupportedFormatVersion(self.version)
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 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
54 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
55 elif self.name() == "Projects":
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 self.__readProjects()
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 else:
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 self.raiseUnexpectedStartTag(self.name())
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 self.showErrorMessage()
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 def __readProjects(self):
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 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
65 """
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 while not self.atEnd():
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 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
68 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
69 break
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 if self.isStartElement():
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 if self.name() == "Project":
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 self.__readProject()
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 else:
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 self.raiseUnexpectedStartTag(self.name())
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 def __readProject(self):
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 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
80 """
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 project = {}
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 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
84 uid = self.attribute("uid", "")
4a0bbb2d5457 Improved the multi project manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
85 if uid:
4a0bbb2d5457 Improved the multi project manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
86 project["uid"] = uid
4a0bbb2d5457 Improved the multi project manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
87 else:
4a0bbb2d5457 Improved the multi project manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
88 # upgrade from pre 5.1 format
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3545
diff changeset
89 from PyQt5.QtCore import QUuid
3545
4a0bbb2d5457 Improved the multi project manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
90 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
91
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 while not self.atEnd():
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 self.readNext()
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 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
95 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
96 # 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
97 project["category"] = ""
5889
092d06e0193f Fixed some weaknesses in the multi project code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
98 self.multiProject.addProject(project)
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 break
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 if self.isStartElement():
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 if self.name() == "ProjectName":
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 project["name"] = self.readElementText()
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 elif self.name() == "ProjectFile":
3833
64b5f5fa3b00 Changed multi project files to contain relative paths to the contained project files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3656
diff changeset
105 project["file"] = Utilities.absoluteUniversalPath(
64b5f5fa3b00 Changed multi project files to contain relative paths to the contained project files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3656
diff changeset
106 self.readElementText(), self.path)
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 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
108 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
109 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
110 project["category"] = self.readElementText()
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 else:
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 self.raiseUnexpectedStartTag(self.name())

eric ide

mercurial