mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-04-29 02:24:43 +00:00
Remove duplicate logger code.
This commit is contained in:
parent
23b20306e9
commit
166969f3a4
9 changed files with 33 additions and 81 deletions
|
|
@ -21,8 +21,9 @@ Output logging support for different formats.
|
|||
import sys
|
||||
import os
|
||||
import datetime
|
||||
import time
|
||||
from ..decorators import notimplemented
|
||||
from .. import log, LOG_CHECK, strformat, dummy
|
||||
from .. import log, LOG_CHECK, strformat, dummy, configuration
|
||||
|
||||
_ = lambda x: x
|
||||
Fields = dict(
|
||||
|
|
@ -244,6 +245,7 @@ class Logger (object):
|
|||
for key in parts:
|
||||
numspaces = (self.max_indent - len(self.part(key)))
|
||||
self.logspaces[key] = u" " * numspaces
|
||||
self.starttime = time.time()
|
||||
|
||||
def log_filter_url (self, url_data, do_print):
|
||||
"""
|
||||
|
|
@ -261,6 +263,25 @@ class Logger (object):
|
|||
self.warnings_printed += num_warnings
|
||||
self.log_url(url_data)
|
||||
|
||||
def write_intro (self):
|
||||
"""Write intro comments."""
|
||||
self.comment(_("created by %(app)s at %(time)s") %
|
||||
{"app": configuration.AppName,
|
||||
"time": strformat.strtime(self.starttime)})
|
||||
self.comment(_("Get the newest version at %(url)s") %
|
||||
{'url': configuration.Url})
|
||||
self.comment(_("Write comments and bugs to %(email)s") %
|
||||
{'email': configuration.Email})
|
||||
self.check_date()
|
||||
|
||||
def write_outro (self):
|
||||
"""Write outro comments."""
|
||||
self.stoptime = time.time()
|
||||
duration = self.stoptime - self.starttime
|
||||
self.comment(_("Stopped checking at %(time)s (%(duration)s)") %
|
||||
{"time": strformat.strtime(self.stoptime),
|
||||
"duration": strformat.strduration_long(duration)})
|
||||
|
||||
@notimplemented
|
||||
def log_url (self, url_data):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -17,11 +17,9 @@
|
|||
"""
|
||||
A CSV logger.
|
||||
"""
|
||||
import time
|
||||
import csv
|
||||
import os
|
||||
from . import Logger
|
||||
from .. import strformat, configuration
|
||||
|
||||
|
||||
class CSVLogger (Logger):
|
||||
|
|
@ -51,17 +49,9 @@ class CSVLogger (Logger):
|
|||
Write checking start info as csv comment.
|
||||
"""
|
||||
super(CSVLogger, self).start_output()
|
||||
self.starttime = time.time()
|
||||
row = []
|
||||
if self.has_part("intro"):
|
||||
self.comment(_("created by %(app)s at %(time)s") %
|
||||
{"app": configuration.AppName,
|
||||
"time": strformat.strtime(self.starttime)})
|
||||
self.comment(_("Get the newest version at %(url)s") %
|
||||
{'url': configuration.Url})
|
||||
self.comment(_("Write comments and bugs to %(email)s") %
|
||||
{'email': configuration.Email})
|
||||
self.check_date()
|
||||
self.write_intro()
|
||||
self.flush()
|
||||
else:
|
||||
# write empty string to initialize file output
|
||||
|
|
@ -115,10 +105,6 @@ class CSVLogger (Logger):
|
|||
"""
|
||||
Write end of checking info as csv comment.
|
||||
"""
|
||||
self.stoptime = time.time()
|
||||
if self.has_part("outro"):
|
||||
duration = self.stoptime - self.starttime
|
||||
self.comment(_("Stopped checking at %(time)s (%(duration)s)") %
|
||||
{"time": strformat.strtime(self.stoptime),
|
||||
"duration": strformat.strduration_long(duration)})
|
||||
self.write_outro()
|
||||
self.close_fileoutput()
|
||||
|
|
|
|||
|
|
@ -18,9 +18,7 @@
|
|||
A DOT graph format logger. The specification has been taken from
|
||||
http://www.graphviz.org/doc/info/lang.html
|
||||
"""
|
||||
import time
|
||||
from .graph import GraphLogger
|
||||
from .. import configuration, strformat
|
||||
|
||||
|
||||
class DOTLogger (GraphLogger):
|
||||
|
|
@ -31,16 +29,8 @@ class DOTLogger (GraphLogger):
|
|||
def start_output (self):
|
||||
"""Write start of checking info as DOT comment."""
|
||||
super(DOTLogger, self).start_output()
|
||||
self.starttime = time.time()
|
||||
if self.has_part("intro"):
|
||||
self.comment(_("created by %(app)s at %(time)s") %
|
||||
{"app": configuration.AppName,
|
||||
"time": strformat.strtime(self.starttime)})
|
||||
self.comment(_("Get the newest version at %(url)s") %
|
||||
{'url': configuration.Url})
|
||||
self.comment(_("Write comments and bugs to %(email)s") %
|
||||
{'email': configuration.Email})
|
||||
self.check_date()
|
||||
self.write_intro()
|
||||
self.writeln()
|
||||
self.writeln(u"digraph G {")
|
||||
self.writeln(u" graph [")
|
||||
|
|
|
|||
|
|
@ -17,9 +17,7 @@
|
|||
"""
|
||||
A gml logger.
|
||||
"""
|
||||
import time
|
||||
from .graph import GraphLogger
|
||||
from .. import configuration, strformat
|
||||
|
||||
|
||||
class GMLLogger (GraphLogger):
|
||||
|
|
@ -29,16 +27,8 @@ class GMLLogger (GraphLogger):
|
|||
def start_output (self):
|
||||
"""Write start of checking info as gml comment."""
|
||||
super(GMLLogger, self).start_output()
|
||||
self.starttime = time.time()
|
||||
if self.has_part("intro"):
|
||||
self.comment(_("created by %(app)s at %(time)s") %
|
||||
{"app": configuration.AppName,
|
||||
"time": strformat.strtime(self.starttime)})
|
||||
self.comment(_("Get the newest version at %(url)s") %
|
||||
{'url': configuration.Url})
|
||||
self.comment(_("Write comments and bugs to %(email)s") %
|
||||
{'email': configuration.Email})
|
||||
self.check_date()
|
||||
self.write_intro()
|
||||
self.writeln()
|
||||
self.writeln(u"graph [")
|
||||
self.writeln(u" directed 1")
|
||||
|
|
|
|||
|
|
@ -18,9 +18,7 @@
|
|||
Base class for graph loggers.
|
||||
"""
|
||||
from . import Logger
|
||||
from .. import strformat
|
||||
from ..decorators import notimplemented
|
||||
import time
|
||||
import re
|
||||
|
||||
|
||||
|
|
@ -80,11 +78,7 @@ class GraphLogger (Logger):
|
|||
self.write_edges()
|
||||
self.end_graph()
|
||||
if self.has_part("outro"):
|
||||
self.stoptime = time.time()
|
||||
duration = self.stoptime - self.starttime
|
||||
self.comment(_("Stopped checking at %(time)s (%(duration)s)") %
|
||||
{"time": strformat.strtime(self.stoptime),
|
||||
"duration": strformat.strduration_long(duration)})
|
||||
self.write_outro()
|
||||
self.close_fileoutput()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -86,7 +86,6 @@ class HtmlLogger (Logger):
|
|||
def start_output (self):
|
||||
"""Write start of checking info."""
|
||||
super(HtmlLogger, self).start_output()
|
||||
self.starttime = time.time()
|
||||
header = {
|
||||
"encoding": self.output_encoding,
|
||||
"title": configuration.App,
|
||||
|
|
|
|||
|
|
@ -18,10 +18,9 @@
|
|||
A SQL logger.
|
||||
"""
|
||||
|
||||
import time
|
||||
import os
|
||||
from . import Logger
|
||||
from .. import configuration, strformat, url as urlutil
|
||||
from .. import url as urlutil
|
||||
|
||||
|
||||
def sqlify (s):
|
||||
|
|
@ -72,17 +71,9 @@ class SQLLogger (Logger):
|
|||
"""
|
||||
Write start of checking info as sql comment.
|
||||
"""
|
||||
Logger.start_output(self)
|
||||
self.starttime = time.time()
|
||||
super(SQLLogger, self).start_output()
|
||||
if self.has_part("intro"):
|
||||
self.comment(_("created by %(app)s at %(time)s") %
|
||||
{"app": configuration.AppName,
|
||||
"time": strformat.strtime(self.starttime)})
|
||||
self.comment(_("Get the newest version at %s") %
|
||||
configuration.Url)
|
||||
self.comment(_("Write comments and bugs to %s") %
|
||||
configuration.Email)
|
||||
self.check_date()
|
||||
self.write_intro()
|
||||
self.writeln()
|
||||
self.flush()
|
||||
|
||||
|
|
@ -134,9 +125,5 @@ class SQLLogger (Logger):
|
|||
Write end of checking info as sql comment.
|
||||
"""
|
||||
if self.has_part("outro"):
|
||||
self.stoptime = time.time()
|
||||
duration = self.stoptime - self.starttime
|
||||
self.comment(_("Stopped checking at %(time)s (%(duration)s)") %
|
||||
{"time": strformat.strtime(self.stoptime),
|
||||
"duration": strformat.strduration_long(duration)})
|
||||
self.write_outro()
|
||||
self.close_fileoutput()
|
||||
|
|
|
|||
|
|
@ -94,7 +94,6 @@ class TextLogger (Logger):
|
|||
Write generic start checking info.
|
||||
"""
|
||||
super(TextLogger, self).start_output()
|
||||
self.starttime = time.time()
|
||||
if self.has_part('intro'):
|
||||
self.writeln(configuration.AppInfo)
|
||||
self.writeln(configuration.Freeware)
|
||||
|
|
|
|||
|
|
@ -18,10 +18,8 @@
|
|||
Base class for XML loggers.
|
||||
"""
|
||||
|
||||
import time
|
||||
import xml.sax.saxutils
|
||||
from . import Logger
|
||||
from .. import configuration, strformat
|
||||
|
||||
|
||||
xmlattr_entities = {
|
||||
|
|
@ -70,18 +68,10 @@ class XMLLogger (Logger):
|
|||
"""
|
||||
Write start of checking info as xml comment.
|
||||
"""
|
||||
self.starttime = time.time()
|
||||
self.writeln(u'<?xml version="1.0" encoding="%s"?>' %
|
||||
xmlquoteattr(self.output_encoding))
|
||||
if self.has_part("intro"):
|
||||
self.comment(_("created by %(app)s at %(time)s") %
|
||||
{"app": configuration.AppName,
|
||||
"time": strformat.strtime(self.starttime)})
|
||||
self.comment(_("Get the newest version at %(url)s") %
|
||||
{'url': configuration.Url})
|
||||
self.comment(_("Write comments and bugs to %(email)s") %
|
||||
{'email': configuration.Email})
|
||||
self.check_date()
|
||||
self.write_intro()
|
||||
self.writeln()
|
||||
|
||||
def xml_end_output (self):
|
||||
|
|
@ -89,11 +79,7 @@ class XMLLogger (Logger):
|
|||
Write end of checking info as xml comment.
|
||||
"""
|
||||
if self.has_part("outro"):
|
||||
self.stoptime = time.time()
|
||||
duration = self.stoptime - self.starttime
|
||||
self.comment(_("Stopped checking at %(time)s (%(duration)s)") %
|
||||
{"time": strformat.strtime(self.stoptime),
|
||||
"duration": strformat.strduration_long(duration)})
|
||||
self.write_outro()
|
||||
|
||||
def xml_starttag (self, name, attrs=None):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue