[PATCH] Add the rss support to hgweb

Goffredo Baroncelli kreijack at libero.it
Sun Jul 3 12:01:06 CDT 2005


Hi,

with the two small patches below, now hgweb can act as feed source. Two kinds of 
objects can be tracked: the changelong and the files. 
This can be useful if anyone would track the changes of a file ( and because 
git has it, mercurial have to has ).

To check the changelog the url is
http://127.0.0.1:8000/pippo.pluto?cmd=changelog;style=rss

To check a file ( the mercurial/hgweb.py for examples ) the url is
http://127.0.0.1:8000/?cmd=filelog;file=mercurial/hgweb.py;filenode=0;style=rss


The first patch adds a new filter for the template: the filter is named
rfc822date, and translates the date from the touple format to a 
rfc822 style date.
The second patch adds the templates needed to create the rss pages.

Tested with akgregator ( kde ).

BUG:
For now the server address/url ( which is used in the rss <link> tag ) are 
hand write in the template pages, because there is no a way to get the server 
adress and the url from the hgweb class. 
If you want to public the rss, you have to change the templates.


Goffredo




Patch #1
--------------------

diff -r eb46971fc57f mercurial/hgweb.py
--- a/mercurial/hgweb.py        Sun Jul  3 06:54:35 2005
+++ b/mercurial/hgweb.py        Sun Jul  3 18:31:33 2005
@@ -108,6 +108,12 @@
             tmpl = self.cache[t] = file(self.map[t]).read()
         return template(tmpl, self.filters, **map)

+def rfc822date(x):
+    month= [None,"Jan", "Feb", "Mar", "Apr", "May", "Jun",
+                 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
+    yyyy,mon,dd,hh,mm,ss,wd,x,y = time.gmtime(x)
+    return "%d %s %d %d:%d:%d"%(dd, month[mon], yyyy, hh, mm, ss)
+
 class hgweb:
     maxchanges = 10
     maxfiles = 10
@@ -127,7 +133,8 @@
             "obfuscate": obfuscate,
             "short": (lambda x: x[:12]),
             "firstline": (lambda x: x.splitlines(1)[0]),
-            "permissions": (lambda x: x and "-rwxr-xr-x" or "-rw-r--r--")
+            "permissions": (lambda x: x and "-rwxr-xr-x" or "-rw-r--r--"),
+            "rfc822date": rfc822date,
             }

     def refresh(self):




Patch #1
--------------------

diff -r eb46971fc57f templates/changelog-rss.tmpl
--- /dev/null   Sun Jul  3 06:54:35 2005
+++ b/templates/changelog-rss.tmpl      Sun Jul  3 18:31:33 2005
@@ -0,0 +1,9 @@
+<rss version="2.0">
+  <channel>
+    <title>#repo|escape# Changelog</title>
+    <link>http://selenic.com/mercurial</link>
+    <description>#repo|escape# Changelog</description>
+    <language>en-us</language>
+    #entries#
+  </channel>
+</rss>
\ No newline at end of file
diff -r eb46971fc57f templates/changelogentry-rss.tmpl
--- /dev/null   Sun Jul  3 06:54:35 2005
+++ b/templates/changelogentry-rss.tmpl Sun Jul  3 18:31:33 2005
@@ -0,0 +1,7 @@
+<item>
+    <title>#desc|firstline|escape#</title>
+    <link>http://127.0.0.1:8000/?cmd=changeset;node=#node#"</link>
+    <description>#desc|escape|addbreaks#</description>
+    <author>#author|obfuscate#</author>
+    <pubDate>#date|rfc822date#</pubDate>
+</item>
diff -r eb46971fc57f templates/filelog-rss.tmpl
--- /dev/null   Sun Jul  3 06:54:35 2005
+++ b/templates/filelog-rss.tmpl        Sun Jul  3 18:31:33 2005
@@ -0,0 +1,9 @@
+<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
+  <channel>
+    <title>#repo|escape#: #file# history</title>
+    <link>http://127.0.0.1/8000</link>
+    <description>#file# revision history</description>
+    <language>en-us</language>
+    #entries#
+  </channel>
+</rss>
\ No newline at end of file
diff -r eb46971fc57f templates/filelogentry-rss.tmpl
--- /dev/null   Sun Jul  3 06:54:35 2005
+++ b/templates/filelogentry-rss.tmpl   Sun Jul  3 18:31:33 2005
@@ -0,0 +1,7 @@
+<item>
+    <title>#desc|firstline|escape#</title>
+    <link>http://127.0.0.1:8000/?cmd=file;file=#file#;filenode=#filenode#"</link>
+    <description>#desc|escape|addbreaks#</description>
+    <author>#author|obfuscate#</author>
+    <pubDate>#date|rfc822date#</pubDate>>
+</item>
diff -r eb46971fc57f templates/map-rss
--- /dev/null   Sun Jul  3 06:54:35 2005
+++ b/templates/map-rss Sun Jul  3 18:31:33 2005
@@ -0,0 +1,4 @@
+changelog = changelog-rss.tmpl
+changelogentry = changelogentry-rss.tmpl
+filelog = filelog-rss.tmpl
+filelogentry = filelogentry-rss.tmpl


-- 
gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <kreijack AT inwind DOT it>
Key fingerprint = CE3C 7E01 6782 30A3 5B87  87C0 BB86 505C 6B2A CFF9


More information about the Mercurial mailing list