E5XML/ProjectWriter.py

changeset 5969
584c21b6587a
parent 5968
c5112b5cb7a9
child 6007
82d44dc0fb3b
equal deleted inserted replaced
5968:c5112b5cb7a9 5969:584c21b6587a
18 18
19 import Preferences 19 import Preferences
20 import Utilities 20 import Utilities
21 21
22 22
23 # TODO: add support for 'PROTOCOLS' (analog INTERFACES)
24 class ProjectWriter(XMLStreamWriterBase): 23 class ProjectWriter(XMLStreamWriterBase):
25 """ 24 """
26 Class implementing the writer class for writing an XML project file. 25 Class implementing the writer class for writing an XML project file.
27 """ 26 """
28 def __init__(self, device, projectName): 27 def __init__(self, device, projectName):
111 if self.pdata["EOL"] >= 0: 110 if self.pdata["EOL"] >= 0:
112 self.writeEmptyElement("Eol") 111 self.writeEmptyElement("Eol")
113 self.writeAttribute("index", str(int(self.pdata["EOL"]))) 112 self.writeAttribute("index", str(int(self.pdata["EOL"])))
114 113
115 # do the sources 114 # do the sources
116 self.writeStartElement("Sources") 115 if self.pdata["SOURCES"]:
117 for name in sorted(self.pdata["SOURCES"]): 116 self.writeStartElement("Sources")
118 self.writeTextElement( 117 for name in sorted(self.pdata["SOURCES"]):
119 "Source", Utilities.fromNativeSeparators(name)) 118 self.writeTextElement(
120 self.writeEndElement() 119 "Source", Utilities.fromNativeSeparators(name))
120 self.writeEndElement()
121 121
122 # do the forms 122 # do the forms
123 self.writeStartElement("Forms") 123 if self.pdata["FORMS"]:
124 for name in sorted(self.pdata["FORMS"]): 124 self.writeStartElement("Forms")
125 self.writeTextElement("Form", Utilities.fromNativeSeparators(name)) 125 for name in sorted(self.pdata["FORMS"]):
126 self.writeEndElement() 126 self.writeTextElement(
127 "Form", Utilities.fromNativeSeparators(name))
128 self.writeEndElement()
127 129
128 # do the translations 130 # do the translations
129 self.writeStartElement("Translations") 131 if self.pdata["TRANSLATIONS"]:
130 for name in sorted(self.pdata["TRANSLATIONS"]): 132 self.writeStartElement("Translations")
131 self.writeTextElement( 133 for name in sorted(self.pdata["TRANSLATIONS"]):
132 "Translation", Utilities.fromNativeSeparators(name)) 134 self.writeTextElement(
133 self.writeEndElement() 135 "Translation", Utilities.fromNativeSeparators(name))
136 self.writeEndElement()
134 137
135 # do the translation exceptions 138 # do the translation exceptions
136 if self.pdata["TRANSLATIONEXCEPTIONS"]: 139 if self.pdata["TRANSLATIONEXCEPTIONS"]:
137 self.writeStartElement("TranslationExceptions") 140 self.writeStartElement("TranslationExceptions")
138 for name in sorted(self.pdata["TRANSLATIONEXCEPTIONS"]): 141 for name in sorted(self.pdata["TRANSLATIONEXCEPTIONS"]):
140 "TranslationException", 143 "TranslationException",
141 Utilities.fromNativeSeparators(name)) 144 Utilities.fromNativeSeparators(name))
142 self.writeEndElement() 145 self.writeEndElement()
143 146
144 # do the resources 147 # do the resources
145 self.writeStartElement("Resources") 148 if self.pdata["RESOURCES"]:
146 for name in sorted(self.pdata["RESOURCES"]): 149 self.writeStartElement("Resources")
147 self.writeTextElement( 150 for name in sorted(self.pdata["RESOURCES"]):
148 "Resource", Utilities.fromNativeSeparators(name)) 151 self.writeTextElement(
149 self.writeEndElement() 152 "Resource", Utilities.fromNativeSeparators(name))
153 self.writeEndElement()
150 154
151 # do the interfaces (IDL) 155 # do the interfaces (IDL)
152 self.writeStartElement("Interfaces") 156 if self.pdata["INTERFACES"]:
153 for name in sorted(self.pdata["INTERFACES"]): 157 self.writeStartElement("Interfaces")
154 self.writeTextElement( 158 for name in sorted(self.pdata["INTERFACES"]):
155 "Interface", Utilities.fromNativeSeparators(name)) 159 self.writeTextElement(
156 self.writeEndElement() 160 "Interface", Utilities.fromNativeSeparators(name))
161 self.writeEndElement()
162
163 # do the protocols (protobuf)
164 if self.pdata["PROTOCOLS"]:
165 self.writeStartElement("Protocols")
166 for name in sorted(self.pdata["PROTOCOLS"]):
167 self.writeTextElement(
168 "Protocol", Utilities.fromNativeSeparators(name))
169 self.writeEndElement()
157 170
158 # do the others 171 # do the others
159 self.writeStartElement("Others") 172 if self.pdata["OTHERS"]:
160 for name in sorted(self.pdata["OTHERS"]): 173 self.writeStartElement("Others")
161 self.writeTextElement( 174 for name in sorted(self.pdata["OTHERS"]):
162 "Other", Utilities.fromNativeSeparators(name)) 175 self.writeTextElement(
163 self.writeEndElement() 176 "Other", Utilities.fromNativeSeparators(name))
177 self.writeEndElement()
164 178
165 # do the main script 179 # do the main script
166 if self.pdata["MAINSCRIPT"]: 180 if self.pdata["MAINSCRIPT"]:
167 self.writeTextElement( 181 self.writeTextElement(
168 "MainScript", 182 "MainScript",

eric ide

mercurial