diff --git a/files/usr/libexec/rocky/rss.py b/files/usr/libexec/rocky/rss.py index 984ce17..9157c01 100644 --- a/files/usr/libexec/rocky/rss.py +++ b/files/usr/libexec/rocky/rss.py @@ -8,10 +8,15 @@ import os import argparse import time import binascii +# The old yum-utils repo-rss used string manipulation. We're instead going to +# use the XML python library to do the work for us. This is cleaner, imo. +from xml.sax.saxutils import escape as xmlescape +from xml.etree.ElementTree import ElementTree, TreeBuilder, tostring +from xml.dom import minidom import dnf import dnf.exceptions #from dnf.comps import Comps -import libxml2 +#import libxml2 def to_unicode(string: str) -> str: """ @@ -43,6 +48,8 @@ class DnfQuiet(dnf.Base): else: available = self.sack.query().available().filter(latest_per_arch=1) + available.run() + for package in available: ftime = int(package.buildtime) if ftime > recentlimit: @@ -60,108 +67,126 @@ class DnfQuiet(dnf.Base): class RepoRSS: def __init__(self, filename='repo-rss.xml'): self.description = 'Repository RSS' - self.link = 'http://dnf.baseurl.org' + self.link = 'https://github.com/rpm-software-management/dnf' self.title = 'Recent Packages' - self.do_file(filename) - self.do_doc() - - def do_doc(self): - self.doc = libxml2.newDoc('1.0') - self.xmlescape = self.doc.encodeEntitiesReentrant - rss = self.doc.newChild(None, 'rss', None) - rss.setProp('version', '2.0') - self.rssnode = rss.newChild(None, 'channel', None) - - def do_file(self, filename): if filename[0] != '/': cwd = os.getcwd() self.filename = os.path.join(cwd, filename) else: self.filename = filename - try: - self.file_open = open(self.filename, 'w+') - except IOError as exc: - print(f'Error opening file {self.filename}: {exc}', file=sys.stderr) - sys.exit(1) - - def rsspackage(self, package): - rfc822_format = "%a, %d %b %Y %X GMT" - changelog_format = "%a, %d %b %Y GMT" - package_hex = binascii.hexlify(package.chksum[1]).decode() - item = self.rssnode.newChild(None, 'item', None) - title = self.xmlescape(str(package)) - description = package.description - item.newChild(None, 'title', title) - date = time.gmtime(float(package.buildtime)) - item.newChild(None, 'pubDate', time.strftime(rfc822_format, date)) - # pylint: disable=line-too-long - item.newChild(None, 'guid', package_hex).setProp("isPermaLink", "false") - link = package.remote_location() - item.newChild(None, 'link', self.xmlescape(link)) - changelog = '' - count = 0 - if package.changelogs is not None: - changelog_list = package.changelogs - else: - changelog_list = [] - for meta in changelog_list: - count += 1 - if count > 3: - changelog += '...' - break - date = meta['timestamp'].strftime(changelog_format) - author = meta['author'] - desc = meta['text'] - changelog += f'{date} - {author}\n{desc}\n\n' - # pylint: disable=line-too-long,consider-using-f-string - description = '
{} - {}
\n\n'.format(self.xmlescape(package.name), self.xmlescape(package.summary)) - description += '%s
\n\nChange Log:
\n\n' % self.xmlescape(description.replace("\n", "%s' % self.xmlescape(changelog)) - item.newChild(None, 'description', description) - return item - - def start_rss(self): - """return string representation of rss preamble""" + def rsspackage(self, packages): + file = self.filename rfc822_format = "%a, %d %b %Y %X GMT" now = time.strftime(rfc822_format, time.gmtime()) - rssheader = f""" -
{package.name} - {package.summary}
\n\n' + description += '%s
\n\nChange Log:
\n\n' % description.replace("\n", "{changelog}' - def do_package(self, package): - item = self.rsspackage(package) - self.file_open.write(item.serialize("utf-8", 1)) - item.unlinkNode() - item.freeNode() - del item + # start item + etbobj.start('item', {}) + # start title + etbobj.start('title', {}) + etbobj.data(title) + etbobj.end('title') + # end title + # start pubDate + etbobj.start('pubDate', {}) + etbobj.data(date) + etbobj.end('pubDate') + # end pubDate + # start guid + etbobj.start('guid', {'isPermaLink': 'false'}) + etbobj.data(package_hex) + etbobj.end('guid',) + # end guid + # start link + etbobj.start('link', {}) + etbobj.data(link) + etbobj.end('link') + # end link + # start description + etbobj.start('description', {}) + etbobj.data(xmlescape(description)) + etbobj.end('description') + # end description + etbobj.end('item') + # end item - def close_rss(self): - end="\n