X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;ds=inline;f=tools%2Fqueue_rss.py;h=0e47d57b01f0987b042f5ee66dd5e1418d75e8fe;hb=93b984f622111a219b0db0bee2ab7292ac0db654;hp=9fcc1d8db5e8e0aa8f3c7807f051e4978ff5cd78;hpb=5bfb9fcc5aa4304b058f941c370e56f6dc0fa3e4;p=dak.git diff --git a/tools/queue_rss.py b/tools/queue_rss.py index 9fcc1d8d..0e47d57b 100755 --- a/tools/queue_rss.py +++ b/tools/queue_rss.py @@ -9,14 +9,20 @@ import cgi import os import os.path import cPickle +import re import sys -import encodings.ascii +import time from optparse import OptionParser from datetime import datetime import PyRSS2Gen -from debian_bundle.deb822 import Changes +try: + # starting with squeeze + from debian.deb822 import Changes +except: + # up to lenny + from debian_bundle.deb822 import Changes inrss_filename = "NEW_in.rss" outrss_filename = "NEW_out.rss" @@ -24,7 +30,7 @@ db_filename = "status.db" parser = OptionParser() parser.set_defaults(queuedir="queue", outdir="out", datadir="status", - max_entries="30") + logdir="log", max_entries="30") parser.add_option("-q", "--queuedir", dest="queuedir", help="The queue dir (%default)") @@ -32,6 +38,8 @@ parser.add_option("-o", "--outdir", dest="outdir", help="The output directory (%default)") parser.add_option("-d", "--datadir", dest="datadir", help="The data dir (%default)") +parser.add_option("-l", "--logdir", dest="logdir", + help="The ACCEPT/REJECT dak log dir (%default)") parser.add_option("-m", "--max-entries", dest="max_entries", type="int", help="Max number of entries to keep (%default)") @@ -49,14 +57,6 @@ class Status: self.queue = {} -def utf2ascii(src): - """ Return an ASCII encoded copy of the input UTF-8 string """ - try: - res = unicode(src, 'utf-8').encode('ascii', 'replace') - except UnicodeDecodeError: - res = None - return res - def purge_old_items(feed, max): """ Purge RSSItem from feed, no more than max. """ if feed.items is None or len(feed.items) == 0: @@ -99,6 +99,28 @@ def parse_queuedir(dir): return res +def parse_leave_reason(fname): + """ Parse a dak log file fname for ACCEPT/REJECT reason from process-new. + + Return a dictionary {filename: reason}""" + + reason_re = re.compile(".+\|process-new\|.+\|NEW (ACCEPT|REJECT): (\S+)") + + try: + f = open(fname) + except IOError, e: + sys.stderr.write("Can't open %s: %s\n" % (fname, e)) + return {} + + res = {} + for l in f.readlines(): + m = reason_re.search(l) + if m: + res[m.group(2)] = m.group(1) + + f.close() + return res + def add_rss_item(status, msg, direction): if direction == "in": feed = status.feed_in @@ -106,14 +128,20 @@ def add_rss_item(status, msg, direction): pubdate = msg['Date'] elif direction == "out": feed = status.feed_out - title = "%s %s left NEW" % (msg['Source'], msg['Version']) + if msg.has_key('Leave-Reason'): + title = "%s %s left NEW (%s)" % (msg['Source'], msg['Version'], + msg['Leave-Reason']) + else: + title = "%s %s left NEW" % (msg['Source'], msg['Version']) + + pubdate = datetime.utcnow() else: return False description = "
Description: %s\nChanges: %s\n" % \ - (utf2ascii(cgi.escape(msg['Description'])), - utf2ascii(cgi.escape(msg['Changes']))) + (cgi.escape(msg['Description']), + cgi.escape(msg['Changes'])) link = "http://ftp-master.debian.org/new/%s_%s.html" % \ (msg['Source'], msg['Version']) @@ -123,16 +151,20 @@ def add_rss_item(status, msg, direction): title, pubDate = pubdate, description = description, - author = utf2ascii(cgi.escape(msg['Maintainer'])), + author = cgi.escape(msg['Maintainer']), link = link, guid = link ) ) -def update_feeds(curqueue, status): +def update_feeds(curqueue, status, settings): # inrss -> append all items in curqueue not in status.queue # outrss -> append all items in status.queue not in curqueue + leave_reason = None + # logfile from dak's process-new + reason_log = os.path.join(settings.logdir, time.strftime("%Y-%m")) + for (name, parsed) in curqueue.items(): if not status.queue.has_key(name): # new package @@ -140,7 +172,11 @@ def update_feeds(curqueue, status): for (name, parsed) in status.queue.items(): if not curqueue.has_key(name): - # removed package + # removed package, try to find out why + if leave_reason is None: + leave_reason = parse_leave_reason(reason_log) + if leave_reason and leave_reason.has_key(name): + parsed['Leave-Reason'] = leave_reason[name] add_rss_item(status, parsed, "out") @@ -172,7 +208,7 @@ if __name__ == "__main__": parser.print_help() sys.exit(1) - update_feeds(current_queue, status) + update_feeds(current_queue, status, settings) purge_old_items(status.feed_in, settings.max_entries) purge_old_items(status.feed_out, settings.max_entries)