Re: prettify xml output of modifyrepo

Luke Macken <[email protected]>
Newsgroups gmane.linux.rpm.metadata
Message-ID <[email protected]>
On Fri, Dec 21, 2007 at 11:13:54AM +0100, Christoph Thiel wrote:
> On Thu, Dec 20, 2007 at 02:18:58PM -0500, Luke Macken wrote:
> > On Wed, Dec 05, 2007 at 06:22:49PM +0100, Christoph Thiel wrote:
> > > Hi folks,
> > > 
> > > please commit the attached modifyrepo-prettyxml.patch
> > 
> > Hi Christoph,
> > 
> > Wouldn't something like this also suffice?
> > 
> > luke
> > 
> > --- a/modifyrepo.py
> > +++ b/modifyrepo.py
> > @@ -108,7 +108,7 @@ class RepoMetadata:
> >  
> >          ## Write the updated repomd.xml
> >          outmd = file(self.repomdxml, 'w')
> > -        self.doc.writexml(outmd)
> > +        outmd.write(self.doc.toprettyxml())
> >          outmd.close()
> >          print "Wrote:", self.repomdxml
> 
> Nope, that didn't work, IIRC :(

Works for me.  The only problem with it that the repomd.xml is written
back out with two spaces between each tag.  The attached patch removes
any whitespace nodes from the repomd.xml dom before writing it back out.
Seems to have the same effect.

luke

_______________________________________________
Rpm-metadata mailing list
[email protected]
https://lists.dulug.duke.edu/mailman/listinfo/rpm-metadata
0001-Remove-any-whitespace-nodes-from-the-repomd-before-w.patch (text/plain, 2.2 KB)
>From e6c992c1c0c728baf438445a5253ae2f948f81f0 Mon Sep 17 00:00:00 2001
From: Luke Macken <[email protected]>
Date: Fri, 21 Dec 2007 15:55:17 -0500
Subject: [PATCH] Remove any whitespace nodes from the repomd before writing it out


diff --git a/modifyrepo.py b/modifyrepo.py
index d4b3b00..6d6370b 100755
--- a/modifyrepo.py
+++ b/modifyrepo.py
@@ -90,35 +90,32 @@ class RepoMetadata:
 
         ## Build the metadata
         root = self.doc.firstChild
-        root.appendChild(self.doc.createTextNode("  "))
         data = self._insert_element(root, 'data', attrs={ 'type' : mdtype })
-        data.appendChild(self.doc.createTextNode("\n    "))
 
         self._insert_element(data, 'location',
                              attrs={ 'href' : 'repodata/' + mdname })
-        data.appendChild(self.doc.createTextNode("\n    "))
         self._insert_element(data, 'checksum', attrs={ 'type' : 'sha' },
                              text=sha.new(newmd).hexdigest())
-        data.appendChild(self.doc.createTextNode("\n    "))
         self._insert_element(data, 'timestamp',
                              text=str(os.stat(destmd).st_mtime))
-        data.appendChild(self.doc.createTextNode("\n    "))
         self._insert_element(data, 'open-checksum', attrs={ 'type' : 'sha' },
                              text=sha.new(md).hexdigest())
 
-        data.appendChild(self.doc.createTextNode("\n  "))
-        root.appendChild(self.doc.createTextNode("\n"))
-
         print "           type =", mdtype 
         print "       location =", 'repodata/' + mdname
         print "       checksum =", sha.new(newmd).hexdigest()
         print "      timestamp =", str(os.stat(destmd).st_mtime)
         print "  open-checksum =", sha.new(md.encode('utf-8')).hexdigest()
 
+        ## Clean the repomd doc of any whitespace nodes
+        for child in self.doc.firstChild.childNodes:
+            if child.nodeType == child.TEXT_NODE:
+                if child.data.strip() == '':
+                    self.doc.removeNode(child)
+
         ## Write the updated repomd.xml
         outmd = file(self.repomdxml, 'w')
         self.doc.writexml(outmd)
-        outmd.write("\n")
         outmd.close()
         print "Wrote:", self.repomdxml
 
-- 
1.5.3.6
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.