2003-07-04 14:24:44 +00:00
|
|
|
# -*- coding: iso-8859-1 -*-
|
2005-01-11 02:22:43 +00:00
|
|
|
# Copyright (C) 2000-2005 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.
|
2005-01-19 15:08:02 +00:00
|
|
|
"""
|
|
|
|
|
Main function module for link checking.
|
|
|
|
|
"""
|
2000-04-10 16:58:05 +00:00
|
|
|
|
2005-01-18 17:03:17 +00:00
|
|
|
# imports and checks
|
|
|
|
|
import sys
|
|
|
|
|
if not hasattr(sys, 'version_info') or \
|
2005-01-24 19:27:00 +00:00
|
|
|
sys.version_info < (2, 4, 0, 'final', 0):
|
|
|
|
|
raise SystemExit, "This program requires Python 2.4 or later."
|
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"
|
2005-07-11 15:37:15 +00:00
|
|
|
LOG_DNS = "linkcheck.dns"
|
2004-08-31 19:15:33 +00:00
|
|
|
LOG_CACHE = "linkcheck.cache"
|
2004-07-07 18:04:40 +00:00
|
|
|
LOG_GUI = "linkcheck.gui"
|
2005-03-09 20:09:21 +00:00
|
|
|
LOG_THREAD = "linkcheck.thread"
|
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,
|
2005-07-11 15:37:15 +00:00
|
|
|
"dns": LOG_DNS,
|
2005-03-09 20:09:21 +00:00
|
|
|
"thread": LOG_THREAD,
|
2004-08-16 19:20:53 +00:00
|
|
|
"all": LOG,
|
|
|
|
|
}
|
|
|
|
|
lognamelist = ", ".join(["%r"%name for name in lognames.keys()])
|
2004-07-07 18:04:40 +00:00
|
|
|
|
2005-02-01 02:05:34 +00:00
|
|
|
import linkcheck.log
|
|
|
|
|
|
2004-01-07 21:27:49 +00:00
|
|
|
|
2003-01-22 19:50:13 +00:00
|
|
|
class LinkCheckerError (Exception):
|
2005-01-18 01:00:45 +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):
|
2005-01-18 01:00:45 +00:00
|
|
|
"""
|
|
|
|
|
Get a link pattern matcher for intern/extern links.
|
2005-01-19 00:40:06 +00:00
|
|
|
Returns a compiled pattern and a negate and strict option.
|
|
|
|
|
|
|
|
|
|
@param arg: pattern from config
|
2005-01-19 15:56:48 +00:00
|
|
|
@type arg: string
|
2005-01-19 00:40:06 +00:00
|
|
|
@param strict: if pattern is to be handled strict
|
2005-01-19 15:56:48 +00:00
|
|
|
@type strict: bool
|
2005-01-19 00:40:06 +00:00
|
|
|
@return: dictionary with keys 'pattern', 'negate' and 'strict'
|
2005-01-19 15:56:48 +00:00
|
|
|
@rtype: dict
|
2005-01-18 01:00:45 +00:00
|
|
|
"""
|
2004-08-16 19:20:53 +00:00
|
|
|
linkcheck.log.debug(LOG_CHECK, "Link pattern %r", arg)
|
2005-05-06 13:06:27 +00:00
|
|
|
if arg.startswith('!'):
|
2002-06-07 20:47:35 +00:00
|
|
|
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
|
2005-01-27 17:11:03 +00:00
|
|
|
import linkcheck.logger.dot
|
2004-08-16 19:20:53 +00:00
|
|
|
import linkcheck.logger.sql
|
|
|
|
|
import linkcheck.logger.csvlog
|
|
|
|
|
import linkcheck.logger.blacklist
|
2005-07-15 21:33:15 +00:00
|
|
|
import linkcheck.logger.gxml
|
|
|
|
|
import linkcheck.logger.customxml
|
2004-08-16 19:20:53 +00:00
|
|
|
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,
|
2005-01-27 17:11:03 +00:00
|
|
|
"dot": linkcheck.logger.dot.DOTLogger,
|
2004-08-16 19:20:53 +00:00
|
|
|
"sql": linkcheck.logger.sql.SQLLogger,
|
|
|
|
|
"csv": linkcheck.logger.csvlog.CSVLogger,
|
|
|
|
|
"blacklist": linkcheck.logger.blacklist.BlacklistLogger,
|
2005-07-15 21:33:15 +00:00
|
|
|
"gxml": linkcheck.logger.gxml.GraphXMLLogger,
|
|
|
|
|
"xml": linkcheck.logger.customxml.CustomXMLLogger,
|
2004-08-16 19:20:53 +00:00
|
|
|
"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 ():
|
2005-01-18 01:00:45 +00:00
|
|
|
"""
|
|
|
|
|
Initialize i18n with the configured locale dir. The environment
|
|
|
|
|
variable LOCPATH can also specify a locale dir.
|
|
|
|
|
|
|
|
|
|
@return: C{None}
|
|
|
|
|
"""
|
2004-09-05 20:48:52 +00:00
|
|
|
locdir = os.environ.get('LOCPATH')
|
|
|
|
|
if locdir is None:
|
|
|
|
|
locdir = os.path.join(configdata.install_data, 'share', 'locale')
|
|
|
|
|
linkcheck.i18n.init(configdata.name, locdir)
|
2005-02-01 02:05:34 +00:00
|
|
|
# install translated log level names
|
|
|
|
|
import logging
|
|
|
|
|
logging.addLevelName(logging.CRITICAL, _('CRITICAL'))
|
|
|
|
|
logging.addLevelName(logging.ERROR, _('ERROR'))
|
|
|
|
|
logging.addLevelName(logging.WARN, _('WARN'))
|
|
|
|
|
logging.addLevelName(logging.WARNING, _('WARNING'))
|
|
|
|
|
logging.addLevelName(logging.INFO, _('INFO'))
|
|
|
|
|
logging.addLevelName(logging.DEBUG, _('DEBUG'))
|
|
|
|
|
logging.addLevelName(logging.NOTSET, _('NOTSET'))
|
2004-09-05 20:48:52 +00:00
|
|
|
|
2005-10-11 12:52:36 +00:00
|
|
|
# initialize i18n, puts _() function into global namespace
|
|
|
|
|
init_i18n()
|