Thu Dec 1 22:07:08 UTC 2005 stephane@sources.org
* ATOM support for syndication
{
hunk ./darcsweb.cgi 23
+iso_datetime = '%Y-%m-%dT%H:%M:%SZ'
hunk ./darcsweb.cgi 1719
+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)
hunk ./darcsweb.cgi 1747
+ 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>'
+[_^I_][_$_]
hunk ./darcsweb.cgi 2192
+
+elif action == 'atom':
+ do_atom()
}