ATOM support for syndication
Thu Dec 1 22:07:08 UTC 2005 stephane@sources.org
* ATOM support for syndication
diff -rN -u old-darcsweb/darcsweb.cgi new-darcsweb/darcsweb.cgi
--- old-darcsweb/darcsweb.cgi 2015-04-15 14:39:01.000000000 +0000
+++ new-darcsweb/darcsweb.cgi 2015-04-15 14:39:01.000000000 +0000
@@ -20,6 +20,7 @@
import xml.sax
from xml.sax.saxutils import escape as xml_escape
+iso_datetime = '%Y-%m-%dT%H:%M:%SZ'
# empty configuration class, we will fill it in later depending on the repo
class config:
@@ -1715,7 +1716,68 @@
print_log(topi = topi)
print_footer()
+def do_atom():
+ print "Content-type: application/atom+xml; charset=utf-8\n"
+ print '<?xml version="1.0" encoding="utf-8"?>'
+ inv = config.repodir + '/_darcs/inventory'
+ repo_lastmod = os.stat(inv).st_mtime
+ print """<feed xmlns="http://www.w3.org/2005/Atom">
+ <title>%(reponame)s darcs repository</title>
+ <link rel="alternate" type="text/html" href="%(url)s"/>
+ <link rel="self" type="application/atom+xml" href="%(url)s/%(reponame)s;a=atom"/>
+ <id>%(url)s</id> <!-- TODO: find a better <id>, see RFC 4151 -->
+ <author><name>darcs repository (several authors)</name></author>
+ <generator>darcsweb.cgi</generator>
+ <updated>%(lastmod)s</updated>
+ <subtitle>%(desc)s</subtitle>
+ """ % {
+ 'reponame': config.reponame,
+ 'url': config.myurl + '/' + config.myreponame,
+ 'desc': config.repodesc,
+ 'lastmod': time.strftime(iso_datetime, time.localtime(repo_lastmod))}
+ ps = get_last_patches(20)
+ for p in ps:
+ title = time.strftime('%d %b %H:%M', time.localtime(p.date))
+ title += ' - ' + p.name
+ pdate = time.strftime(iso_datetime,
+ time.localtime(p.date))
+ link = '%s/%s;a=commit;h=%s' % (config.myurl,
+ config.myreponame, p.hash)
+ print """
+ <entry>
+ <title>%(title)s</title>
+ <author><name>%(author)s</name><!-- TODO: parse it to get the email. Not obvious, darcs authors can be anything --></author>
+ <updated>%(pdate)s</updated>
+ <id>%(url)s/%(pname)s</id> <!-- TODO: find a better <id>, see RFC 4151 -->
+ <link rel="alternate" href="%(link)s"/>
+ <summary>%(desc)s</summary>
+ """ % {
+ 'title': escape(title),
+ 'author': p.author,
+ 'url': config.myurl + '/' + config.myreponame,
+ 'pdate': pdate,
+ 'pname': escape(p.name),
+ 'link': link,
+ 'desc': escape(p.name),
+ }
+ # TODO: allow to get plain text, not HTML?
+ print ' <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>'
+ print escape(p.name) + '<br/>'
+ if p.comment:
+ print '<br/>'
+ print escape(p.comment).replace('\n', '<br/>\n')
+ print '<br/>'
+ print '<br/>'
+ changed = p.adds + p.removes + p.modifies.keys() + \
+ p.moves.keys() + p.diradds + p.dirremoves + \
+ p.replaces.keys()
+ for i in changed: # TODO: link to the file
+ print '<code>%s</code><br/>' % i
+ print '</p></div>'
+ print '</content></entry>'
+ print '</feed>'
+
def do_rss():
print "Content-type: text/xml; charset=utf-8\n"
print '<?xml version="1.0" encoding="utf-8"?>'
@@ -2128,6 +2190,9 @@
elif action == 'rss':
do_rss()
+elif action == 'atom':
+ do_atom()
+
else:
action = "invalid query"
do_die()