src/eric7/EricXML/ProjectReader.py

branch
eric7
changeset 9209
b99e7fd55fd3
parent 8881
54e42bc2437a
child 9221
bf71ee032bb4
equal deleted inserted replaced
9208:3fc8dfeb6ebe 9209:b99e7fd55fd3
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2010 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a class for reading an XML project file.
8 """
9
10 from .Config import projectFileFormatVersion
11 from .XMLStreamReaderBase import XMLStreamReaderBase
12
13 import Utilities
14
15
16 class ProjectReader(XMLStreamReaderBase):
17 """
18 Class for reading an XML project file.
19 """
20 supportedVersions = ["4.6",
21 "5.0", "5.1",
22 "6.0", "6.1", "6.2", "6.3", "6.4", "6.5"]
23
24 def __init__(self, device, project):
25 """
26 Constructor
27
28 @param device reference to the I/O device to read from (QIODevice)
29 @param project Reference to the project object to store the
30 information into.
31 """
32 XMLStreamReaderBase.__init__(self, device)
33
34 self.project = project
35
36 self.version = ""
37
38 def readXML(self):
39 """
40 Public method to read and parse the XML document.
41 """
42 while not self.atEnd():
43 self.readNext()
44 if self.isStartElement():
45 if self.name() == "Project":
46 self.version = self.attribute(
47 "version", projectFileFormatVersion)
48 if self.version not in self.supportedVersions:
49 self.raiseUnsupportedFormatVersion(self.version)
50 elif self.name() == "Language":
51 self.project.pdata["SPELLLANGUAGE"] = (
52 self.readElementText()
53 )
54 elif self.name() == "ProjectWordList":
55 self.project.pdata["SPELLWORDS"] = (
56 Utilities.toNativeSeparators(self.readElementText())
57 )
58 elif self.name() == "ProjectExcludeList":
59 self.project.pdata["SPELLEXCLUDES"] = (
60 Utilities.toNativeSeparators(self.readElementText())
61 )
62 elif self.name() == "Hash":
63 self.project.pdata["HASH"] = self.readElementText()
64 elif self.name() == "ProgLanguage":
65 self.project.pdata["MIXEDLANGUAGE"] = int(
66 self.attribute("mixed", "0")
67 )
68 self.project.pdata["PROGLANGUAGE"] = self.readElementText()
69 if self.project.pdata["PROGLANGUAGE"] == "Python":
70 # convert Python to the more specific Python3
71 self.project.pdata["PROGLANGUAGE"] = "Python3"
72 elif self.name() == "ProjectType":
73 self.project.pdata["PROJECTTYPE"] = self.readElementText()
74 elif self.name() == "Description":
75 self.project.pdata["DESCRIPTION"] = self.readElementText()
76 elif self.name() == "Version":
77 self.project.pdata["VERSION"] = self.readElementText()
78 elif self.name() == "Author":
79 self.project.pdata["AUTHOR"] = self.readElementText()
80 elif self.name() == "Email":
81 self.project.pdata["EMAIL"] = self.readElementText()
82 elif self.name() == "TranslationPattern":
83 self.project.pdata["TRANSLATIONPATTERN"] = (
84 Utilities.toNativeSeparators(self.readElementText())
85 )
86 elif self.name() == "TranslationsBinPath":
87 self.project.pdata["TRANSLATIONSBINPATH"] = (
88 Utilities.toNativeSeparators(self.readElementText())
89 )
90 elif self.name() == "Eol":
91 self.project.pdata["EOL"] = int(
92 self.attribute("index", "0")
93 )
94 elif self.name() == "Sources":
95 self.__readFiles("Sources", "Source", "SOURCES")
96 elif self.name() == "Forms":
97 self.__readFiles("Forms", "Form", "FORMS")
98 elif self.name() == "Translations":
99 self.__readFiles(
100 "Translations", "Translation", "TRANSLATIONS")
101 elif self.name() == "TranslationExceptions":
102 self.__readFiles(
103 "TranslationExceptions", "TranslationException",
104 "TRANSLATIONEXCEPTIONS")
105 elif self.name() == "Resources":
106 self.__readFiles("Resources", "Resource", "RESOURCES")
107 elif self.name() == "Interfaces":
108 self.__readFiles("Interfaces", "Interface", "INTERFACES")
109 elif self.name() == "Protocols":
110 self.__readFiles("Protocols", "Protocol", "PROTOCOLS")
111 elif self.name() == "Others":
112 self.__readFiles("Others", "Other", "OTHERS")
113 elif self.name() == "MainScript":
114 self.project.pdata["MAINSCRIPT"] = (
115 Utilities.toNativeSeparators(self.readElementText())
116 )
117 elif self.name() == "Vcs":
118 self.__readVcs()
119 elif self.name() == "FiletypeAssociations":
120 self.__readFiletypeAssociations()
121 elif self.name() == "LexerAssociations":
122 self.__readLexerAssociations()
123 elif self.name() == "Make":
124 self.__readBasicDataField(
125 "Make", "MakeParameters", "MAKEPARAMS")
126 elif self.name() == "IdlCompiler":
127 self.__readBasicDataField(
128 "IdlCompiler", "IdlCompilerParameters", "IDLPARAMS")
129 elif self.name() == "UicCompiler":
130 self.__readBasicDataField(
131 "UicCompiler", "UicCompilerParameters", "UICPARAMS")
132 elif self.name() == "RccCompiler":
133 self.__readBasicDataField(
134 "RccCompiler", "RccCompilerParameters", "RCCPARAMS")
135 elif self.name() == "DocstringStyle":
136 self.project.pdata["DOCSTRING"] = self.readElementText()
137 elif self.name() == "ProjectTypeSpecific":
138 self.__readBasicDataField(
139 "ProjectTypeSpecific", "ProjectTypeSpecificData",
140 "PROJECTTYPESPECIFICDATA")
141 elif self.name() == "Documentation":
142 self.__readBasicDataField(
143 "Documentation", "DocumentationParams",
144 "DOCUMENTATIONPARMS")
145 elif self.name() == "Packagers":
146 self.__readBasicDataField(
147 "Packagers", "PackagersParams", "PACKAGERSPARMS")
148 elif self.name() == "Checkers":
149 self.__readBasicDataField(
150 "Checkers", "CheckersParams", "CHECKERSPARMS")
151 elif self.name() == "OtherTools":
152 self.__readBasicDataField(
153 "OtherTools", "OtherToolsParams", "OTHERTOOLSPARMS")
154 else:
155 self.raiseUnexpectedStartTag(self.name())
156
157 self.showErrorMessage()
158
159 def __readFiles(self, tag, listTag, dataKey):
160 """
161 Private method to read a list of files.
162
163 @param tag name of the list tag (string)
164 @param listTag name of the list element tag (string)
165 @param dataKey key of the project data element (string)
166 """
167 while not self.atEnd():
168 self.readNext()
169 if self.isEndElement() and self.name() == tag:
170 break
171
172 if self.isStartElement():
173 if self.name() == listTag:
174 self.project.pdata[dataKey].append(
175 Utilities.toNativeSeparators(self.readElementText()))
176 else:
177 self.raiseUnexpectedStartTag(self.name())
178
179 def __readBasicDataField(self, tag, dataTag, dataKey):
180 """
181 Private method to read a list of files.
182
183 @param tag name of the list tag (string)
184 @param dataTag name of the data tag (string)
185 @param dataKey key of the project data element (string)
186 """
187 while not self.atEnd():
188 self.readNext()
189 if self.isEndElement() and self.name() == tag:
190 break
191
192 if self.isStartElement():
193 if self.name() == dataTag:
194 self.project.pdata[dataKey] = self._readBasics()
195 else:
196 self.raiseUnexpectedStartTag(self.name())
197
198 def __readVcs(self):
199 """
200 Private method to read the VCS info.
201 """
202 while not self.atEnd():
203 self.readNext()
204 if self.isEndElement() and self.name() == "Vcs":
205 break
206
207 if self.isStartElement():
208 if self.name() == "VcsType":
209 self.project.pdata["VCS"] = self.readElementText()
210 elif self.name() == "VcsOptions":
211 self.project.pdata["VCSOPTIONS"] = self._readBasics()
212 elif self.name() == "VcsOtherData":
213 self.project.pdata["VCSOTHERDATA"] = self._readBasics()
214 else:
215 self.raiseUnexpectedStartTag(self.name())
216
217 def __readFiletypeAssociations(self):
218 """
219 Private method to read the file type associations.
220 """
221 while not self.atEnd():
222 self.readNext()
223 if self.isEndElement() and self.name() == "FiletypeAssociations":
224 break
225
226 if self.isStartElement():
227 if self.name() == "FiletypeAssociation":
228 pattern = self.attribute("pattern", "")
229 filetype = self.attribute("type", "OTHERS")
230 if pattern:
231 self.project.pdata["FILETYPES"][pattern] = filetype
232 else:
233 self.raiseUnexpectedStartTag(self.name())
234
235 def __readLexerAssociations(self):
236 """
237 Private method to read the lexer associations.
238 """
239 while not self.atEnd():
240 self.readNext()
241 if self.isEndElement() and self.name() == "LexerAssociations":
242 break
243
244 if self.isStartElement():
245 if self.name() == "LexerAssociation":
246 pattern = self.attribute("pattern", "")
247 lexer = self.attribute("lexer")
248 if pattern:
249 self.project.pdata["LEXERASSOCS"][pattern] = lexer
250 else:
251 self.raiseUnexpectedStartTag(self.name())

eric ide

mercurial