# Copyright (C) 2000-2002 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. from StandardLogger import StandardLogger from linkcheck.log import strtime import time, linkcheck, linkcheck.Config HTML_HEADER = """ %s """ class HtmlLogger (StandardLogger): """Logger with HTML output""" def __init__ (self, **args): apply(StandardLogger.__init__, (self,), 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 init (self): if self.fd is None: return self.starttime = time.time() self.fd.write(HTML_HEADER%(linkcheck.Config.App, self.colorbackground, self.colorlink, self.colorlink, self.colorlink)) if self.logfield('intro'): self.fd.write("

"+linkcheck.Config.App+"

"+ "
"+linkcheck.Config.Freeware+"

"+ (linkcheck._("Start checking at %s\n") % strtime(self.starttime))+ "

") self.fd.flush() def newUrl (self, urlData): if self.fd is None: return self.fd.write('
'+ urlData.parentName+" line "+str(urlData.line)+ "\n") if urlData.baseRef and self.logfield("base"): self.fd.write("\n") if urlData.url and self.logfield("realurl"): self.fd.write("\n") if urlData.downloadtime and self.logfield("dltime"): self.fd.write("\n") if urlData.checktime and self.logfield("checktime"): self.fd.write("\n") if urlData.infoString and self.logfield("info"): self.fd.write("\n") if urlData.warningString: #self.warnings += 1 if self.logfield("warning"): self.fd.write(""+self.tablewarning+linkcheck._("Warning")+ ""+self.tablewarning+ urlData.warningString.replace("\n", "
")+ "\n") if self.logfield("result"): if urlData.valid: self.fd.write(""+self.tableok+linkcheck._("Result")+""+ self.tableok+urlData.validString+"\n") else: self.errors += 1 self.fd.write(""+self.tableerror+linkcheck._("Result")+ ""+self.tableerror+ urlData.errorString+"\n") self.fd.write("
"+linkcheck._("Base")+""+ urlData.baseRef+"
"+linkcheck._("Real URL")+""+ ''+urlData.url+"
"+linkcheck._("D/L Time")+""+ (linkcheck._("%.3f seconds") % urlData.downloadtime)+ "
"+linkcheck._("Check Time")+ ""+ (linkcheck._("%.3f seconds") % urlData.checktime)+ "
"+linkcheck._("Info")+""+ linkcheck.StringUtil.htmlify(urlData.infoString)+ "


") self.fd.flush() def endOfOutput (self, linknumber=-1): if self.fd is None: return if self.logfield("outro"): self.fd.write("\n"+linkcheck._("Thats it. ")) #if self.warnings==1: # self.fd.write(linkcheck._("1 warning, ")) #else: # self.fd.write(str(self.warnings)+linkcheck._(" warnings, ")) if self.errors==1: self.fd.write(linkcheck._("1 error")) else: self.fd.write(str(self.errors)+linkcheck._(" errors")) if linknumber >= 0: if linknumber == 1: self.fd.write(linkcheck._(" in 1 link")) else: self.fd.write(linkcheck._(" in %d links") % linknumber) self.fd.write(linkcheck._(" found")+"\n
") self.stoptime = time.time() duration = self.stoptime - self.starttime name = linkcheck._("seconds") self.fd.write(linkcheck._("Stopped checking at %s") % strtime(self.stoptime)) if duration > 60: duration = duration / 60 name = linkcheck._("minutes") if duration > 60: duration = duration / 60 name = linkcheck._("hours") self.fd.write(" (%.3f %s)\n" % (duration, name)) self.fd.write("


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