2014-01-08 21:33:04 +00:00
|
|
|
# Copyright (C) 2000-2014 Bastian Kleineidam
|
2005-07-15 21:37:16 +00:00
|
|
|
#
|
|
|
|
|
# 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.
|
2005-07-15 21:37:16 +00:00
|
|
|
"""
|
2005-07-16 07:12:15 +00:00
|
|
|
An XML logger.
|
2005-07-15 21:37:16 +00:00
|
|
|
"""
|
2008-05-09 06:16:03 +00:00
|
|
|
from . import xmllog
|
|
|
|
|
from .. import strformat
|
2005-07-15 21:37:16 +00:00
|
|
|
|
|
|
|
|
|
2020-05-16 19:19:42 +00:00
|
|
|
class CustomXMLLogger(xmllog._XMLLogger):
|
2005-07-15 21:37:16 +00:00
|
|
|
"""
|
|
|
|
|
XML custom output for easy post-processing.
|
|
|
|
|
"""
|
|
|
|
|
|
2013-12-11 17:41:55 +00:00
|
|
|
LoggerName = "xml"
|
|
|
|
|
|
|
|
|
|
LoggerArgs = {
|
|
|
|
|
"filename": "linkchecker-out.xml",
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-16 19:19:42 +00:00
|
|
|
def start_output(self):
|
2005-07-15 21:37:16 +00:00
|
|
|
"""
|
2005-07-16 07:12:15 +00:00
|
|
|
Write start of checking info as xml comment.
|
2005-07-15 21:37:16 +00:00
|
|
|
"""
|
2020-06-03 19:06:36 +00:00
|
|
|
super().start_output()
|
2005-07-15 21:37:16 +00:00
|
|
|
self.xml_start_output()
|
2008-05-09 06:16:03 +00:00
|
|
|
attrs = {"created": strformat.strtime(self.starttime)}
|
2020-04-30 19:11:59 +00:00
|
|
|
self.xml_starttag('linkchecker', attrs)
|
2005-07-15 21:37:16 +00:00
|
|
|
self.flush()
|
|
|
|
|
|
2020-05-16 19:19:42 +00:00
|
|
|
def log_url(self, url_data):
|
2005-07-15 21:37:16 +00:00
|
|
|
"""
|
2005-07-16 07:12:15 +00:00
|
|
|
Log URL data in custom XML format.
|
2005-07-15 21:37:16 +00:00
|
|
|
"""
|
2020-04-30 19:11:59 +00:00
|
|
|
self.xml_starttag('urldata')
|
2005-07-15 21:37:16 +00:00
|
|
|
if self.has_part('url'):
|
2020-05-19 18:56:42 +00:00
|
|
|
self.xml_tag("url", url_data.base_url)
|
2005-07-15 21:37:16 +00:00
|
|
|
if url_data.name and self.has_part('name'):
|
2020-05-19 18:56:42 +00:00
|
|
|
self.xml_tag("name", url_data.name)
|
2005-07-15 21:37:16 +00:00
|
|
|
if url_data.parent_url and self.has_part('parenturl'):
|
2005-07-15 21:51:07 +00:00
|
|
|
attrs = {
|
2020-04-30 19:11:59 +00:00
|
|
|
'line': "%s" % url_data.line,
|
|
|
|
|
'column': "%s" % url_data.column,
|
2005-07-15 21:51:07 +00:00
|
|
|
}
|
2020-05-30 16:01:36 +00:00
|
|
|
self.xml_tag("parent", url_data.parent_url, attrs=attrs)
|
2005-07-15 21:37:16 +00:00
|
|
|
if url_data.base_ref and self.has_part('base'):
|
2020-05-19 18:56:42 +00:00
|
|
|
self.xml_tag("baseref", url_data.base_ref)
|
2005-07-15 21:37:16 +00:00
|
|
|
if self.has_part("realurl"):
|
2020-05-19 18:56:42 +00:00
|
|
|
self.xml_tag("realurl", url_data.url)
|
2005-07-16 07:12:15 +00:00
|
|
|
if self.has_part("extern"):
|
2020-04-30 19:11:59 +00:00
|
|
|
self.xml_tag("extern", "%d" % (1 if url_data.extern else 0))
|
2005-07-15 21:37:16 +00:00
|
|
|
if url_data.dltime >= 0 and self.has_part("dltime"):
|
2020-04-30 19:11:59 +00:00
|
|
|
self.xml_tag("dltime", "%f" % url_data.dltime)
|
2014-02-28 23:12:34 +00:00
|
|
|
if url_data.size >= 0 and self.has_part("dlsize"):
|
2020-04-30 19:11:59 +00:00
|
|
|
self.xml_tag("dlsize", "%d" % url_data.size)
|
2005-07-15 21:37:16 +00:00
|
|
|
if url_data.checktime and self.has_part("checktime"):
|
2020-04-30 19:11:59 +00:00
|
|
|
self.xml_tag("checktime", "%f" % url_data.checktime)
|
2011-04-09 08:51:03 +00:00
|
|
|
if self.has_part("level"):
|
2020-04-30 19:11:59 +00:00
|
|
|
self.xml_tag("level", "%d" % url_data.level)
|
2005-07-15 21:37:16 +00:00
|
|
|
if url_data.info and self.has_part('info'):
|
2020-04-30 19:11:59 +00:00
|
|
|
self.xml_starttag("infos")
|
2009-03-06 20:20:09 +00:00
|
|
|
for info in url_data.info:
|
2020-04-30 19:11:59 +00:00
|
|
|
self.xml_tag("info", info)
|
|
|
|
|
self.xml_endtag("infos")
|
2012-09-18 10:12:00 +00:00
|
|
|
if url_data.modified and self.has_part('modified'):
|
2020-04-30 19:11:59 +00:00
|
|
|
self.xml_tag("modified", self.format_modified(url_data.modified))
|
2005-07-15 21:37:16 +00:00
|
|
|
if url_data.warnings and self.has_part('warning'):
|
2020-04-30 19:11:59 +00:00
|
|
|
self.xml_starttag("warnings")
|
2011-03-15 12:42:21 +00:00
|
|
|
for tag, data in url_data.warnings:
|
2011-03-21 15:07:45 +00:00
|
|
|
attrs = {}
|
|
|
|
|
if tag:
|
|
|
|
|
attrs["tag"] = tag
|
2020-04-30 19:11:59 +00:00
|
|
|
self.xml_tag("warning", data, attrs)
|
|
|
|
|
self.xml_endtag("warnings")
|
2005-07-15 21:37:16 +00:00
|
|
|
if self.has_part("result"):
|
2007-04-03 00:57:55 +00:00
|
|
|
attrs = {}
|
|
|
|
|
if url_data.result:
|
|
|
|
|
attrs["result"] = url_data.result
|
2020-04-30 19:11:59 +00:00
|
|
|
self.xml_tag("valid", "%d" % (1 if url_data.valid else 0), attrs)
|
|
|
|
|
self.xml_endtag('urldata')
|
2005-07-15 21:37:16 +00:00
|
|
|
self.flush()
|
|
|
|
|
|
2020-05-16 19:19:42 +00:00
|
|
|
def end_output(self, **kwargs):
|
2005-07-15 21:37:16 +00:00
|
|
|
"""
|
|
|
|
|
Write XML end tag.
|
|
|
|
|
"""
|
2020-04-30 19:11:59 +00:00
|
|
|
self.xml_endtag("linkchecker")
|
2005-07-15 21:37:16 +00:00
|
|
|
self.xml_end_output()
|
|
|
|
|
self.close_fileoutput()
|