| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
from html import escape |
| 19 |
import codecs |
| 20 |
from io import StringIO, BytesIO |
| 21 |
|
| 22 |
from breezy import log |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
def log_as_html(branch, rqst): |
| 38 |
"""Get the log for a branch as HTML text.""" |
| 39 |
sio = codecs.getwriter('utf-8')(BytesIO()) |
| 40 |
|
| 41 |
try: |
| 42 |
lf = HtmlLogFormatter(sio) |
| 43 |
log.Logger(branch, rqst).show(lf) |
| 44 |
return sio.getvalue().decode('utf-8') |
| 45 |
finally: |
| 46 |
sio.close() |
| 47 |
|
| 48 |
class HtmlLogFormatter(log.LineLogFormatter): |
| 49 |
|
| 50 |
def __init__(self, *args, **kwargs): |
| 51 |
super(HtmlLogFormatter, self).__init__(*args, **kwargs) |
| 52 |
self.show_markers = False |
| 53 |
|
| 54 |
def begin_log(self): |
| 55 |
self.to_file.write('<table>\n') |
| 56 |
headers = ['Rev', 'Message', 'Date', 'Author'] |
| 57 |
if self.show_markers: |
| 58 |
headers.append('Markers') |
| 59 |
self.to_file.write(self._make_row(headers, header=True)) |
| 60 |
|
| 61 |
def end_log(self): |
| 62 |
self.to_file.write("</table>\n") |
| 63 |
|
| 64 |
def log_revision(self, revision): |
| 65 |
rev = revision.rev |
| 66 |
cells = [] |
| 67 |
if revision.revno: |
| 68 |
|
| 69 |
revno_str = "%s" % revision.revno |
| 70 |
else: |
| 71 |
|
| 72 |
revno_str = "" |
| 73 |
cells.append(revno_str) |
| 74 |
cells.append(rev.get_summary()) |
| 75 |
cells.append(self.date_string(rev)) |
| 76 |
cells.append(self.author_string(rev)) |
| 77 |
if self.show_markers: |
| 78 |
markers = [] |
| 79 |
if len(rev.parent_ids) > 1: |
| 80 |
markers.append('[merge]') |
| 81 |
if revision.tags: |
| 82 |
markers.append('{%s} ' % (', '.join(revision.tags))) |
| 83 |
cells.append(" ".join(markers)) |
| 84 |
self.to_file.write(self._make_row(cells)) |
| 85 |
|
| 86 |
def author_string(self, rev): |
| 87 |
return self.short_author(rev) |
| 88 |
|
| 89 |
def _make_row(self, cells, header=False): |
| 90 |
if header: |
| 91 |
cells = ['<th align="left">%s</th>' % escape(cell) |
| 92 |
for cell in cells] |
| 93 |
else: |
| 94 |
cells = ["<td>%s </td>" % escape(cell) |
| 95 |
for cell in cells] |
| 96 |
return "<tr>%s</tr>\n" % ''.join(cells) |