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