--- Begin Message ---
Package: qa.debian.org
Severity: wishlist
Tags: patch
Usertags: pts
It would be nice to have pubDate elements in the news.rss20.xml of PTS to allow
better sorting of items aggregated from multiple packages' feeds. The attached
patch adds more detailed date information to items in news.xml and transforms
them into pubDate elements in the RSS items.
Regards
Jan
-- System Information:
Debian Release: wheezy/sid
APT prefers stable
APT policy: (990, 'stable'), (500, 'unstable'), (500, 'testing'), (1,
'experimental')
Architecture: amd64 (x86_64)
Kernel: Linux 2.6.32-5-amd64 (SMP w/8 CPU cores)
Locale: LANG=de_DE.utf8, LC_CTYPE=de_DE.utf8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
--
Jan Dittberner - Debian Developer
GPG-key: 4096R/558FB8DD 2009-05-10
B2FF 1D95 CE8F 7A22 DF4C F09B A73E 0055 558F B8DD
http://ddportfolio.debian.net/ - http://people.debian.org/~jandd/
Subject: add pubDate to package RSS feeds
Author: Jan Dittberner <ja...@debian.org>
Description: This patch adds a pubDate element to item elements in the RSS
feeds for package's news and fixes deprecation warnings.
* common.py: use hashlib.md5 instead of the md5 module
* update_news.py:
- use subprocess.Popen instead of deprecated os.popen3 for mhonarc
invocation
- use the xml.dom.minidom implementation included in Python since 2.0
- add timestamp_to_rfc822date(timestamp) to convert the timestamp format of
news filenames to RFC 822 timestamps
- generate a new attribute rfc822date in news.xml item elements
* news2rss.xsl: add transformation from rfc822date attribute in news.xml to
pubDate element in RSS
Index: www/xsl/news2rss.xsl
===================================================================
--- www/xsl/news2rss.xsl (Revision 2506)
+++ www/xsl/news2rss.xsl (Arbeitskopie)
@@ -69,6 +69,7 @@
<xsl:text>/</xsl:text> <xsl:value-of select="$hash" />
<xsl:text>/</xsl:text> <xsl:value-of select="@url" />
</xsl:variable>
+ <pubDate> <xsl:value-of select="@rfc822date" /> </pubDate>
<guid> <xsl:value-of select="$id" /> </guid>
<link> <xsl:value-of select="$id" /> </link>
<description>
Index: www/bin/common.py
===================================================================
--- www/bin/common.py (Revision 2506)
+++ www/bin/common.py (Arbeitskopie)
@@ -7,7 +7,7 @@
# This file is distributed under the terms of the General Public License
# version 2 or (at your option) any later version.
-import md5, os, os.path, re, rfc822, time, email
+import hashlib, os, os.path, re, rfc822, time, email
from email import Utils, Header
from config import root
@@ -135,7 +135,7 @@
f = open(fname,"r")
if not f: return 0
- hash = md5.new()
+ hash = hashlib.md5()
for line in f.readlines():
hash.update(line)
f.close()
Index: www/bin/update_news.py
===================================================================
--- www/bin/update_news.py (Revision 2506)
+++ www/bin/update_news.py (Arbeitskopie)
@@ -6,11 +6,12 @@
# Copyright 2002 Raphaël Hertzog
# Copyright 2006 Jeroen van Wolffelaar
+# Copyright 2011 Jan Dittberner
# This file is distributed under the terms of the General Public License
# version 2 or (at your option) any later version.
-import os, rfc822, sys, string, re, email, common
-from xml.dom import implementation, ext
+import os, rfc822, sys, string, re, email, time, common, subprocess
+from xml.dom.minidom import getDOMImplementation
from config import dir, odir, root
from common import hash_name
@@ -29,10 +30,13 @@
dir = os.path.dirname(htmlfile)
if not os.path.exists(dir): os.makedirs(dir)
- (stdin, stdout, stderr) = os.popen3("""cd %s; \
+ mhproc = subprocess.Popen("""cd %s; \
mhonarc -rcfile /dev/stdin \
-rcfile %s/etc/mhonarc.rc \
- -single %s 2> /dev/null""" % (dir, root, source))
+ -single %s 2> /dev/null""" % (dir, root, source), shell=True,
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
+ close_fds=True)
+ (stdin, stdout, stderr) = (mhproc.stdin, mhproc.stdout, mhproc.stderr)
stdin.write("""
<MSGHEAD>
<h3><a href="../../%s.html">Back to %s PTS page</a></h3>
@@ -45,6 +49,17 @@
os.chmod(htmlfile+".new", 0664)
os.rename(htmlfile+".new", htmlfile)
+
+def timestamp_to_rfc822date(timestamp):
+ """Format a timestamp in format YYYYMMDDThhmmssZ to a RFC 822 String.
+
+ >>> timestamp_to_rfc822date('20090718T163915Z')
+ 'Sat, 18 Jul 2009 16:39:15 GMT'
+ """
+ return time.strftime("%a, %d %b %Y %H:%M:%S GMT",
+ time.strptime(timestamp, '%Y%m%dT%H%M%SZ'))
+
+
def add_resume_for_msg(pkg, file, elt, doc, kind):
if not os.path.isfile(file):
pass
@@ -64,34 +79,37 @@
sub_elt.setAttribute("url", htmlfile)
if info.has_key("date"):
sub_elt.setAttribute("date", info["date"])
+ sub_elt.setAttribute("rfc822date",
+ timestamp_to_rfc822date(info["timestamp"]))
if info.has_key("from_name"):
sub_elt.setAttribute("from", info["from_name"])
elt.appendChild(sub_elt)
-# Create the XML documents
-while 1:
- line = sys.stdin.readline()
- if not line: break #eof
- pkg = line.strip()
- doc = implementation.createDocument(None, "news", None)
- root_elt = doc.documentElement
- hash = hash_name(pkg)
+if __name__ == '__main__':
+ # Create the XML documents
+ while 1:
+ line = sys.stdin.readline()
+ if not line: break #eof
+ pkg = line.strip()
- # Get news information : static/news/auto
- for type, number in [("static", 5), ("news", 30)]:
- elt = doc.createElement(type)
- dir = "%s/base/%s/%s/%s" % (root, hash, pkg, type)
- if not os.path.exists(dir): os.makedirs(dir)
- entries = os.listdir(dir)
- entries.sort()
- entries.reverse()
- for entry in entries[:number]:
- add_resume_for_msg(pkg, dir+"/"+entry, elt, doc, type)
- root_elt.appendChild(elt)
+ doc = getDOMImplementation().createDocument(None, "news", None)
+ root_elt = doc.documentElement
+ hash = hash_name(pkg)
- # Output the data to the XML file
- f = open("%s/%s/%s/news.xml" % (odir, hash, pkg), "w")
- ext.PrettyPrint(doc, f, 'utf8')
- f.close()
+ # Get news information : static/news/auto
+ for type, number in [("static", 5), ("news", 30)]:
+ elt = doc.createElement(type)
+ dir = "%s/base/%s/%s/%s" % (root, hash, pkg, type)
+ if not os.path.exists(dir): os.makedirs(dir)
+ entries = os.listdir(dir)
+ entries.sort()
+ entries.reverse()
+ for entry in entries[:number]:
+ add_resume_for_msg(pkg, dir+"/"+entry, elt, doc, type)
+ root_elt.appendChild(elt)
+ # Output the data to the XML file
+ f = open("%s/%s/%s/news.xml" % (odir, hash, pkg), "w")
+ f.write(doc.toprettyxml(encoding='utf8'))
+ f.close()
signature.asc
Description: Digital signature
--- End Message ---