2001-03-15 01:19:35 +00:00
|
|
|
"""main function module for link checking"""
|
2001-05-23 21:20:44 +00:00
|
|
|
# Copyright (C) 2000,2001 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
|
|
|
|
2002-05-04 13:27:02 +00:00
|
|
|
class error (Exception):
|
2000-06-10 18:06:43 +00:00
|
|
|
pass
|
2000-02-26 10:24:46 +00:00
|
|
|
|
2002-06-07 20:47:35 +00:00
|
|
|
import re
|
|
|
|
|
def getLinkPat (arg, strict=0):
|
|
|
|
|
"""get a link pattern matcher for intern/extern links"""
|
|
|
|
|
if arg[0:1] == '!':
|
|
|
|
|
pattern = arg[1:]
|
|
|
|
|
negate = 1
|
|
|
|
|
else:
|
|
|
|
|
pattern = arg
|
|
|
|
|
negate = 0
|
|
|
|
|
return {
|
|
|
|
|
"pattern": re.compile(pattern),
|
|
|
|
|
"negate": negate,
|
|
|
|
|
"strict": strict,
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-30 22:34:43 +00:00
|
|
|
# i18n suppport
|
2002-06-26 20:46:42 +00:00
|
|
|
import sys, os, _linkchecker_configdata
|
2002-02-24 12:29:35 +00:00
|
|
|
def init_gettext ():
|
|
|
|
|
global _
|
|
|
|
|
try:
|
|
|
|
|
import gettext
|
|
|
|
|
domain = 'linkcheck'
|
|
|
|
|
localedir = os.path.join(_linkchecker_configdata.install_data,
|
|
|
|
|
'share/locale')
|
|
|
|
|
_ = gettext.translation(domain, localedir).gettext
|
|
|
|
|
except (IOError, ImportError):
|
|
|
|
|
_ = lambda s: s
|
|
|
|
|
init_gettext()
|
2000-05-28 23:49:42 +00:00
|
|
|
|
2002-06-26 20:46:42 +00:00
|
|
|
import Config
|
2001-05-24 15:48:07 +00:00
|
|
|
from debuglevels import *
|
|
|
|
|
debug = Config.debug
|
2000-02-26 10:24:46 +00:00
|
|
|
|
2002-01-29 21:20:37 +00:00
|
|
|
|
|
|
|
|
# main check function
|
2002-05-04 13:27:02 +00:00
|
|
|
def checkUrls (config):
|
2000-04-10 16:58:05 +00:00
|
|
|
""" checkUrls gets a complete configuration object as parameter where all
|
|
|
|
|
runtime-dependent options are stored.
|
|
|
|
|
If you call checkUrls more than once, you can specify different
|
|
|
|
|
configurations.
|
|
|
|
|
|
|
|
|
|
In the config object there are functions to get a new URL (getUrl) and
|
|
|
|
|
to check it (checkUrl).
|
|
|
|
|
"""
|
2000-02-26 10:24:46 +00:00
|
|
|
config.log_init()
|
|
|
|
|
try:
|
|
|
|
|
while not config.finished():
|
|
|
|
|
if config.hasMoreUrls():
|
|
|
|
|
config.checkUrl(config.getUrl())
|
2001-01-06 18:00:43 +00:00
|
|
|
config.log_endOfOutput()
|
2000-02-26 10:24:46 +00:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
|
config.finish()
|
|
|
|
|
config.log_endOfOutput()
|
2002-02-14 15:33:53 +00:00
|
|
|
config.warn(_("keyboard interrupt"))
|