mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-04-08 00:20:59 +00:00
count errors, warnings and number of checked links in the logger classes
git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@2527 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
parent
a3125087fc
commit
040139e6d8
10 changed files with 47 additions and 27 deletions
|
|
@ -62,8 +62,12 @@ class Logger (object):
|
|||
self.logspaces = {}
|
||||
# maximum indent of spaces for alignment
|
||||
self.max_indent = 0
|
||||
# number of logged urls
|
||||
self.number = 0
|
||||
# number of encountered errors
|
||||
self.errors = 0
|
||||
# number of encountered warningss
|
||||
self.warnings = 0
|
||||
# encoding of output
|
||||
self.output_encoding = args.get("encoding", "iso-8859-1")
|
||||
|
||||
|
|
@ -177,13 +181,25 @@ class Logger (object):
|
|||
numspaces = (self.max_indent - len(self.field(key)))
|
||||
self.logspaces[key] = u" " * numspaces
|
||||
|
||||
def new_url (self, url_data):
|
||||
def log_filter_url (self, url_data, do_print):
|
||||
"""
|
||||
Log a new url with this logger if do_filter is True. Else
|
||||
only update accounting data
|
||||
"""
|
||||
self.number += 1
|
||||
if not url_data.valid:
|
||||
self.errors += 1
|
||||
self.warnings += len(url_data.warning)
|
||||
if do_print:
|
||||
self.log_url(url_data)
|
||||
|
||||
def log_url (self, url_data):
|
||||
"""
|
||||
Log a new url with this logger.
|
||||
"""
|
||||
raise NotImplementedError, "abstract function"
|
||||
|
||||
def end_output (self, linknumber=-1):
|
||||
def end_output (self):
|
||||
"""
|
||||
End of output, used for cleanup (eg output buffer flushing).
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ class BlacklistLogger (linkcheck.logger.Logger):
|
|||
"""
|
||||
pass
|
||||
|
||||
def new_url (self, url_data):
|
||||
def log_url (self, url_data):
|
||||
"""
|
||||
Put invalid url in blacklist, delete valid url from blacklist.
|
||||
"""
|
||||
|
|
@ -71,7 +71,7 @@ class BlacklistLogger (linkcheck.logger.Logger):
|
|||
if not url_data.valid:
|
||||
self.blacklist[key] = 1
|
||||
|
||||
def end_output (self, linknumber=-1):
|
||||
def end_output (self):
|
||||
"""
|
||||
Write blacklist file.
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ class CSVLogger (linkcheck.logger.Logger):
|
|||
if row:
|
||||
self.writer.writerow(row)
|
||||
|
||||
def new_url (self, url_data):
|
||||
def log_url (self, url_data):
|
||||
"""
|
||||
Print csv formatted url check info.
|
||||
"""
|
||||
|
|
@ -116,7 +116,7 @@ class CSVLogger (linkcheck.logger.Logger):
|
|||
self.writer.writerow(row)
|
||||
self.flush()
|
||||
|
||||
def end_output (self, linknumber=-1):
|
||||
def end_output (self):
|
||||
"""
|
||||
Print end of checking info as csv comment.
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ class DOTLogger (linkcheck.logger.Logger):
|
|||
self.write(u"// ")
|
||||
self.writeln(s=s, **args)
|
||||
|
||||
def new_url (self, url_data):
|
||||
def log_url (self, url_data):
|
||||
"""
|
||||
Write one node and all possible edges.
|
||||
"""
|
||||
|
|
@ -106,7 +106,7 @@ class DOTLogger (linkcheck.logger.Logger):
|
|||
self.writeln(u" ];")
|
||||
self.flush()
|
||||
|
||||
def end_output (self, linknumber=-1):
|
||||
def end_output (self):
|
||||
"""
|
||||
Print end of checking info as DOT comment.
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ class GMLLogger (linkcheck.logger.Logger):
|
|||
self.write(u"# ")
|
||||
self.writeln(s=s, **args)
|
||||
|
||||
def new_url (self, url_data):
|
||||
def log_url (self, url_data):
|
||||
"""
|
||||
Write one node and all possible edges.
|
||||
"""
|
||||
|
|
@ -110,7 +110,7 @@ class GMLLogger (linkcheck.logger.Logger):
|
|||
self.writeln(u" ]")
|
||||
self.flush()
|
||||
|
||||
def end_output (self, linknumber=-1):
|
||||
def end_output (self):
|
||||
"""
|
||||
Print end of checking info as gml comment.
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ class HtmlLogger (linkcheck.logger.Logger):
|
|||
self.check_date()
|
||||
self.flush()
|
||||
|
||||
def new_url (self, url_data):
|
||||
def log_url (self, url_data):
|
||||
"""
|
||||
Print url checking info as HTML.
|
||||
"""
|
||||
|
|
@ -267,7 +267,6 @@ class HtmlLogger (linkcheck.logger.Logger):
|
|||
self.field("result")+u"</td><td bgcolor=\""+self.colorok+u"\">")
|
||||
self.write(_("Valid"))
|
||||
else:
|
||||
self.errors += 1
|
||||
self.write(u"<tr><td bgcolor=\""+self.colorerror+u"\">"+
|
||||
self.field("result")+u"</td><td bgcolor=\""+self.colorerror+u"\">")
|
||||
self.write(_("Error"))
|
||||
|
|
@ -275,7 +274,7 @@ class HtmlLogger (linkcheck.logger.Logger):
|
|||
self.write(u": "+cgi.escape(url_data.result))
|
||||
self.writeln(u"</td></tr>")
|
||||
|
||||
def end_output (self, linknumber=-1):
|
||||
def end_output (self):
|
||||
"""
|
||||
Print end of checking info as HTML.
|
||||
"""
|
||||
|
|
@ -284,10 +283,13 @@ class HtmlLogger (linkcheck.logger.Logger):
|
|||
if self.has_field("outro"):
|
||||
self.writeln()
|
||||
self.write(_("That's it.")+" ")
|
||||
if linknumber >= 0:
|
||||
if self.number >= 0:
|
||||
self.write(_n("%d link checked.", "%d links checked.",
|
||||
linknumber) % linknumber)
|
||||
self.number) % self.number)
|
||||
self.write(u" ")
|
||||
self.write(_n("%d warning found.", "%d warnings found.",
|
||||
self.warnings) % self.warnings)
|
||||
self.write(u" ")
|
||||
self.writeln(_n("%d error found.", "%d errors found.",
|
||||
self.errors) % self.errors)
|
||||
self.writeln(u"<br>")
|
||||
|
|
|
|||
|
|
@ -38,13 +38,13 @@ class NoneLogger (linkcheck.logger.Logger):
|
|||
"""
|
||||
pass
|
||||
|
||||
def new_url (self, url_data):
|
||||
def log_filter_url (self, url_data, do_filter):
|
||||
"""
|
||||
Do nothing.
|
||||
"""
|
||||
pass
|
||||
|
||||
def end_output (self, linknumber=-1):
|
||||
def end_output (self):
|
||||
"""
|
||||
Do nothing.
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ class SQLLogger (linkcheck.logger.Logger):
|
|||
self.writeln()
|
||||
self.flush()
|
||||
|
||||
def new_url (self, url_data):
|
||||
def log_url (self, url_data):
|
||||
"""
|
||||
Store url check info into the database.
|
||||
"""
|
||||
|
|
@ -136,7 +136,7 @@ class SQLLogger (linkcheck.logger.Logger):
|
|||
})
|
||||
self.flush()
|
||||
|
||||
def end_output (self, linknumber=-1):
|
||||
def end_output (self):
|
||||
"""
|
||||
Print end of checking info as sql comment.
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class TextLogger (linkcheck.logger.Logger):
|
|||
as a default and then switch to another configured output. So we
|
||||
must not print anything out at __init__ time.
|
||||
|
||||
C{def new_url (self, url_data)}
|
||||
C{def log_filter_url (self, url_data, do_filter)}
|
||||
Called every time an url finished checking. All data we checked is in
|
||||
the UrlData object url_data.
|
||||
|
||||
|
|
@ -105,7 +105,7 @@ class TextLogger (linkcheck.logger.Logger):
|
|||
linkcheck.strformat.strtime(self.starttime))
|
||||
self.flush()
|
||||
|
||||
def new_url (self, url_data):
|
||||
def log_url (self, url_data):
|
||||
"""
|
||||
Print url checking info.
|
||||
"""
|
||||
|
|
@ -224,14 +224,13 @@ class TextLogger (linkcheck.logger.Logger):
|
|||
color = self.colorvalid
|
||||
self.write(_("Valid"), color=color)
|
||||
else:
|
||||
self.errors += 1
|
||||
color = self.colorinvalid
|
||||
self.write(_("Error"), color=color)
|
||||
if url_data.result:
|
||||
self.write(u": "+url_data.result, color=color)
|
||||
self.writeln()
|
||||
|
||||
def end_output (self, linknumber=-1):
|
||||
def end_output (self):
|
||||
"""
|
||||
Print end of output info, and flush all output buffers.
|
||||
"""
|
||||
|
|
@ -240,11 +239,14 @@ class TextLogger (linkcheck.logger.Logger):
|
|||
if self.has_field('outro'):
|
||||
self.writeln()
|
||||
self.write(_("That's it.")+" ")
|
||||
if linknumber >= 0:
|
||||
if self.number >= 0:
|
||||
self.write(_n("%d link checked.", "%d links checked.",
|
||||
linknumber) % linknumber)
|
||||
self.number) % self.number)
|
||||
self.write(u" ")
|
||||
|
||||
self.write(_n("%d warning found.", "%d warnings found.",
|
||||
self.warnings) % self.warnings)
|
||||
self.write(u" ")
|
||||
self.writeln(_n("%d error found.", "%d errors found.",
|
||||
self.errors) % self.errors)
|
||||
self.stoptime = time.time()
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ class XMLLogger (linkcheck.logger.Logger):
|
|||
self.writeln(u'<graph isDirected="true">')
|
||||
self.flush()
|
||||
|
||||
def new_url (self, url_data):
|
||||
def low_url (self, url_data):
|
||||
"""
|
||||
Write one node and all possible edges.
|
||||
"""
|
||||
|
|
@ -157,7 +157,7 @@ class XMLLogger (linkcheck.logger.Logger):
|
|||
self.writeln(u" </edge>")
|
||||
self.flush()
|
||||
|
||||
def end_output (self, linknumber=-1):
|
||||
def end_output (self):
|
||||
"""
|
||||
Finish graph output, and print end of checking info as xml comment.
|
||||
"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue