aboutsummaryrefslogtreecommitdiff
path: root/htmlchangelog.py
diff options
context:
space:
mode:
authorGuido G√ľnther <agx@sigxcpu.org>2008-11-07 18:49:45 +0100
committerGuido Guenther <agx@sigxcpu.org>2008-11-07 19:56:36 +0100
commit3b28bc894e71df060d2895f506ed1958e43d6110 (patch)
tree93d52d26048c8475d2e1735ed819f453b1882338 /htmlchangelog.py
parentba08fae3fd0158fb41651d74f97916021ccfb172 (diff)
add HTMLChangelog
Diffstat (limited to 'htmlchangelog.py')
-rw-r--r--htmlchangelog.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/htmlchangelog.py b/htmlchangelog.py
new file mode 100644
index 0000000..4c13bdc
--- /dev/null
+++ b/htmlchangelog.py
@@ -0,0 +1,60 @@
+# vim: set fileencoding=utf-8 :
+
+import re
+import cgi
+from genshi.template import TemplateLoader
+import debian_bundle.changelog
+import vcsbrowsers
+
+_TEMPLATEDIR='templates/'
+
+class HTMLChangelogFilter(object):
+ commit_id_re = re.compile(r"(?P<s>\s+\*\s+\[)"
+ +r"(?P<commitid>[a-fA-F0-9]{7,})"
+ +r"(?P<e>\]\s+.*)")
+
+ def __init__(self, vcsbrowser=None):
+ self.vcsbrowser=vcsbrowser
+
+ def vcs_commit_filter(self, changes):
+ body = []
+ for line in changes:
+ line = cgi.escape(line)
+ m = self.commit_id_re.match(line)
+ if m:
+ commitid = m.group('commitid')
+ link = '<a href="%s">%s</a>' % (self.vcsbrowser.commit(commitid), commitid)
+ body.append(m.group("s") + link + m.group("e"))
+ else:
+ body.append(line)
+ return "\n".join(body)
+
+ def markup_block(self, block):
+ if self.vcsbrowser:
+ block.body = self.vcs_commit_filter(block.changes())
+ else:
+ block.body = cgi.escape("\n".join(block.changes()))
+ return block
+
+
+class HTMLChangelog(debian_bundle.changelog.Changelog):
+ def __init__(self, file=None, max_blocks=None, allow_empty_author=False, strict=True, templatedir=_TEMPLATEDIR, vcsbrowser=None):
+ debian_bundle.changelog.Changelog.__init__(self, file=file, max_blocks=max_blocks,
+ allow_empty_author=allow_empty_author,
+ strict=strict)
+ self.templatedir = templatedir
+ loader = TemplateLoader(self.templatedir)
+ self.html_tmpl = loader.load('cl.html')
+ self.block_tmpl = loader.load('block.html')
+ self.filter = HTMLChangelogFilter(vcsbrowser=vcsbrowser)
+
+ def markup_block(self, block):
+ return self.block_tmpl.generate(block=self.filter.markup_block(block))
+
+ def stream(self):
+ title = u"Changelog for %s (%s)" % (self.get_package(), self.get_version())
+ return self.html_tmpl.generate(title=title, blocks=self._blocks, markup_block=self.markup_block)
+
+ def __str__(self):
+ return self.stream().render('xhtml', doctype='xhtml-strict')
+