1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2004 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the writer class for writing an XML project file. |
|
8 """ |
|
9 |
|
10 import time |
|
11 |
|
12 from E5Gui.E5Application import e5App |
|
13 |
|
14 from .XMLStreamWriterBase import XMLStreamWriterBase |
|
15 from .Config import ( |
|
16 projectFileFormatVersion, projectFileFormatVersionRcc, |
|
17 projectFileFormatVersionUic, projectFileFormatVersionIdl, |
|
18 projectFileFormatVersionMake, projectFileFormatVersionProto, |
|
19 projectFileFormatVersionAlt |
|
20 ) |
|
21 |
|
22 import Preferences |
|
23 import Utilities |
|
24 |
|
25 |
|
26 class ProjectWriter(XMLStreamWriterBase): |
|
27 """ |
|
28 Class implementing the writer class for writing an XML project file. |
|
29 """ |
|
30 def __init__(self, device, projectName): |
|
31 """ |
|
32 Constructor |
|
33 |
|
34 @param device reference to the I/O device to write to (QIODevice) |
|
35 @param projectName name of the project (string) |
|
36 """ |
|
37 XMLStreamWriterBase.__init__(self, device) |
|
38 |
|
39 self.pdata = e5App().getObject("Project").pdata |
|
40 self.name = projectName |
|
41 |
|
42 def writeXML(self): |
|
43 """ |
|
44 Public method to write the XML to the file. |
|
45 """ |
|
46 XMLStreamWriterBase.writeXML(self) |
|
47 |
|
48 project = e5App().getObject("Project") |
|
49 if not project.hasDefaultDocstringParameter(): |
|
50 fileFormatVersion = projectFileFormatVersion |
|
51 elif not project.hasDefaultRccCompilerParameters(): |
|
52 fileFormatVersion = projectFileFormatVersionRcc |
|
53 elif not project.hasDefaultUicCompilerParameters(): |
|
54 fileFormatVersion = projectFileFormatVersionUic |
|
55 elif not project.hasDefaultIdlCompilerParameters(): |
|
56 fileFormatVersion = projectFileFormatVersionIdl |
|
57 elif not project.hasDefaultMakeParameters(): |
|
58 fileFormatVersion = projectFileFormatVersionMake |
|
59 elif self.pdata["PROTOCOLS"]: |
|
60 fileFormatVersion = projectFileFormatVersionProto |
|
61 else: |
|
62 fileFormatVersion = projectFileFormatVersionAlt |
|
63 |
|
64 self.writeDTD('<!DOCTYPE Project SYSTEM "Project-{0}.dtd">'.format( |
|
65 fileFormatVersion)) |
|
66 |
|
67 # add some generation comments |
|
68 self.writeComment( |
|
69 " eric project file for project {0} ".format(self.name)) |
|
70 if Preferences.getProject("TimestampFile"): |
|
71 self.writeComment( |
|
72 " Saved: {0} ".format(time.strftime('%Y-%m-%d, %H:%M:%S'))) |
|
73 self.writeComment(" Copyright (C) {0} {1}, {2} ".format( |
|
74 time.strftime('%Y'), |
|
75 self.pdata["AUTHOR"], |
|
76 self.pdata["EMAIL"])) |
|
77 |
|
78 # add the main tag |
|
79 self.writeStartElement("Project") |
|
80 self.writeAttribute("version", fileFormatVersion) |
|
81 |
|
82 # do the language (used for spell checking) |
|
83 self.writeTextElement("Language", self.pdata["SPELLLANGUAGE"]) |
|
84 if self.pdata["SPELLWORDS"]: |
|
85 self.writeTextElement( |
|
86 "ProjectWordList", |
|
87 Utilities.fromNativeSeparators(self.pdata["SPELLWORDS"])) |
|
88 if self.pdata["SPELLEXCLUDES"]: |
|
89 self.writeTextElement( |
|
90 "ProjectExcludeList", |
|
91 Utilities.fromNativeSeparators(self.pdata["SPELLEXCLUDES"])) |
|
92 |
|
93 # do the hash |
|
94 self.writeTextElement("Hash", self.pdata["HASH"]) |
|
95 |
|
96 # do the programming language |
|
97 self.writeStartElement("ProgLanguage") |
|
98 self.writeAttribute("mixed", str(int(self.pdata["MIXEDLANGUAGE"]))) |
|
99 self.writeCharacters(self.pdata["PROGLANGUAGE"]) |
|
100 self.writeEndElement() |
|
101 |
|
102 # do the UI type |
|
103 self.writeTextElement("ProjectType", self.pdata["PROJECTTYPE"]) |
|
104 |
|
105 # do description |
|
106 if self.pdata["DESCRIPTION"]: |
|
107 self.writeTextElement("Description", self.pdata["DESCRIPTION"]) |
|
108 |
|
109 # do version, author and email |
|
110 self.writeTextElement("Version", self.pdata["VERSION"]) |
|
111 self.writeTextElement("Author", self.pdata["AUTHOR"]) |
|
112 self.writeTextElement("Email", self.pdata["EMAIL"]) |
|
113 |
|
114 # do the translation pattern |
|
115 if self.pdata["TRANSLATIONPATTERN"]: |
|
116 self.writeTextElement( |
|
117 "TranslationPattern", |
|
118 Utilities.fromNativeSeparators( |
|
119 self.pdata["TRANSLATIONPATTERN"])) |
|
120 |
|
121 # do the binary translations path |
|
122 if self.pdata["TRANSLATIONSBINPATH"]: |
|
123 self.writeTextElement( |
|
124 "TranslationsBinPath", |
|
125 Utilities.fromNativeSeparators( |
|
126 self.pdata["TRANSLATIONSBINPATH"])) |
|
127 |
|
128 # do the eol setting |
|
129 if self.pdata["EOL"] >= 0: |
|
130 self.writeEmptyElement("Eol") |
|
131 self.writeAttribute("index", str(int(self.pdata["EOL"]))) |
|
132 |
|
133 # do the sources |
|
134 if self.pdata["SOURCES"]: |
|
135 self.writeStartElement("Sources") |
|
136 for name in sorted(self.pdata["SOURCES"]): |
|
137 self.writeTextElement( |
|
138 "Source", Utilities.fromNativeSeparators(name)) |
|
139 self.writeEndElement() |
|
140 |
|
141 # do the forms |
|
142 if self.pdata["FORMS"]: |
|
143 self.writeStartElement("Forms") |
|
144 for name in sorted(self.pdata["FORMS"]): |
|
145 self.writeTextElement( |
|
146 "Form", Utilities.fromNativeSeparators(name)) |
|
147 self.writeEndElement() |
|
148 |
|
149 # do the translations |
|
150 if self.pdata["TRANSLATIONS"]: |
|
151 self.writeStartElement("Translations") |
|
152 for name in sorted(self.pdata["TRANSLATIONS"]): |
|
153 self.writeTextElement( |
|
154 "Translation", Utilities.fromNativeSeparators(name)) |
|
155 self.writeEndElement() |
|
156 |
|
157 # do the translation exceptions |
|
158 if self.pdata["TRANSLATIONEXCEPTIONS"]: |
|
159 self.writeStartElement("TranslationExceptions") |
|
160 for name in sorted(self.pdata["TRANSLATIONEXCEPTIONS"]): |
|
161 self.writeTextElement( |
|
162 "TranslationException", |
|
163 Utilities.fromNativeSeparators(name)) |
|
164 self.writeEndElement() |
|
165 |
|
166 # do the resources |
|
167 if self.pdata["RESOURCES"]: |
|
168 self.writeStartElement("Resources") |
|
169 for name in sorted(self.pdata["RESOURCES"]): |
|
170 self.writeTextElement( |
|
171 "Resource", Utilities.fromNativeSeparators(name)) |
|
172 self.writeEndElement() |
|
173 |
|
174 # do the interfaces (IDL) |
|
175 if self.pdata["INTERFACES"]: |
|
176 self.writeStartElement("Interfaces") |
|
177 for name in sorted(self.pdata["INTERFACES"]): |
|
178 self.writeTextElement( |
|
179 "Interface", Utilities.fromNativeSeparators(name)) |
|
180 self.writeEndElement() |
|
181 |
|
182 # do the protocols (protobuf) |
|
183 if self.pdata["PROTOCOLS"]: |
|
184 self.writeStartElement("Protocols") |
|
185 for name in sorted(self.pdata["PROTOCOLS"]): |
|
186 self.writeTextElement( |
|
187 "Protocol", Utilities.fromNativeSeparators(name)) |
|
188 self.writeEndElement() |
|
189 |
|
190 # do the others |
|
191 if self.pdata["OTHERS"]: |
|
192 self.writeStartElement("Others") |
|
193 for name in sorted(self.pdata["OTHERS"]): |
|
194 self.writeTextElement( |
|
195 "Other", Utilities.fromNativeSeparators(name)) |
|
196 self.writeEndElement() |
|
197 |
|
198 # do the main script |
|
199 if self.pdata["MAINSCRIPT"]: |
|
200 self.writeTextElement( |
|
201 "MainScript", |
|
202 Utilities.fromNativeSeparators(self.pdata["MAINSCRIPT"])) |
|
203 |
|
204 # do the vcs stuff |
|
205 self.writeStartElement("Vcs") |
|
206 if self.pdata["VCS"]: |
|
207 self.writeTextElement("VcsType", self.pdata["VCS"]) |
|
208 if self.pdata["VCSOPTIONS"]: |
|
209 self.writeBasics("VcsOptions", self.pdata["VCSOPTIONS"]) |
|
210 if self.pdata["VCSOTHERDATA"]: |
|
211 self.writeBasics("VcsOtherData", self.pdata["VCSOTHERDATA"]) |
|
212 self.writeEndElement() |
|
213 |
|
214 # do the filetype associations |
|
215 self.writeStartElement("FiletypeAssociations") |
|
216 for pattern, filetype in sorted(self.pdata["FILETYPES"].items()): |
|
217 self.writeEmptyElement("FiletypeAssociation") |
|
218 self.writeAttribute("pattern", pattern) |
|
219 self.writeAttribute("type", filetype) |
|
220 self.writeEndElement() |
|
221 |
|
222 # do the lexer associations |
|
223 if self.pdata["LEXERASSOCS"]: |
|
224 self.writeStartElement("LexerAssociations") |
|
225 for pattern, lexer in sorted(self.pdata["LEXERASSOCS"].items()): |
|
226 self.writeEmptyElement("LexerAssociation") |
|
227 self.writeAttribute("pattern", pattern) |
|
228 self.writeAttribute("lexer", lexer) |
|
229 self.writeEndElement() |
|
230 |
|
231 # do the 'make' parameters |
|
232 if not e5App().getObject("Project").hasDefaultMakeParameters(): |
|
233 self.writeStartElement("Make") |
|
234 self.writeBasics("MakeParameters", self.pdata["MAKEPARAMS"]) |
|
235 self.writeEndElement() |
|
236 |
|
237 # do the 'IDL' parameters |
|
238 if not e5App().getObject("Project").hasDefaultIdlCompilerParameters(): |
|
239 self.writeStartElement("IdlCompiler") |
|
240 self.writeBasics("IdlCompilerParameters", self.pdata["IDLPARAMS"]) |
|
241 self.writeEndElement() |
|
242 |
|
243 # do the 'uic' parameters |
|
244 if not e5App().getObject("Project").hasDefaultUicCompilerParameters(): |
|
245 self.writeStartElement("UicCompiler") |
|
246 self.writeBasics("UicCompilerParameters", self.pdata["UICPARAMS"]) |
|
247 self.writeEndElement() |
|
248 |
|
249 # do the 'rcc' parameters |
|
250 if not e5App().getObject("Project").hasDefaultRccCompilerParameters(): |
|
251 self.writeStartElement("RccCompiler") |
|
252 self.writeBasics("RccCompilerParameters", self.pdata["RCCPARAMS"]) |
|
253 self.writeEndElement() |
|
254 |
|
255 # do the 'docstring' parameter |
|
256 if not e5App().getObject("Project").hasDefaultDocstringParameter(): |
|
257 self.writeTextElement("DocstringStyle", self.pdata["DOCSTRING"]) |
|
258 |
|
259 # do the extra project data stuff |
|
260 if len(self.pdata["PROJECTTYPESPECIFICDATA"]): |
|
261 self.writeStartElement("ProjectTypeSpecific") |
|
262 if self.pdata["PROJECTTYPESPECIFICDATA"]: |
|
263 self.writeBasics( |
|
264 "ProjectTypeSpecificData", |
|
265 self.pdata["PROJECTTYPESPECIFICDATA"]) |
|
266 self.writeEndElement() |
|
267 |
|
268 # do the documentation generators stuff |
|
269 if len(self.pdata["DOCUMENTATIONPARMS"]): |
|
270 self.writeStartElement("Documentation") |
|
271 if self.pdata["DOCUMENTATIONPARMS"]: |
|
272 self.writeBasics( |
|
273 "DocumentationParams", self.pdata["DOCUMENTATIONPARMS"]) |
|
274 self.writeEndElement() |
|
275 |
|
276 # do the packagers stuff |
|
277 if len(self.pdata["PACKAGERSPARMS"]): |
|
278 self.writeStartElement("Packagers") |
|
279 if self.pdata["PACKAGERSPARMS"]: |
|
280 self.writeBasics( |
|
281 "PackagersParams", self.pdata["PACKAGERSPARMS"]) |
|
282 self.writeEndElement() |
|
283 |
|
284 # do the checkers stuff |
|
285 if len(self.pdata["CHECKERSPARMS"]): |
|
286 self.writeStartElement("Checkers") |
|
287 if self.pdata["CHECKERSPARMS"]: |
|
288 self.writeBasics( |
|
289 "CheckersParams", self.pdata["CHECKERSPARMS"]) |
|
290 self.writeEndElement() |
|
291 |
|
292 # do the other tools stuff |
|
293 if len(self.pdata["OTHERTOOLSPARMS"]): |
|
294 self.writeStartElement("OtherTools") |
|
295 if self.pdata["OTHERTOOLSPARMS"]: |
|
296 self.writeBasics( |
|
297 "OtherToolsParams", self.pdata["OTHERTOOLSPARMS"]) |
|
298 self.writeEndElement() |
|
299 |
|
300 self.writeEndElement() |
|
301 self.writeEndDocument() |
|