# Copyright (C) 2009 Canonical Ltd # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA from html import escape import codecs from io import StringIO, BytesIO from breezy import log # def log_as_html(branch, rqst): # """Get the log for a branch as HTML text.""" # sio = codecs.getwriter('utf-8')(StringIO()) # #sio.encoding = 'utf-8' # try: # lf = HtmlLogFormatter(sio) # log.Logger(branch, rqst).show(lf) # return sio.getvalue().decode('utf-8') # finally: # sio.close() def log_as_html(branch, rqst): """Get the log for a branch as HTML text.""" sio = codecs.getwriter('utf-8')(BytesIO()) #sio.encoding = 'utf-8' try: lf = HtmlLogFormatter(sio) log.Logger(branch, rqst).show(lf) return sio.getvalue().decode('utf-8') finally: sio.close() class HtmlLogFormatter(log.LineLogFormatter): def __init__(self, *args, **kwargs): super(HtmlLogFormatter, self).__init__(*args, **kwargs) self.show_markers = False def begin_log(self): self.to_file.write('