[lnst] Preserve original node attributes for sourced xml bits

Jiří Pírko jirka at fedoraproject.org
Thu Aug 16 11:43:16 UTC 2012


commit 8874632a971bea298cc6cb02c5aebf68762f4948
Author: Jan Tluka <jtluka at redhat.com>
Date:   Wed Aug 15 14:58:41 2012 +0200

    Preserve original node attributes for sourced xml bits
    
    Signed-off-by: Jan Tluka <jtluka at redhat.com>

 Common/XmlProcessing.py |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
---
diff --git a/Common/XmlProcessing.py b/Common/XmlProcessing.py
index a76364e..8d92e83 100644
--- a/Common/XmlProcessing.py
+++ b/Common/XmlProcessing.py
@@ -191,6 +191,13 @@ class XmlParser(object):
         text = str(''.join(content).strip())
         return self._convert_string(node, text, conversion_cb)
 
+    def _get_all_attributes(self, node):
+        res = {}
+        for i in range(0, node.attributes.length):
+            attr = node.attributes.item(i)
+            res[attr.name] = attr.value
+
+        return res
 
 class RecipeParser(XmlParser):
     """ Enhanced XmlParser
@@ -294,10 +301,18 @@ class RecipeParser(XmlParser):
                                     % (node.nodeName, file_path))
                 raise XmlProcessingError(msg, node)
 
+            old_attrs = self._get_all_attributes(node)
+
             parent = node.parentNode
             parent.replaceChild(loaded_node, node)
             node = loaded_node
 
+            # copy all of the original attributes to the sourced node
+            for name, value in old_attrs.iteritems():
+                # do not overwrite sourced attributes
+                if not node.hasAttribute(name):
+                    node.setAttribute(name, value)
+
         parent = super(RecipeParser, self)
         parent._process_node(node, handler, params)
 


More information about the LNST-developers mailing list