9 |
9 |
10 import time |
10 import time |
11 |
11 |
12 from E5Gui.E5Application import e5App |
12 from E5Gui.E5Application import e5App |
13 |
13 |
14 from .XMLWriterBase import XMLWriterBase |
14 from .XMLStreamWriterBase import XMLStreamWriterBase |
15 from .Config import projectFileFormatVersion |
15 from .Config import projectFileFormatVersion |
16 |
16 |
17 import Preferences |
17 import Preferences |
18 import Utilities |
18 import Utilities |
19 |
19 |
20 class ProjectWriter(XMLWriterBase): |
20 class ProjectWriter(XMLStreamWriterBase): |
21 """ |
21 """ |
22 Class implementing the writer class for writing an XML project file. |
22 Class implementing the writer class for writing an XML project file. |
23 """ |
23 """ |
24 def __init__(self, file, projectName): |
24 def __init__(self, device, projectName): |
25 """ |
25 """ |
26 Constructor |
26 Constructor |
27 |
27 |
28 @param file open file (like) object for writing |
28 @param device reference to the I/O device to write to (QIODevice) |
29 @param projectName name of the project (string) |
29 @param projectName name of the project (string) |
30 """ |
30 """ |
31 XMLWriterBase.__init__(self, file) |
31 XMLStreamWriterBase.__init__(self, device) |
32 |
32 |
33 self.pdata = e5App().getObject("Project").pdata |
33 self.pdata = e5App().getObject("Project").pdata |
34 self.name = projectName |
34 self.name = projectName |
35 |
35 |
36 def writeXML(self): |
36 def writeXML(self): |
37 """ |
37 """ |
38 Public method to write the XML to the file. |
38 Public method to write the XML to the file. |
39 """ |
39 """ |
40 XMLWriterBase.writeXML(self) |
40 XMLStreamWriterBase.writeXML(self) |
41 |
41 |
42 self._write('<!DOCTYPE Project SYSTEM "Project-{0}.dtd">'.format( |
42 self.writeDTD('<!DOCTYPE Project SYSTEM "Project-{0}.dtd">'.format( |
43 projectFileFormatVersion)) |
43 projectFileFormatVersion)) |
44 |
44 |
45 # add some generation comments |
45 # add some generation comments |
46 self._write("<!-- eric5 project file for project {0} -->".format(self.name)) |
46 self.writeComment(" eric5 project file for project {0} ".format(self.name)) |
47 if Preferences.getProject("XMLTimestamp"): |
47 if Preferences.getProject("XMLTimestamp"): |
48 self._write("<!-- Saved: {0} -->".format(time.strftime('%Y-%m-%d, %H:%M:%S'))) |
48 self.writeComment(" Saved: {0} ".format(time.strftime('%Y-%m-%d, %H:%M:%S'))) |
49 self._write("<!-- Copyright (C) {0} {1}, {2} -->".format( |
49 self.writeComment(" Copyright (C) {0} {1}, {2} ".format( |
50 time.strftime('%Y'), |
50 time.strftime('%Y'), |
51 self.escape(self.pdata["AUTHOR"][0]), |
51 self.escape(self.pdata["AUTHOR"][0]), |
52 self.escape(self.pdata["EMAIL"][0]))) |
52 self.escape(self.pdata["EMAIL"][0]))) |
53 |
53 |
54 # add the main tag |
54 # add the main tag |
55 self._write('<Project version="{0}">'.format(projectFileFormatVersion)) |
55 self.writeStartElement("Project") |
|
56 self.writeAttribute("version", projectFileFormatVersion) |
56 |
57 |
57 # do the language (used for spell checking) |
58 # do the language (used for spell checking) |
58 self._write(' <Language>{0}</Language>'.format(self.pdata["SPELLLANGUAGE"][0])) |
59 self.writeTextElement("Language", self.pdata["SPELLLANGUAGE"][0]) |
59 if len(self.pdata["SPELLWORDS"][0]) > 0: |
60 if len(self.pdata["SPELLWORDS"][0]) > 0: |
60 self._write(" <ProjectWordList>{0}</ProjectWordList>".format( |
61 self.writeTextElement("ProjectWordList", |
61 Utilities.fromNativeSeparators(self.pdata["SPELLWORDS"][0]))) |
62 Utilities.fromNativeSeparators(self.pdata["SPELLWORDS"][0])) |
62 if len(self.pdata["SPELLEXCLUDES"][0]) > 0: |
63 if len(self.pdata["SPELLEXCLUDES"][0]) > 0: |
63 self._write(" <ProjectExcludeList>{0}</ProjectExcludeList>".format( |
64 self.writeTextElement("ProjectExcludeList", |
64 Utilities.fromNativeSeparators(self.pdata["SPELLEXCLUDES"][0]))) |
65 Utilities.fromNativeSeparators(self.pdata["SPELLEXCLUDES"][0])) |
65 |
66 |
66 # do the hash |
67 # do the hash |
67 self._write(' <Hash>{0}</Hash>'.format(self.pdata["HASH"][0])) |
68 self.writeTextElement("Hash", self.pdata["HASH"][0]) |
68 |
69 |
69 # do the programming language |
70 # do the programming language |
70 self._write(' <ProgLanguage mixed="{0:d}">{1}</ProgLanguage>'.format( |
71 self.writeStartElement("ProgLanguage") |
71 self.pdata["MIXEDLANGUAGE"][0], self.pdata["PROGLANGUAGE"][0])) |
72 self.writeAttribute("mixed", str(int(self.pdata["MIXEDLANGUAGE"][0]))) |
|
73 self.writeCharacters(self.pdata["PROGLANGUAGE"][0]) |
|
74 self.writeEndElement() |
72 |
75 |
73 # do the UI type |
76 # do the UI type |
74 self._write(' <ProjectType>{0}</ProjectType>'.format( |
77 self.writeTextElement("ProjectType", self.pdata["PROJECTTYPE"][0]) |
75 self.pdata["PROJECTTYPE"][0])) |
|
76 |
78 |
77 # do description |
79 # do description |
78 if self.pdata["DESCRIPTION"]: |
80 if self.pdata["DESCRIPTION"]: |
79 self._write(" <Description>{0}</Description>".format( |
81 self.writeTextElement("Description", self.pdata["DESCRIPTION"][0]) |
80 self.escape(self.encodedNewLines(self.pdata["DESCRIPTION"][0])))) |
|
81 |
82 |
82 # do version, author and email |
83 # do version, author and email |
83 for key in ["VERSION", "AUTHOR", "EMAIL"]: |
84 self.writeTextElement("Version", self.pdata["VERSION"][0]) |
84 element = key.capitalize() |
85 self.writeTextElement("Author", self.pdata["AUTHOR"][0]) |
85 if self.pdata[key]: |
86 self.writeTextElement("Email", self.pdata["EMAIL"][0]) |
86 self._write(" <{0}>{1}</{0}>".format( |
|
87 element, self.escape(self.pdata[key][0]))) |
|
88 |
87 |
89 # do the translation pattern |
88 # do the translation pattern |
90 if self.pdata["TRANSLATIONPATTERN"]: |
89 if self.pdata["TRANSLATIONPATTERN"]: |
91 self._write(" <TranslationPattern>{0}</TranslationPattern>".format( |
90 self.writeTextElement("TranslationPattern", |
92 Utilities.fromNativeSeparators(self.pdata["TRANSLATIONPATTERN"][0]))) |
91 Utilities.fromNativeSeparators(self.pdata["TRANSLATIONPATTERN"][0])) |
93 |
92 |
94 # do the binary translations path |
93 # do the binary translations path |
95 if self.pdata["TRANSLATIONSBINPATH"]: |
94 if self.pdata["TRANSLATIONSBINPATH"]: |
96 self._write(" <TranslationsBinPath>{0}</TranslationsBinPath>".format( |
95 self.writeTextElement("TranslationsBinPath", |
97 Utilities.fromNativeSeparators(self.pdata["TRANSLATIONSBINPATH"][0]))) |
96 Utilities.fromNativeSeparators(self.pdata["TRANSLATIONSBINPATH"][0])) |
98 |
97 |
99 # do the eol setting |
98 # do the eol setting |
100 if self.pdata["EOL"] and self.pdata["EOL"][0]: |
99 if self.pdata["EOL"] and self.pdata["EOL"][0]: |
101 self._write(' <Eol index="{0:d}" />'.format(self.pdata["EOL"][0])) |
100 self.writeEmptyElement("Eol") |
|
101 self.writeAttribute("index", str(int(self.pdata["EOL"][0]))) |
102 |
102 |
103 # do the sources |
103 # do the sources |
104 self._write(" <Sources>") |
104 self.writeStartElement("Sources") |
105 for name in self.pdata["SOURCES"]: |
105 for name in self.pdata["SOURCES"]: |
106 self._write(" <Source>{0}</Source>".format( |
106 self.writeTextElement("Source", Utilities.fromNativeSeparators(name)) |
107 Utilities.fromNativeSeparators(name))) |
107 self.writeEndElement() |
108 self._write(" </Sources>") |
|
109 |
108 |
110 # do the forms |
109 # do the forms |
111 self._write(" <Forms>") |
110 self.writeStartElement("Forms") |
112 for name in self.pdata["FORMS"]: |
111 for name in self.pdata["FORMS"]: |
113 self._write(" <Form>{0}</Form>".format( |
112 self.writeTextElement("Form", Utilities.fromNativeSeparators(name)) |
114 Utilities.fromNativeSeparators(name))) |
113 self.writeEndElement() |
115 self._write(" </Forms>") |
|
116 |
114 |
117 # do the translations |
115 # do the translations |
118 self._write(" <Translations>") |
116 self.writeStartElement("Translations") |
119 for name in self.pdata["TRANSLATIONS"]: |
117 for name in self.pdata["TRANSLATIONS"]: |
120 self._write(" <Translation>{0}</Translation>".format( |
118 self.writeTextElement("Translation", Utilities.fromNativeSeparators(name)) |
121 Utilities.fromNativeSeparators(name))) |
119 self.writeEndElement() |
122 self._write(" </Translations>") |
|
123 |
120 |
124 # do the translation exceptions |
121 # do the translation exceptions |
125 if self.pdata["TRANSLATIONEXCEPTIONS"]: |
122 if self.pdata["TRANSLATIONEXCEPTIONS"]: |
126 self._write(" <TranslationExceptions>") |
123 self.writeStartElement("TranslationExceptions") |
127 for name in self.pdata["TRANSLATIONEXCEPTIONS"]: |
124 for name in self.pdata["TRANSLATIONEXCEPTIONS"]: |
128 self._write(" <TranslationException>{0}</TranslationException>".format( |
125 self.writeTextElement("TranslationException", |
129 Utilities.fromNativeSeparators(name))) |
126 Utilities.fromNativeSeparators(name)) |
130 self._write(" </TranslationExceptions>") |
127 self.writeEndElement() |
131 |
128 |
132 # do the resources |
129 # do the resources |
133 self._write(" <Resources>") |
130 self.writeStartElement("Resources") |
134 for name in self.pdata["RESOURCES"]: |
131 for name in self.pdata["RESOURCES"]: |
135 self._write(" <Resource>{0}</Resource>".format( |
132 self.writeTextElement("Resource", Utilities.fromNativeSeparators(name)) |
136 Utilities.fromNativeSeparators(name))) |
133 self.writeEndElement() |
137 self._write(" </Resources>") |
|
138 |
134 |
139 # do the interfaces (IDL) |
135 # do the interfaces (IDL) |
140 self._write(" <Interfaces>") |
136 self.writeStartElement("Interfaces") |
141 for name in self.pdata["INTERFACES"]: |
137 for name in self.pdata["INTERFACES"]: |
142 self._write(" <Interface>{0}</Interface>".format( |
138 self.writeTextElement("Interface", Utilities.fromNativeSeparators(name)) |
143 Utilities.fromNativeSeparators(name))) |
139 self.writeEndElement() |
144 self._write(" </Interfaces>") |
|
145 |
140 |
146 # do the others |
141 # do the others |
147 self._write(" <Others>") |
142 self.writeStartElement("Others") |
148 for name in self.pdata["OTHERS"]: |
143 for name in self.pdata["OTHERS"]: |
149 self._write(" <Other>{0}</Other>".format( |
144 self.writeTextElement("Other", Utilities.fromNativeSeparators(name)) |
150 Utilities.fromNativeSeparators(name))) |
145 self.writeEndElement() |
151 self._write(" </Others>") |
|
152 |
146 |
153 # do the main script |
147 # do the main script |
154 if self.pdata["MAINSCRIPT"]: |
148 if self.pdata["MAINSCRIPT"]: |
155 self._write(" <MainScript>{0}</MainScript>".format( |
149 self.writeTextElement("MainScript", |
156 Utilities.fromNativeSeparators(self.pdata["MAINSCRIPT"][0]))) |
150 Utilities.fromNativeSeparators(self.pdata["MAINSCRIPT"][0])) |
157 |
151 |
158 # do the vcs stuff |
152 # do the vcs stuff |
159 self._write(" <Vcs>") |
153 self.writeStartElement("Vcs") |
160 if self.pdata["VCS"]: |
154 if self.pdata["VCS"]: |
161 self._write(" <VcsType>{0}</VcsType>".format(self.pdata["VCS"][0])) |
155 self.writeTextElement("VcsType", self.pdata["VCS"][0]) |
162 if self.pdata["VCSOPTIONS"]: |
156 if self.pdata["VCSOPTIONS"]: |
163 self._write(" <VcsOptions>") |
157 self.writeBasics("VcsOptions", self.pdata["VCSOPTIONS"][0]) |
164 self._writeBasics(self.pdata["VCSOPTIONS"][0], 3) |
|
165 self._write(" </VcsOptions>") |
|
166 if self.pdata["VCSOTHERDATA"]: |
158 if self.pdata["VCSOTHERDATA"]: |
167 self._write(" <VcsOtherData>") |
159 self.writeBasics("VcsOtherData", self.pdata["VCSOTHERDATA"][0]) |
168 self._writeBasics(self.pdata["VCSOTHERDATA"][0], 3) |
160 self.writeEndElement() |
169 self._write(" </VcsOtherData>") |
|
170 self._write(" </Vcs>") |
|
171 |
161 |
172 # do the filetype associations |
162 # do the filetype associations |
173 self._write(" <FiletypeAssociations>") |
163 self.writeStartElement("FiletypeAssociations") |
174 for pattern, filetype in list(self.pdata["FILETYPES"].items()): |
164 for pattern, filetype in list(self.pdata["FILETYPES"].items()): |
175 self._write(' <FiletypeAssociation pattern="{0}" type="{1}" />'.format( |
165 self.writeEmptyElement("FiletypeAssociation") |
176 pattern, filetype)) |
166 self.writeAttribute("pattern", pattern) |
177 self._write(" </FiletypeAssociations>") |
167 self.writeAttribute("type", filetype) |
|
168 self.writeEndElement() |
178 |
169 |
179 # do the lexer associations |
170 # do the lexer associations |
180 if self.pdata["LEXERASSOCS"]: |
171 if self.pdata["LEXERASSOCS"]: |
181 self._write(" <LexerAssociations>") |
172 self.writeStartElement("LexerAssociations") |
182 for pattern, lexer in list(self.pdata["LEXERASSOCS"].items()): |
173 for pattern, lexer in list(self.pdata["LEXERASSOCS"].items()): |
183 self._write(' <LexerAssociation pattern="{0}" lexer="{1}" />'.format( |
174 self.writeEmptyElement("LexerAssociation") |
184 pattern, lexer)) |
175 self.writeAttribute("pattern", pattern) |
185 self._write(" </LexerAssociations>") |
176 self.writeAttribute("lexer", lexer) |
|
177 self.writeEndElement() |
186 |
178 |
187 # do the extra project data stuff |
179 # do the extra project data stuff |
188 if len(self.pdata["PROJECTTYPESPECIFICDATA"]): |
180 if len(self.pdata["PROJECTTYPESPECIFICDATA"]): |
189 self._write(" <ProjectTypeSpecific>") |
181 self.writeStartElement("ProjectTypeSpecific") |
190 if self.pdata["PROJECTTYPESPECIFICDATA"]: |
182 if self.pdata["PROJECTTYPESPECIFICDATA"]: |
191 self._write(" <ProjectTypeSpecificData>") |
183 self.writeBasics("ProjectTypeSpecificData", |
192 self._writeBasics(self.pdata["PROJECTTYPESPECIFICDATA"], 3) |
184 self.pdata["PROJECTTYPESPECIFICDATA"]) |
193 self._write(" </ProjectTypeSpecificData>") |
185 self.writeEndElement() |
194 self._write(" </ProjectTypeSpecific>") |
|
195 |
186 |
196 # do the documentation generators stuff |
187 # do the documentation generators stuff |
197 if len(self.pdata["DOCUMENTATIONPARMS"]): |
188 if len(self.pdata["DOCUMENTATIONPARMS"]): |
198 self._write(" <Documentation>") |
189 self.writeStartElement("Documentation") |
199 if self.pdata["DOCUMENTATIONPARMS"]: |
190 if self.pdata["DOCUMENTATIONPARMS"]: |
200 self._write(" <DocumentationParams>") |
191 self.writeBasics("DocumentationParams", |
201 self._writeBasics(self.pdata["DOCUMENTATIONPARMS"], 3) |
192 self.pdata["DOCUMENTATIONPARMS"]) |
202 self._write(" </DocumentationParams>") |
193 self.writeEndElement() |
203 self._write(" </Documentation>") |
|
204 |
194 |
205 # do the packagers stuff |
195 # do the packagers stuff |
206 if len(self.pdata["PACKAGERSPARMS"]): |
196 if len(self.pdata["PACKAGERSPARMS"]): |
207 self._write(" <Packagers>") |
197 self.writeStartElement("Packagers") |
208 if self.pdata["PACKAGERSPARMS"]: |
198 if self.pdata["PACKAGERSPARMS"]: |
209 self._write(" <PackagersParams>") |
199 self.writeBasics("PackagersParams", |
210 self._writeBasics(self.pdata["PACKAGERSPARMS"], 3) |
200 self.pdata["PACKAGERSPARMS"]) |
211 self._write(" </PackagersParams>") |
201 self.writeEndElement() |
212 self._write(" </Packagers>") |
|
213 |
202 |
214 # do the checkers stuff |
203 # do the checkers stuff |
215 if len(self.pdata["CHECKERSPARMS"]): |
204 if len(self.pdata["CHECKERSPARMS"]): |
216 self._write(" <Checkers>") |
205 self.writeStartElement("Checkers") |
217 if self.pdata["CHECKERSPARMS"]: |
206 if self.pdata["CHECKERSPARMS"]: |
218 self._write(" <CheckersParams>") |
207 self.writeBasics("CheckersParams", |
219 self._writeBasics(self.pdata["CHECKERSPARMS"], 3) |
208 self.pdata["CHECKERSPARMS"]) |
220 self._write(" </CheckersParams>") |
209 self.writeEndElement() |
221 self._write(" </Checkers>") |
|
222 |
210 |
223 # do the other tools stuff |
211 # do the other tools stuff |
224 if len(self.pdata["OTHERTOOLSPARMS"]): |
212 if len(self.pdata["OTHERTOOLSPARMS"]): |
225 self._write(" <OtherTools>") |
213 self.writeStartElement("OtherTools") |
226 if self.pdata["OTHERTOOLSPARMS"]: |
214 if self.pdata["OTHERTOOLSPARMS"]: |
227 self._write(" <OtherToolsParams>") |
215 self.writeBasics("OtherToolsParams", |
228 self._writeBasics(self.pdata["OTHERTOOLSPARMS"], 3) |
216 self.pdata["OTHERTOOLSPARMS"]) |
229 self._write(" </OtherToolsParams>") |
217 self.writeEndElement() |
230 self._write(" </OtherTools>") |
218 |
231 |
219 self.writeEndElement() |
232 self._write("</Project>", newline = False) |
220 self.writeEndDocument() |