E5XML/ProjectWriter.py

changeset 5969
584c21b6587a
parent 5968
c5112b5cb7a9
child 6007
82d44dc0fb3b
diff -r c5112b5cb7a9 -r 584c21b6587a E5XML/ProjectWriter.py
--- a/E5XML/ProjectWriter.py	Sun Nov 12 19:42:02 2017 +0100
+++ b/E5XML/ProjectWriter.py	Mon Nov 13 20:20:06 2017 +0100
@@ -20,7 +20,6 @@
 import Utilities
 
 
-# TODO: add support for 'PROTOCOLS' (analog INTERFACES)
 class ProjectWriter(XMLStreamWriterBase):
     """
     Class implementing the writer class for writing an XML project file.
@@ -113,24 +112,28 @@
             self.writeAttribute("index", str(int(self.pdata["EOL"])))
         
         # do the sources
-        self.writeStartElement("Sources")
-        for name in sorted(self.pdata["SOURCES"]):
-            self.writeTextElement(
-                "Source", Utilities.fromNativeSeparators(name))
-        self.writeEndElement()
+        if self.pdata["SOURCES"]:
+            self.writeStartElement("Sources")
+            for name in sorted(self.pdata["SOURCES"]):
+                self.writeTextElement(
+                    "Source", Utilities.fromNativeSeparators(name))
+            self.writeEndElement()
         
         # do the forms
-        self.writeStartElement("Forms")
-        for name in sorted(self.pdata["FORMS"]):
-            self.writeTextElement("Form", Utilities.fromNativeSeparators(name))
-        self.writeEndElement()
+        if self.pdata["FORMS"]:
+            self.writeStartElement("Forms")
+            for name in sorted(self.pdata["FORMS"]):
+                self.writeTextElement(
+                    "Form", Utilities.fromNativeSeparators(name))
+            self.writeEndElement()
         
         # do the translations
-        self.writeStartElement("Translations")
-        for name in sorted(self.pdata["TRANSLATIONS"]):
-            self.writeTextElement(
-                "Translation", Utilities.fromNativeSeparators(name))
-        self.writeEndElement()
+        if self.pdata["TRANSLATIONS"]:
+            self.writeStartElement("Translations")
+            for name in sorted(self.pdata["TRANSLATIONS"]):
+                self.writeTextElement(
+                    "Translation", Utilities.fromNativeSeparators(name))
+            self.writeEndElement()
         
         # do the translation exceptions
         if self.pdata["TRANSLATIONEXCEPTIONS"]:
@@ -142,25 +145,36 @@
             self.writeEndElement()
         
         # do the resources
-        self.writeStartElement("Resources")
-        for name in sorted(self.pdata["RESOURCES"]):
-            self.writeTextElement(
-                "Resource", Utilities.fromNativeSeparators(name))
-        self.writeEndElement()
+        if self.pdata["RESOURCES"]:
+            self.writeStartElement("Resources")
+            for name in sorted(self.pdata["RESOURCES"]):
+                self.writeTextElement(
+                    "Resource", Utilities.fromNativeSeparators(name))
+            self.writeEndElement()
         
         # do the interfaces (IDL)
-        self.writeStartElement("Interfaces")
-        for name in sorted(self.pdata["INTERFACES"]):
-            self.writeTextElement(
-                "Interface", Utilities.fromNativeSeparators(name))
-        self.writeEndElement()
+        if self.pdata["INTERFACES"]:
+            self.writeStartElement("Interfaces")
+            for name in sorted(self.pdata["INTERFACES"]):
+                self.writeTextElement(
+                    "Interface", Utilities.fromNativeSeparators(name))
+            self.writeEndElement()
+        
+        # do the protocols (protobuf)
+        if self.pdata["PROTOCOLS"]:
+            self.writeStartElement("Protocols")
+            for name in sorted(self.pdata["PROTOCOLS"]):
+                self.writeTextElement(
+                    "Protocol", Utilities.fromNativeSeparators(name))
+            self.writeEndElement()
         
         # do the others
-        self.writeStartElement("Others")
-        for name in sorted(self.pdata["OTHERS"]):
-            self.writeTextElement(
-                "Other", Utilities.fromNativeSeparators(name))
-        self.writeEndElement()
+        if self.pdata["OTHERS"]:
+            self.writeStartElement("Others")
+            for name in sorted(self.pdata["OTHERS"]):
+                self.writeTextElement(
+                    "Other", Utilities.fromNativeSeparators(name))
+            self.writeEndElement()
         
         # do the main script
         if self.pdata["MAINSCRIPT"]:

eric ide

mercurial