mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-04-01 05:30:26 +00:00
Logging refactor, interrupt and abort flags added.
This commit is contained in:
parent
b152ce7a6e
commit
43c2e6641b
14 changed files with 24 additions and 23 deletions
|
|
@ -163,7 +163,7 @@ def interrupt (aggregate):
|
|||
while True:
|
||||
try:
|
||||
log.warn(LOG_CHECK,
|
||||
_("user interrupt; waiting for active threads to finish"))
|
||||
_("interrupt; waiting for active threads to finish"))
|
||||
log.warn(LOG_CHECK,
|
||||
_("another interrupt will exit immediately"))
|
||||
abort(aggregate)
|
||||
|
|
@ -178,11 +178,11 @@ def abort (aggregate):
|
|||
try:
|
||||
aggregate.abort()
|
||||
aggregate.finish()
|
||||
aggregate.end_log_output()
|
||||
aggregate.end_log_output(interrupt=True)
|
||||
break
|
||||
except KeyboardInterrupt:
|
||||
log.warn(LOG_CHECK, _("user abort; force shutdown"))
|
||||
aggregate.end_log_output()
|
||||
aggregate.end_log_output(abort=True)
|
||||
abort_now()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -173,10 +173,10 @@ class Aggregate (object):
|
|||
"""Add to number of downloaded bytes."""
|
||||
self.downloaded_bytes += numbytes
|
||||
|
||||
def end_log_output(self):
|
||||
def end_log_output(self, **kwargs):
|
||||
"""Print ending output to log."""
|
||||
kwargs = dict(
|
||||
kwargs.update(dict(
|
||||
downloaded_bytes=self.downloaded_bytes,
|
||||
num_urls = len(self.result_cache),
|
||||
)
|
||||
))
|
||||
self.logger.end_log_output(**kwargs)
|
||||
|
|
|
|||
|
|
@ -55,9 +55,9 @@ class SignalLogger (_Logger):
|
|||
"""Emit URL data which gets logged in the main window."""
|
||||
self.log_url_signal.emit(url_data)
|
||||
|
||||
def end_output (self, downloaded_bytes=None, num_urls=None):
|
||||
def end_output (self, **kwargs):
|
||||
"""Emit statistic data which gets logged in the main window."""
|
||||
self.stats.downloaded_bytes = downloaded_bytes
|
||||
self.stats.downloaded_bytes = kwargs.get("downloaded_bytes")
|
||||
self.log_stats_signal.emit(self.stats)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -139,9 +139,10 @@ class _Logger (object):
|
|||
* start_output()
|
||||
Initialize and start log output. Most loggers print a comment
|
||||
with copyright information.
|
||||
* end_output()
|
||||
* end_output(**kwargs)
|
||||
Finish log output, possibly flushing buffers. Most loggers also
|
||||
print some statistics.
|
||||
Custom keyword arguments can be given for different loggers.
|
||||
* log_filter_url(url_data, do_print)
|
||||
Log a checked URL. The url_data object is a transport form of
|
||||
the UrlData class. The do_print flag indicates if this URL
|
||||
|
|
@ -151,7 +152,7 @@ class _Logger (object):
|
|||
|
||||
* start_output()
|
||||
Also call the base class implementation of this.
|
||||
* end_output()
|
||||
* end_output(**kwargs)
|
||||
See above.
|
||||
* log_url(url_data)
|
||||
Log a checked URL. Called by log_filter_url if do_print is True.
|
||||
|
|
@ -401,7 +402,7 @@ class _Logger (object):
|
|||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def end_output (self, downloaded_bytes=None, num_urls=None):
|
||||
def end_output (self, **kwargs):
|
||||
"""
|
||||
End of output, used for cleanup (eg output buffer flushing).
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ class BlacklistLogger (_Logger):
|
|||
if not url_data.valid:
|
||||
self.blacklist[key] = 1
|
||||
|
||||
def end_output (self, downloaded_bytes=None, num_urls=None):
|
||||
def end_output (self, **kwargs):
|
||||
"""
|
||||
Write blacklist file.
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ class CSVLogger (_Logger):
|
|||
# empty queue
|
||||
self.queue.truncate(0)
|
||||
|
||||
def end_output (self, downloaded_bytes=None, num_urls=None):
|
||||
def end_output (self, **kwargs):
|
||||
"""Write end of checking info as csv comment."""
|
||||
if self.has_part("outro"):
|
||||
self.write_outro()
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ class CustomXMLLogger (xmllog._XMLLogger):
|
|||
self.xml_endtag(u'urldata')
|
||||
self.flush()
|
||||
|
||||
def end_output (self, downloaded_bytes=None, num_urls=None):
|
||||
def end_output (self, **kwargs):
|
||||
"""
|
||||
Write XML end tag.
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ class _GraphLogger (_Logger):
|
|||
"""Write end-of-graph marker."""
|
||||
pass
|
||||
|
||||
def end_output (self, downloaded_bytes=None, num_urls=None):
|
||||
def end_output (self, **kwargs):
|
||||
"""Write edges and end of checking info as gml comment."""
|
||||
self.write_edges()
|
||||
self.end_graph()
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ class GraphXMLLogger (_XMLLogger, _GraphLogger):
|
|||
self.xml_endtag(u"data")
|
||||
self.xml_endtag(u"edge")
|
||||
|
||||
def end_output (self, downloaded_bytes=None, num_urls=None):
|
||||
def end_output (self, **kwargs):
|
||||
"""Finish graph output, and print end of checking info as xml
|
||||
comment."""
|
||||
self.xml_endtag(u"graph")
|
||||
|
|
|
|||
|
|
@ -328,7 +328,7 @@ class HtmlLogger (_Logger):
|
|||
configuration.DonateUrl+u"</a>."))
|
||||
self.writeln(u"</small></body></html>")
|
||||
|
||||
def end_output (self, downloaded_bytes=None, num_urls=None):
|
||||
def end_output (self, **kwargs):
|
||||
"""Write end of checking info as HTML."""
|
||||
if self.has_part("stats"):
|
||||
self.write_stats()
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class NoneLogger (_Logger):
|
|||
"""Do nothing."""
|
||||
pass
|
||||
|
||||
def end_output (self, downloaded_bytes=None, num_urls=None):
|
||||
def end_output (self, **kwargs):
|
||||
"""
|
||||
Do nothing.
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ class SitemapXmlLogger (xmllog._XMLLogger):
|
|||
self.xml_endtag(u'url')
|
||||
self.flush()
|
||||
|
||||
def end_output (self, downloaded_bytes=None, num_urls=None):
|
||||
def end_output (self, **kwargs):
|
||||
"""Write XML end tag."""
|
||||
self.xml_endtag(u"urlset")
|
||||
self.xml_end_output()
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ class SQLLogger (_Logger):
|
|||
})
|
||||
self.flush()
|
||||
|
||||
def end_output (self, downloaded_bytes=None, num_urls=None):
|
||||
def end_output (self, **kwargs):
|
||||
"""
|
||||
Write end of checking info as sql comment.
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -282,10 +282,10 @@ class TextLogger (_Logger):
|
|||
else:
|
||||
self.writeln(_("No statistics available since no URLs were checked."))
|
||||
|
||||
def end_output (self, downloaded_bytes=None, num_urls=None):
|
||||
def end_output (self, **kwargs):
|
||||
"""Write end of output info, and flush all output buffers."""
|
||||
self.stats.downloaded_bytes = downloaded_bytes
|
||||
self.stats.num_urls = num_urls
|
||||
self.stats.downloaded_bytes = kwargs.get("downloaded_bytes")
|
||||
self.stats.num_urls = kwargs.get("num_urls")
|
||||
if self.has_part('stats'):
|
||||
self.write_stats()
|
||||
if self.has_part('outro'):
|
||||
|
|
|
|||
Loading…
Reference in a new issue