# -*- coding: iso-8859-1 -*- """a html logger""" # Copyright (C) 2000-2004 Bastian Kleineidam # # 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., 675 Mass Ave, Cambridge, MA 02139, USA. import time import cgi import os import linkcheck.logger import linkcheck.logger.standard import linkcheck.strformat import linkcheck.configuration from linkcheck.i18n import _ HTML_HEADER = """ %s """ class HtmlLogger (linkcheck.logger.standard.StandardLogger): """Logger with HTML output""" def __init__ (self, **args): """initialize default HTML color values""" super(HtmlLogger, self).__init__(**args) self.colorbackground = args['colorbackground'] self.colorurl = args['colorurl'] self.colorborder = args['colorborder'] self.colorlink = args['colorlink'] self.tablewarning = args['tablewarning'] self.tableerror = args['tableerror'] self.tableok = args['tableok'] def start_output (self): """print start of checking info""" linkcheck.logger.Logger.start_output(self) if self.fd is None: return self.starttime = time.time() self.fd.write(HTML_HEADER % (linkcheck.configuration.App, self.colorbackground, self.colorlink, self.colorlink, self.colorlink)) if self.has_field('intro'): self.fd.write("

"+linkcheck.configuration.App+ "


"+ linkcheck.configuration.Freeware+"

"+ (_("Start checking at %s\n") % \ linkcheck.strformat.strtime(self.starttime))+ "
") self.flush() def new_url (self, url_data): """print url checking info as HTML""" if self.fd is None: return self.fd.write("

\n"+ "\n"+ "\n"+ "
\n"+ "\n") if self.has_field("url"): self.fd.write("\n"+ "\n"+ "\n\n") if url_data.name and self.has_field("name"): self.fd.write("\n\n\n\n") if url_data.parent_url and self.has_field("parenturl"): self.fd.write("\n\n\n\n") if url_data.base_ref and self.has_field("base"): self.fd.write("\n\n\n\n") if url_data.url and self.has_field("realurl"): self.fd.write("\n\n\n\n") if url_data.dltime >= 0 and self.has_field("dltime"): self.fd.write("\n\n\n\n") if url_data.dlsize >= 0 and self.has_field("dlsize"): self.fd.write("\n\n\n\n") if url_data.checktime and self.has_field("checktime"): self.fd.write("\n\n\n\n") if url_data.info and self.has_field("info"): text = os.linesep.join(url_data.info) self.fd.write("\n\n\n\n") if url_data.warning and self.has_field("warning"): text = os.linesep.join(url_data.warning) self.fd.write("\n"+ self.tablewarning+self.field("warning")+ "\n"+self.tablewarning+ cgi.escape(text).replace(os.linesep, "
")+ "\n\n") if self.has_field("result"): if url_data.valid: self.fd.write("\n"+self.tableok+ self.field("result")+"\n"+ self.tableok+url_data.result+"\n\n") else: self.errors += 1 self.fd.write("\n"+self.tableerror+self.field("result")+ "\n"+self.tableerror+ url_data.result+"\n\n") self.fd.write("
"+self.field("url")+""+url_data.base_url) if url_data.cached: self.fd.write(_(" (cached)")) self.fd.write("
"+self.field("name")+""+ url_data.name+"
"+self.field("parenturl")+ ''+ (url_data.parent_url or "")+"") if url_data.line: self.fd.write(_(", line %d")%url_data.line) if url_data.column: self.fd.write(_(", col %d")%url_data.column) self.fd.write("
"+self.field("base")+""+ url_data.base_ref+"
"+self.field("realurl")+""+ ''+url_data.url+"
"+self.field("dltime")+""+ (_("%.3f seconds") % url_data.dltime)+ "
"+self.field("dlsize")+""+ linkcheck.strformat.strsize(url_data.dlsize)+ "
"+self.field("checktime")+ ""+ (_("%.3f seconds") % url_data.checktime)+ "
"+self.field("info")+""+ cgi.escape(text).replace(os.linesep, "
")+ "

") self.flush() def end_output (self, linknumber=-1): """print end of checking info as HTML""" if self.fd is None: return if self.has_field("outro"): self.fd.write("\n"+_("Thats it. ")) #if self.warnings == 1: # self.fd.write(_("1 warning, ")) #else: # self.fd.write(str(self.warnings)+_(" warnings, ")) if self.errors == 1: self.fd.write(_("1 error")) else: self.fd.write(str(self.errors)+_(" errors")) if linknumber >= 0: if linknumber == 1: self.fd.write(_(" in 1 link")) else: self.fd.write(_(" in %d links") % linknumber) self.fd.write(_(" found")+"\n
") self.stoptime = time.time() duration = self.stoptime - self.starttime self.fd.write(_("Stopped checking at %s (%s)\n")%\ (linkcheck.strformat.strtime(self.stoptime), linkcheck.strformat.strduration(duration))) self.fd.write("


"+ linkcheck.configuration.HtmlAppInfo+"
") self.fd.write(_("Get the newest version at %s\n") %\ (''+ linkcheck.configuration.Url+ ".
")) self.fd.write(_("Write comments and bugs to %s\n\n") %\ (''+ linkcheck.configuration.Email+".")) self.fd.write("
") self.flush() self.fd = None