eric6/E5XML/ProjectWriter.py

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

eric ide

mercurial