linkchecker/linkcheck/gui/logger.py

76 lines
2.5 KiB
Python
Raw Normal View History

# -*- coding: iso-8859-1 -*-
2014-01-08 21:33:04 +00:00
# Copyright (C) 2009-2014 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.
#
2009-07-24 21:58:20 +00:00
# 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.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
from logging import Handler
2013-12-11 17:41:55 +00:00
from ..logger import _Logger
class GuiLogHandler (Handler, object):
2009-02-24 20:51:44 +00:00
"""Delegate log messages to the UI."""
2010-11-18 22:26:34 +00:00
def __init__ (self, signal):
2009-02-24 20:51:44 +00:00
"""Save widget."""
super(GuiLogHandler, self).__init__()
2010-11-18 22:26:34 +00:00
self.signal = signal
def emit (self, record):
2010-10-14 19:13:28 +00:00
"""Emit a record. It gets logged in the debug widget."""
2010-11-18 22:26:34 +00:00
self.signal.emit(self.format(record))
2013-12-11 17:41:55 +00:00
class SignalLogger (_Logger):
"""Use Qt signals for logged URLs and statistics."""
2013-12-11 17:41:55 +00:00
LoggerName = "gui"
def __init__ (self, **args):
2011-02-17 18:59:02 +00:00
"""Store signals for URL and statistic data."""
super(SignalLogger, self).__init__(**args)
2010-11-18 22:26:34 +00:00
self.log_url_signal = args["signal"]
self.log_stats_signal = args["stats"]
def start_fileoutput (self):
2011-02-17 18:59:02 +00:00
"""Override fileoutput handling of base class."""
pass
def close_fileoutput (self):
2011-02-17 18:59:02 +00:00
"""Override fileoutput handling of base class."""
pass
def log_url (self, url_data):
2011-02-17 18:59:02 +00:00
"""Emit URL data which gets logged in the main window."""
2010-11-18 22:26:34 +00:00
self.log_url_signal.emit(url_data)
2014-03-14 20:06:10 +00:00
def end_output (self, downloaded_bytes=None):
2011-02-17 18:59:02 +00:00
"""Emit statistic data which gets logged in the main window."""
2014-03-14 20:06:10 +00:00
self.stats.downloaded_bytes = downloaded_bytes
self.log_stats_signal.emit(self.stats)
2011-05-07 19:14:08 +00:00
class StatusLogger (object):
"""GUI status logger, signaling to progress labels."""
def __init__ (self, signal):
"""Store given signal object."""
self.signal = signal
2014-03-14 20:06:10 +00:00
def log_status (self, checked, in_progress, queued, duration,
downloaded_bytes):
2011-05-07 19:14:08 +00:00
"""Emit signal with given status information."""
2014-03-14 20:06:10 +00:00
self.signal.emit(checked, in_progress, queued, duration,
downloaded_bytes)