Mercurial > hg > mercurial-crew-with-dirclash
comparison mercurial/hgweb.py @ 599:765182a4c843
[PATCH] Add RSS support to hgweb
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
[PATCH] Add RSS support to hgweb
From: Goffredo Baroncelli <kreijack@libero.it>
with the two small patches below, now hgweb can act as feed source.
Two kinds ofobjects 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 ).
[tweaked by mpm:
add Content-type: text/xml
add support for URL to header()
add header with link and content type
add RSS links on the normal pages]
manifest hash: 170c03d50490d7160097f59abdde1a5073d2ba82
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCyFmLywK+sNU5EO8RApkrAKCYF/vZ3DwdMXPBds2LxGEX8+tK5QCfTeOc
ZhPN8Xjt2cD3wMbNXMcoNSo=
=COlM
-----END PGP SIGNATURE-----
author | mpm@selenic.com |
---|---|
date | Sun, 03 Jul 2005 13:32:59 -0800 |
parents | f8d44a2e6928 |
children | 11c379e23ad6 |
comparison
equal
deleted
inserted
replaced
598:f8d44a2e6928 | 599:765182a4c843 |
---|---|
106 tmpl = self.cache[t] | 106 tmpl = self.cache[t] |
107 except KeyError: | 107 except KeyError: |
108 tmpl = self.cache[t] = file(self.map[t]).read() | 108 tmpl = self.cache[t] = file(self.map[t]).read() |
109 return template(tmpl, self.filters, **map) | 109 return template(tmpl, self.filters, **map) |
110 | 110 |
111 def rfc822date(x): | |
112 month= [None,"Jan", "Feb", "Mar", "Apr", "May", "Jun", | |
113 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] | |
114 yyyy,mon,dd,hh,mm,ss,wd,x,y = time.gmtime(x) | |
115 return "%d %s %d %d:%d:%d"%(dd, month[mon], yyyy, hh, mm, ss) | |
116 | |
111 class hgweb: | 117 class hgweb: |
112 maxchanges = 10 | 118 maxchanges = 10 |
113 maxfiles = 10 | 119 maxfiles = 10 |
114 | 120 |
115 def __init__(self, path, name, templates = ""): | 121 def __init__(self, path, name, templates = ""): |
125 "date": (lambda x: time.asctime(time.gmtime(x))), | 131 "date": (lambda x: time.asctime(time.gmtime(x))), |
126 "addbreaks": nl2br, | 132 "addbreaks": nl2br, |
127 "obfuscate": obfuscate, | 133 "obfuscate": obfuscate, |
128 "short": (lambda x: x[:12]), | 134 "short": (lambda x: x[:12]), |
129 "firstline": (lambda x: x.splitlines(1)[0]), | 135 "firstline": (lambda x: x.splitlines(1)[0]), |
130 "permissions": (lambda x: x and "-rwxr-xr-x" or "-rw-r--r--") | 136 "permissions": (lambda x: x and "-rwxr-xr-x" or "-rw-r--r--"), |
137 "rfc822date": rfc822date, | |
131 } | 138 } |
132 | 139 |
133 def refresh(self): | 140 def refresh(self): |
134 s = os.stat(os.path.join(self.path, ".hg", "00changelog.i")) | 141 s = os.stat(os.path.join(self.path, ".hg", "00changelog.i")) |
135 if s.st_mtime != self.mtime: | 142 if s.st_mtime != self.mtime: |
215 to = r.file(f).read(mmap1[f]) | 222 to = r.file(f).read(mmap1[f]) |
216 tn = None | 223 tn = None |
217 yield diffblock(mdiff.unidiff(to, date1, tn, date2, f), f, tn) | 224 yield diffblock(mdiff.unidiff(to, date1, tn, date2, f), f, tn) |
218 | 225 |
219 def header(self): | 226 def header(self): |
220 yield self.t("header", repo = self.reponame) | 227 port = os.environ["SERVER_PORT"] |
228 port = port != "80" and (":" + port) or "" | |
229 self.url = "http://%s%s%s" % \ | |
230 (os.environ["SERVER_NAME"], port, os.environ["REQUEST_URI"]) | |
231 | |
232 yield self.t("header", repo = self.reponame, url = self.url) | |
221 | 233 |
222 def footer(self): | 234 def footer(self): |
223 yield self.t("footer", repo = self.reponame) | 235 yield self.t("footer", repo = self.reponame) |
224 | 236 |
225 def changelog(self, pos): | 237 def changelog(self, pos): |
727 query = query.replace('+', ' ') | 739 query = query.replace('+', ' ') |
728 | 740 |
729 env = {} | 741 env = {} |
730 env['GATEWAY_INTERFACE'] = 'CGI/1.1' | 742 env['GATEWAY_INTERFACE'] = 'CGI/1.1' |
731 env['REQUEST_METHOD'] = self.command | 743 env['REQUEST_METHOD'] = self.command |
744 env['SERVER_NAME'] = self.server.server_name | |
745 env['SERVER_PORT'] = str(self.server.server_port) | |
746 env['REQUEST_URI'] = "/" | |
732 if query: | 747 if query: |
733 env['QUERY_STRING'] = query | 748 env['QUERY_STRING'] = query |
734 host = self.address_string() | 749 host = self.address_string() |
735 if host != self.client_address[0]: | 750 if host != self.client_address[0]: |
736 env['REMOTE_HOST'] = host | 751 env['REMOTE_HOST'] = host |