[yum-commits] Branch 'yum-3_2_X' - yum/update_md.py
skvidal at osuosl.org
skvidal at osuosl.org
Fri Oct 17 19:32:37 UTC 2008
yum/update_md.py | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
New commits:
commit f87cd6743b1d4ac45cf30b96843fc65f7380d3f5
Author: Seth Vidal <skvidal at fedoraproject.org>
Date: Fri Oct 17 15:32:22 2008 -0400
add xml() method for UpdateMetadata and UpdateNotice objects to push back out
xml from these objects
diff --git a/yum/update_md.py b/yum/update_md.py
index e96b167..b1d7388 100644
--- a/yum/update_md.py
+++ b/yum/update_md.py
@@ -26,6 +26,7 @@ import gzip
from textwrap import wrap
from yum.yumRepo import YumRepository
+from yum.misc import to_xml
import rpmUtils.miscutils
@@ -233,6 +234,55 @@ class UpdateNotice(object):
self._md['reboot_suggested'] = True
return package
+ def xml(self):
+ """Generate the xml for this update notice object"""
+ msg="""
+<update from="%s" status="%s" type="%s" version="%s">
+ <id>%s</id>
+ <title>%s</title>
+ <release>%s</release>
+ <issued date="%s"/>
+ <description>%s</description>\n""" % (to_xml(self._md['from']),
+ to_xml(self._md['status']), to_xml(self._md['type']),
+ to_xml(self._md['version']),to_xml(self._md['update_id']),
+ to_xml(self._md['title']), to_xml(self._md['release']),
+ to_xml(self._md['issued'], attrib=True),
+ to_xml(self._md['description']))
+
+ if self._md['references']:
+ msg += """ <references>\n"""
+ for ref in self._md['references']:
+ if ref['title']:
+ msg += """ <reference href="%s" id="%s" title="%s" type="%s"/>\n""" % (
+ to_xml(ref['href'], attrib=True), to_xml(ref['id'], attrib=True),
+ to_xml(ref['title'], attrib=True), to_xml(ref['type'], attrib=True))
+ else:
+ msg += """ <reference href="%s" id="%s" type="%s"/>\n""" % (
+ to_xml(ref['href'], attrib=True), to_xml(ref['id'], attrib=True),
+ to_xml(ref['type'], attrib=True))
+
+ msg += """ </references>\n"""
+
+ if self._md['pkglist']:
+ msg += """ <pkglist>\n"""
+ for coll in self._md['pkglist']:
+ msg += """ <collection short="%s">\n <name>%s</name>\n""" % (
+ to_xml(coll['short'], attrib=True),
+ to_xml(coll['name']))
+
+ for pkg in coll['packages']:
+ msg += """ <package arch="%s" name="%s" release="%s" src="%s" version="%s">
+ <filename>%s</filename>
+ </package>\n""" % (to_xml(pkg['arch'], attrib=True),
+ to_xml(pkg['name'], attrib=True),
+ to_xml(pkg['release'], attrib=True),
+ to_xml(pkg['src'], attrib=True),
+ to_xml(pkg['version'], attrib=True),
+ to_xml(pkg['filename']))
+ msg += """ </collection>\n"""
+ msg += """ </pkglist>\n"""
+ msg += """</update>\n"""
+ return msg
def _rpm_tup_vercmp(tup1, tup2):
""" Compare two "std." tuples, (n, a, e, v, r). """
@@ -333,6 +383,28 @@ class UpdateMetadata(object):
ret += str(notice)
return ret
+ def xml(self, fileobj=None):
+ msg = """<?xml version="1.0"?>\n<updates>"""
+ if fileobj:
+ fileobj.write(msg)
+
+ for notice in self._notices.values():
+ if fileobj:
+ fileobj.write(notice.xml())
+ else:
+ msg += notice.xml()
+
+ end = """</updates>\n"""
+ if fileobj:
+ fileobj.write(end)
+ else:
+ msg+= end
+
+ if fileobj:
+ return
+
+ return msg
+
def main():
""" update_md test function. """
More information about the Yum-commits
mailing list