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