Add support for regexp-based replacing.
darcsweb.cgi
Mon Dec 25 22:18:20 UTC 2006 Alberto Bertogli <albertito@gmail.com>
* Add support for regexp-based replacing.
Add an option to replace text in the summary, using regexps. This allows you
to configure darcsweb to automatically detect and put links to other commits
or bug numbers.
This patch is heavily based on the one written by Kirill Smelkov
(kirr@mns.spb.ru).
--- old-darcsweb/darcsweb.cgi 2015-11-01 04:06:13.000000000 +0000
+++ new-darcsweb/darcsweb.cgi 2015-11-01 04:06:13.000000000 +0000
@@ -161,6 +161,22 @@
pos = s.find("\t")
return s
+def replace_links(s):
+ """Replace user defined strings with links, as specified in the
+ configuration file."""
+ import re
+
+ vardict = {
+ "myreponame": config.myreponame,
+ "reponame": config.reponame,
+ }
+
+ for link_pat, link_dst in config.url_links:
+ s = re.sub(link_pat, link_dst % vardict, s)
+
+ return s
+
+
def highlight(s, l):
"Highlights appearences of s in l"
import re
@@ -1146,7 +1162,7 @@
for p in ps:
if p.comment:
- comment = escape(p.comment)
+ comment = replace_links(escape(p.comment))
fmt_comment = comment.replace('\n', '<br/>') + '\n'
fmt_comment += '<br/><br/>'
else:
@@ -1589,10 +1605,10 @@
'name': escape(p.name),
}
if p.comment:
- comment = escape(p.comment)
+ comment = replace_links(escape(p.comment))
c = comment.replace('\n', '<br/>\n')
print '<div class="page_body">'
- print escape(p.name), '<br/><br/>'
+ print replace_links(escape(p.name)), '<br/><br/>'
print c
print '</div>'
@@ -2321,6 +2337,11 @@
else:
config.logtimes = None
+ if "url_links" in dir(base):
+ config.url_links = base.url_links
+ else:
+ config.url_links = ()
+
if name and "footer" in dir(c):
config.footer = c.footer
elif "footer" in dir(base):