| 1 | #!/usr/bin/env python |
|---|
| 2 | # -*- coding: utf-8 -*- |
|---|
| 3 | # |
|---|
| 4 | # Copyright (C) 2006-2008 Alec Thomas |
|---|
| 5 | # Copyright (C) 2010-2012 Ryan J Ollos <ryan.j.ollos@gmail.com> |
|---|
| 6 | # All rights reserved. |
|---|
| 7 | # |
|---|
| 8 | # This software is licensed as described in the file COPYING, which |
|---|
| 9 | # you should have received as part of this distribution. |
|---|
| 10 | # |
|---|
| 11 | |
|---|
| 12 | from trac.core import * |
|---|
| 13 | from trac.util import escape, Markup |
|---|
| 14 | from trac.wiki.api import parse_args |
|---|
| 15 | from trac.wiki.macros import WikiMacroBase |
|---|
| 16 | from trac.wiki.formatter import wiki_to_html |
|---|
| 17 | from trac.util import format_datetime |
|---|
| 18 | from StringIO import StringIO |
|---|
| 19 | |
|---|
| 20 | class ChangeLogMacro(WikiMacroBase): |
|---|
| 21 | """ Provides the macro |
|---|
| 22 | |
|---|
| 23 | {{{ |
|---|
| 24 | [[ChangeLog(path[,limit[,rev]])]] |
|---|
| 25 | }}} |
|---|
| 26 | |
|---|
| 27 | which dumps the change log for path of revision rev, back |
|---|
| 28 | limit revisions. "rev" can be 0 for the latest revision. |
|---|
| 29 | |
|---|
| 30 | limit and rev may be keyword arguments |
|---|
| 31 | """ |
|---|
| 32 | |
|---|
| 33 | def expand_macro(self, formatter, name, content): |
|---|
| 34 | req = formatter.req |
|---|
| 35 | args, kwargs = parse_args(content) |
|---|
| 36 | args += [None, None] |
|---|
| 37 | path, limit, rev = args[:3] |
|---|
| 38 | limit = kwargs.pop('limit', limit) |
|---|
| 39 | rev = kwargs.pop('rev', rev) |
|---|
| 40 | |
|---|
| 41 | if 'CHANGESET_VIEW' not in req.perm: |
|---|
| 42 | return Markup('<i>Changelog not available</i>') |
|---|
| 43 | |
|---|
| 44 | repo = self.env.get_repository(req.authname) |
|---|
| 45 | |
|---|
| 46 | if rev is None: |
|---|
| 47 | rev = repo.get_youngest_rev() |
|---|
| 48 | rev = repo.normalize_rev(rev) |
|---|
| 49 | path = repo.normalize_path(path) |
|---|
| 50 | if limit is None: |
|---|
| 51 | limit = 5 |
|---|
| 52 | else: |
|---|
| 53 | limit = int(limit) |
|---|
| 54 | node = repo.get_node(path, rev) |
|---|
| 55 | out = StringIO() |
|---|
| 56 | out.write('<div class="changelog">\n') |
|---|
| 57 | for npath, nrev, nlog in node.get_history(limit): |
|---|
| 58 | change = repo.get_changeset(nrev) |
|---|
| 59 | datetime = format_datetime(change.date, '%Y/%m/%d %H:%M:%S', req.tz) |
|---|
| 60 | out.write(wiki_to_html("'''[%s] by %s on %s'''\n\n%s" % |
|---|
| 61 | (nrev, change.author, datetime, change.message), |
|---|
| 62 | self.env, req)); |
|---|
| 63 | out.write('</div>\n') |
|---|
| 64 | return out.getvalue() |
|---|