X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=queue_rss.py;h=c312b25b64d9c67c438ab000c5a9a887df2aa3ff;hb=0708400a8775dc847856de8ccf4a9fa6e9d2863d;hp=2e92dd29fc07f8b9fc620eb87fa99cdc434b15e2;hpb=0833b2d8ce6cfeb09a7d985d7b81ee87ae499e2d;p=dak.git diff --git a/queue_rss.py b/queue_rss.py index 2e92dd29..c312b25b 100755 --- a/queue_rss.py +++ b/queue_rss.py @@ -15,6 +15,8 @@ from optparse import OptionParser import PyRSS2Gen +from debian_bundle.deb822 import Changes + inrss_filename = "changes_in.rss" outrss_filename = "changes_out.rss" db_filename = "status.db" @@ -48,7 +50,7 @@ class Status: def utf2ascii(src): """ Return an ASCII encoded copy of the input UTF-8 string """ try: - res = unicode(src, 'utf-8').encode('ascii', 'replace') + res = unicode(src, 'utf-8').encode('ascii', 'replace') except UnicodeDecodeError: res = None return res @@ -57,9 +59,7 @@ def purge_old_items(feed, max): """ Purge RSSItem from feed, no more than max. """ if feed.items is None or len(feed.items) == 0: return False - - # most recent first - feed.items.sort(lambda x,y: cmp(y.pubDate, x.pubDate)) + feed.items = feed.items[:max] return True @@ -68,12 +68,7 @@ def parse_changes(fname): Return {fname: parsed} """ - p = HeaderParser() - - try: - m = p.parse(open(fname), True) - except IOError: - sys.stderr.write("Unable to parse %s\n" % fname) + m = Changes(open(fname)) wanted_fields = set(['Source', 'Version', 'Architecture', 'Distribution', 'Date', 'Maintainer', 'Description', 'Changes']) @@ -102,7 +97,7 @@ def parse_queuedir(dir): return res -def append_rss_item(status, msg, direction): +def add_rss_item(status, msg, direction): if direction == "in": feed = status.feed_in title = "%s %s entered NEW" % (msg['Source'], msg['Version']) @@ -115,9 +110,9 @@ def append_rss_item(status, msg, direction): description = "
Description: %s\nChanges: %s\n
" % \ (utf2ascii(msg['Description']), utf2ascii(msg['Changes'])) - feed.items.append( + feed.items.insert(0, PyRSS2Gen.RSSItem( - title, + title, pubDate = msg['Date'], # pubDate = now(), description = description, @@ -134,12 +129,12 @@ def update_feeds(curqueue, status): for (name, parsed) in curqueue.items(): if not status.queue.has_key(name): # new package - append_rss_item(status, parsed, "in") + add_rss_item(status, parsed, "in") for (name, parsed) in status.queue.items(): if not curqueue.has_key(name): # removed package - append_rss_item(status, parsed, "out") + add_rss_item(status, parsed, "out") @@ -149,10 +144,12 @@ if __name__ == "__main__": if not os.path.exists(settings.outdir): sys.stderr.write("Outdir '%s' does not exists\n" % settings.outdir) + parser.print_help() sys.exit(1) if not os.path.exists(settings.datadir): sys.stderr.write("Datadir '%s' does not exists\n" % settings.datadir) + parser.print_help() sys.exit(1) status_db = os.path.join(settings.datadir, db_filename) @@ -176,11 +173,19 @@ if __name__ == "__main__": feed_in_file = os.path.join(settings.outdir, inrss_filename) feed_out_file = os.path.join(settings.outdir, outrss_filename) - status.feed_in.write_xml(file(feed_in_file, "w+"), "utf-8") - status.feed_out.write_xml(file(feed_out_file, "w+"), "utf-8") + try: + status.feed_in.write_xml(file(feed_in_file, "w+"), "utf-8") + status.feed_out.write_xml(file(feed_out_file, "w+"), "utf-8") + except IOError, why: + sys.stderr.write("Unable to write feeds: %s\n", why) + sys.exit(1) status.queue = current_queue - cPickle.dump(status, open(status_db, "w+")) + try: + cPickle.dump(status, open(status_db, "w+")) + except IOError, why: + sys.stderr.write("Unable to save status: %s\n", why) + sys.exit(1) # vim:et:ts=4