2003-07-04 14:24:44 +00:00
|
|
|
# -*- coding: iso-8859-1 -*-
|
2001-03-15 01:19:35 +00:00
|
|
|
"""main function module for link checking"""
|
2004-01-03 14:59:33 +00:00
|
|
|
# Copyright (C) 2000-2004 Bastian Kleineidam
|
2001-03-15 01:19:35 +00:00
|
|
|
#
|
2001-05-23 21:20:44 +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.
|
2001-03-15 01:19:35 +00:00
|
|
|
#
|
2001-05-23 21:20:44 +00:00
|
|
|
# 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.
|
2001-03-15 01:19:35 +00:00
|
|
|
#
|
2001-05-23 21:20:44 +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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
2000-04-10 16:58:05 +00:00
|
|
|
|
2004-09-05 20:48:52 +00:00
|
|
|
import os
|
2004-07-19 08:58:59 +00:00
|
|
|
import re
|
2004-07-07 18:04:40 +00:00
|
|
|
|
2004-09-05 20:48:52 +00:00
|
|
|
import linkcheck.i18n
|
|
|
|
|
import _linkchecker_configdata as configdata
|
2004-08-16 19:20:53 +00:00
|
|
|
|
2004-08-31 19:15:33 +00:00
|
|
|
# application log areas
|
2004-08-16 19:20:53 +00:00
|
|
|
LOG = "linkcheck"
|
2004-07-07 18:04:40 +00:00
|
|
|
LOG_CMDLINE = "linkcheck.cmdline"
|
|
|
|
|
LOG_CHECK = "linkcheck.check"
|
2004-08-31 19:15:33 +00:00
|
|
|
LOG_CACHE = "linkcheck.cache"
|
2004-07-07 18:04:40 +00:00
|
|
|
LOG_GUI = "linkcheck.gui"
|
2004-08-16 19:20:53 +00:00
|
|
|
lognames = {
|
|
|
|
|
"cmdline": LOG_CMDLINE,
|
|
|
|
|
"checking": LOG_CHECK,
|
2004-08-31 19:15:33 +00:00
|
|
|
"cache": LOG_CACHE,
|
2004-08-16 19:20:53 +00:00
|
|
|
"gui": LOG_GUI,
|
|
|
|
|
"all": LOG,
|
|
|
|
|
}
|
|
|
|
|
lognamelist = ", ".join(["%r"%name for name in lognames.keys()])
|
2004-07-07 18:04:40 +00:00
|
|
|
|
2004-01-07 21:27:49 +00:00
|
|
|
|
2003-01-22 19:50:13 +00:00
|
|
|
class LinkCheckerError (Exception):
|
2004-08-16 19:20:53 +00:00
|
|
|
"""exception to be raised on linkchecker-specific check errors"""
|
2000-06-10 18:06:43 +00:00
|
|
|
pass
|
2000-02-26 10:24:46 +00:00
|
|
|
|
2004-01-07 21:27:49 +00:00
|
|
|
|
2004-08-16 19:20:53 +00:00
|
|
|
def get_link_pat (arg, strict=False):
|
2002-06-07 20:47:35 +00:00
|
|
|
"""get a link pattern matcher for intern/extern links"""
|
2004-08-16 19:20:53 +00:00
|
|
|
linkcheck.log.debug(LOG_CHECK, "Link pattern %r", arg)
|
2002-06-07 20:47:35 +00:00
|
|
|
if arg[0:1] == '!':
|
|
|
|
|
pattern = arg[1:]
|
2003-08-11 11:49:30 +00:00
|
|
|
negate = True
|
2002-06-07 20:47:35 +00:00
|
|
|
else:
|
|
|
|
|
pattern = arg
|
2003-08-11 11:49:30 +00:00
|
|
|
negate = False
|
2002-06-07 20:47:35 +00:00
|
|
|
return {
|
|
|
|
|
"pattern": re.compile(pattern),
|
|
|
|
|
"negate": negate,
|
|
|
|
|
"strict": strict,
|
|
|
|
|
}
|
|
|
|
|
|
2004-07-07 18:04:40 +00:00
|
|
|
|
2004-08-31 19:15:33 +00:00
|
|
|
# note: don't confuse URL loggers with application logs above
|
2004-08-25 20:10:01 +00:00
|
|
|
import linkcheck.logger.text
|
2004-08-16 19:20:53 +00:00
|
|
|
import linkcheck.logger.html
|
|
|
|
|
import linkcheck.logger.gml
|
|
|
|
|
import linkcheck.logger.sql
|
|
|
|
|
import linkcheck.logger.csvlog
|
|
|
|
|
import linkcheck.logger.blacklist
|
|
|
|
|
import linkcheck.logger.xmllog
|
|
|
|
|
import linkcheck.logger.none
|
2004-07-19 08:58:59 +00:00
|
|
|
|
|
|
|
|
|
2004-08-31 19:15:33 +00:00
|
|
|
# default link logger classes
|
2004-07-19 08:58:59 +00:00
|
|
|
Loggers = {
|
2004-08-25 20:10:01 +00:00
|
|
|
"text": linkcheck.logger.text.TextLogger,
|
2004-08-16 19:20:53 +00:00
|
|
|
"html": linkcheck.logger.html.HtmlLogger,
|
|
|
|
|
"gml": linkcheck.logger.gml.GMLLogger,
|
|
|
|
|
"sql": linkcheck.logger.sql.SQLLogger,
|
|
|
|
|
"csv": linkcheck.logger.csvlog.CSVLogger,
|
|
|
|
|
"blacklist": linkcheck.logger.blacklist.BlacklistLogger,
|
|
|
|
|
"xml": linkcheck.logger.xmllog.XMLLogger,
|
|
|
|
|
"none": linkcheck.logger.none.NoneLogger,
|
2004-07-19 08:58:59 +00:00
|
|
|
}
|
|
|
|
|
# for easy printing: a comma separated logger list
|
2004-08-16 19:20:53 +00:00
|
|
|
LoggerKeys = ", ".join(["%r"%name for name in Loggers.keys()])
|
2004-08-19 21:36:17 +00:00
|
|
|
|
2004-09-05 20:48:52 +00:00
|
|
|
|
|
|
|
|
def init_i18n ():
|
|
|
|
|
locdir = os.environ.get('LOCPATH')
|
|
|
|
|
if locdir is None:
|
|
|
|
|
locdir = os.path.join(configdata.install_data, 'share', 'locale')
|
|
|
|
|
linkcheck.i18n.init(configdata.name, locdir)
|
|
|
|
|
|