mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-04-27 01:24:42 +00:00
Merge pull request #600 from cjmayo/entrypoint
Generate linkchecker command using an entry point
This commit is contained in:
commit
bfee783500
12 changed files with 915 additions and 853 deletions
|
|
@ -30,8 +30,6 @@ if sys.version_info < (3, 6, 0, 'final', 0):
|
|||
|
||||
import os
|
||||
import re
|
||||
import signal
|
||||
import traceback
|
||||
|
||||
from . import i18n, log
|
||||
from .logconf import (
|
||||
|
|
@ -127,40 +125,3 @@ def init_i18n(loc=None):
|
|||
|
||||
# initialize i18n, puts _() and _n() function into global namespace
|
||||
init_i18n()
|
||||
|
||||
|
||||
def drop_privileges():
|
||||
"""Make sure to drop root privileges on POSIX systems."""
|
||||
if os.name != 'posix':
|
||||
return
|
||||
if os.geteuid() == 0:
|
||||
log.warn(
|
||||
LOG_CHECK,
|
||||
_(
|
||||
"Running as root user; "
|
||||
"dropping privileges by changing user to nobody."
|
||||
),
|
||||
)
|
||||
import pwd
|
||||
|
||||
os.seteuid(pwd.getpwnam('nobody')[3])
|
||||
|
||||
|
||||
if hasattr(signal, "SIGUSR1"):
|
||||
# install SIGUSR1 handler
|
||||
from .decorators import signal_handler
|
||||
|
||||
@signal_handler(signal.SIGUSR1)
|
||||
def print_threadstacks(sig, frame):
|
||||
"""Print stack traces of all running threads."""
|
||||
log.warn(LOG_THREAD, "*** STACKTRACE START ***")
|
||||
for threadId, stack in sys._current_frames().items():
|
||||
log.warn(LOG_THREAD, "# ThreadID: %s" % threadId)
|
||||
for filename, lineno, name, line in traceback.extract_stack(stack):
|
||||
log.warn(
|
||||
LOG_THREAD, 'File: "%s", line %d, in %s' % (filename, lineno, name)
|
||||
)
|
||||
line = line.strip()
|
||||
if line:
|
||||
log.warn(LOG_THREAD, " %s" % line)
|
||||
log.warn(LOG_THREAD, "*** STACKTRACE END ***")
|
||||
|
|
|
|||
3
linkcheck/__main__.py
Normal file
3
linkcheck/__main__.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
from .command.linkchecker import linkchecker
|
||||
|
||||
linkchecker()
|
||||
0
linkcheck/command/__init__.py
Normal file
0
linkcheck/command/__init__.py
Normal file
449
linkcheck/command/arg_parser.py
Normal file
449
linkcheck/command/arg_parser.py
Normal file
|
|
@ -0,0 +1,449 @@
|
|||
# Copyright (C) 2000-2016 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.
|
||||
#
|
||||
# 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.
|
||||
"""
|
||||
Create command line arguments.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
|
||||
from .. import checker, logconf, logger
|
||||
|
||||
from ..cmdline import LCArgumentParser
|
||||
|
||||
# usage texts
|
||||
Notes = _(
|
||||
"""NOTES
|
||||
o URLs on the command line starting with "ftp." are treated like
|
||||
"ftp://ftp.", URLs starting with "www." are treated like "http://www.".
|
||||
You can also give local files as arguments.
|
||||
o If you have your system configured to automatically establish a
|
||||
connection to the internet (e.g. with diald), it will connect when
|
||||
checking links not pointing to your local system.
|
||||
See the --ignore-url option on how to prevent this.
|
||||
o Javascript links are currently ignored.
|
||||
o If your platform does not support threading, LinkChecker disables it
|
||||
automatically.
|
||||
o You can supply multiple user/password pairs in a configuration file.
|
||||
o When checking 'news:' links the given NNTP host doesn't need to be the
|
||||
same as the host of the user browsing your pages.
|
||||
"""
|
||||
)
|
||||
|
||||
ProxySupport = _(
|
||||
"""PROXY SUPPORT
|
||||
To use a proxy on Unix or Windows set $http_proxy or $https_proxy
|
||||
to the proxy URL. The URL should be of the form
|
||||
"http://[<user>:<pass>@]<host>[:<port>]".
|
||||
LinkChecker also detects manual proxy settings of Internet Explorer under
|
||||
Windows systems. On a Mac use the Internet Config to select a proxy.
|
||||
|
||||
LinkChecker honors the $no_proxy environment variable. It can be a list
|
||||
of domain names for which no proxy will be used.
|
||||
|
||||
Setting a HTTP proxy on Unix for example looks like this:
|
||||
|
||||
export http_proxy="http://proxy.example.com:8080"
|
||||
|
||||
Proxy authentication is also supported:
|
||||
|
||||
export http_proxy="http://user1:mypass@proxy.example.org:8081"
|
||||
|
||||
Setting a proxy on the Windows command prompt:
|
||||
|
||||
set http_proxy=http://proxy.example.com:8080
|
||||
|
||||
"""
|
||||
)
|
||||
|
||||
RegularExpressions = _(
|
||||
"""REGULAR EXPRESSIONS
|
||||
Only Python regular expressions are accepted by LinkChecker.
|
||||
See https://docs.python.org/howto/regex.html for an introduction in
|
||||
regular expressions.
|
||||
|
||||
The only addition is that a leading exclamation mark negates
|
||||
the regular expression.
|
||||
"""
|
||||
)
|
||||
|
||||
CookieFormat = _(
|
||||
"""COOKIE FILES
|
||||
A cookie file contains standard RFC 805 header data with the following
|
||||
possible names:
|
||||
Scheme (optional)
|
||||
Sets the scheme the cookies are valid for; default scheme is 'http'.
|
||||
Host (required)
|
||||
Sets the domain the cookies are valid for.
|
||||
Path (optional)
|
||||
Gives the path the cookies are value for; default path is '/'.
|
||||
Set-cookie (optional)
|
||||
Set cookie name/value. Can be given more than once.
|
||||
|
||||
Multiple entries are separated by a blank line.
|
||||
|
||||
The example below will send two cookies to all URLs starting with
|
||||
'http://example.org/hello/' and one to all URLs starting
|
||||
with 'https://example.com/':
|
||||
|
||||
Host: example.org
|
||||
Path: /hello
|
||||
Set-cookie: ID="smee"
|
||||
Set-cookie: spam="egg"
|
||||
|
||||
Scheme: https
|
||||
Host: example.com
|
||||
Set-cookie: baggage="elitist"; comment="hologram"
|
||||
"""
|
||||
)
|
||||
|
||||
Retval = _(
|
||||
r"""RETURN VALUE
|
||||
The return value is non-zero when
|
||||
o invalid links were found or
|
||||
o warnings were found warnings are enabled
|
||||
o a program error occurred
|
||||
"""
|
||||
)
|
||||
|
||||
Examples = _(
|
||||
r"""EXAMPLES
|
||||
The most common use checks the given domain recursively, plus any
|
||||
single URL pointing outside of the domain:
|
||||
linkchecker http://www.example.org/
|
||||
Beware that this checks the whole site which can have several hundred
|
||||
thousands URLs. Use the -r option to restrict the recursion depth.
|
||||
|
||||
Don't connect to mailto: hosts, only check their URL syntax. All other
|
||||
links are checked as usual:
|
||||
linkchecker --ignore-url=^mailto: www.example.org
|
||||
|
||||
Checking local HTML files on Unix:
|
||||
linkchecker ../bla.html subdir/blubber.html
|
||||
|
||||
Checking a local HTML file on Windows:
|
||||
linkchecker c:\temp\test.html
|
||||
|
||||
You can skip the "http://" url part if the domain starts with "www.":
|
||||
linkchecker www.example.de
|
||||
|
||||
You can skip the "ftp://" url part if the domain starts with "ftp.":
|
||||
linkchecker -r0 ftp.example.org
|
||||
"""
|
||||
)
|
||||
|
||||
LoggerTypes = _(
|
||||
r"""OUTPUT TYPES
|
||||
Note that by default only errors and warnings are logged.
|
||||
You should use the --verbose option to see valid URLs,
|
||||
and when outputting a sitemap graph format.
|
||||
|
||||
text Standard text output, logging URLs in keyword: argument fashion.
|
||||
html Log URLs in keyword: argument fashion, formatted as HTML.
|
||||
Additionally has links to the referenced pages. Invalid URLs have
|
||||
HTML and CSS syntax check links appended.
|
||||
csv Log check result in CSV format with one URL per line.
|
||||
gml Log parent-child relations between linked URLs as a GML sitemap
|
||||
graph.
|
||||
dot Log parent-child relations between linked URLs as a DOT sitemap
|
||||
graph.
|
||||
gxml Log check result as a GraphXML sitemap graph.
|
||||
xml Log check result as machine-readable XML.
|
||||
sql Log check result as SQL script with INSERT commands. An example
|
||||
script to create the initial SQL table is included as create.sql.
|
||||
failures
|
||||
Suitable for cron jobs. Logs the check result into a file
|
||||
~/.linkchecker/failures which only contains entries with invalid
|
||||
URLs and the number of times they have failed.
|
||||
none Logs nothing. Suitable for debugging or checking the exit code.
|
||||
"""
|
||||
)
|
||||
|
||||
Warnings = (
|
||||
_(
|
||||
r"""IGNORE WARNINGS
|
||||
The following warnings are recognized in the 'ignorewarnings' config
|
||||
file entry:
|
||||
"""
|
||||
)
|
||||
+ "\n".join(
|
||||
[
|
||||
" o %s - %s" % (tag, desc)
|
||||
for tag, desc in sorted(checker.const.Warnings.items())
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
Epilog = "\n".join(
|
||||
(
|
||||
Examples,
|
||||
LoggerTypes,
|
||||
RegularExpressions,
|
||||
CookieFormat,
|
||||
ProxySupport,
|
||||
Notes,
|
||||
Retval,
|
||||
Warnings,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class ArgParser(LCArgumentParser):
|
||||
"""Create a parser for command line arguments"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
epilog=Epilog, formatter_class=argparse.RawDescriptionHelpFormatter
|
||||
)
|
||||
|
||||
# ================== general options =====================
|
||||
group = self.add_argument_group(_("General options"))
|
||||
group.add_argument(
|
||||
"-f",
|
||||
"--config",
|
||||
dest="configfile",
|
||||
metavar="FILENAME",
|
||||
help=_(
|
||||
"Use FILENAME as configuration file. Per default LinkChecker uses\n"
|
||||
"~/.linkchecker/linkcheckerrc (under Windows\n"
|
||||
"%%HOMEPATH%%\\.linkchecker\\linkcheckerrc)."
|
||||
),
|
||||
)
|
||||
group.add_argument(
|
||||
"-t",
|
||||
"--threads",
|
||||
type=int,
|
||||
metavar="NUMBER",
|
||||
help=_(
|
||||
"Generate no more than the given number of threads. Default number\n"
|
||||
"of threads is 10. To disable threading specify a non-positive number."
|
||||
),
|
||||
)
|
||||
group.add_argument(
|
||||
"-V", "--version", action="store_true", help=_("Print version and exit.")
|
||||
)
|
||||
group.add_argument(
|
||||
"--list-plugins",
|
||||
action="store_true",
|
||||
dest="listplugins",
|
||||
help=_("Print available check plugins and exit."),
|
||||
)
|
||||
group.add_argument(
|
||||
"--stdin",
|
||||
action="store_true",
|
||||
help=_("Read list of white-space separated URLs to check from stdin."),
|
||||
)
|
||||
|
||||
# ================== output options =====================
|
||||
group = self.add_argument_group(_("Output options"))
|
||||
group.add_argument(
|
||||
"-D",
|
||||
"--debug",
|
||||
action="append",
|
||||
metavar="STRING",
|
||||
help=_(
|
||||
"Print debugging output for the given logger.\n"
|
||||
"Available loggers are %(lognamelist)s.\n"
|
||||
"Specifying 'all' is an alias for specifying all available loggers.\n"
|
||||
"The option can be given multiple times to debug with more\n"
|
||||
"than one logger.\n"
|
||||
"\n"
|
||||
"For accurate results, threading will be disabled during debug runs."
|
||||
)
|
||||
% {"lognamelist": logconf.lognamelist},
|
||||
)
|
||||
group.add_argument(
|
||||
"-F",
|
||||
"--file-output",
|
||||
action="append",
|
||||
dest="fileoutput",
|
||||
metavar="TYPE[/ENCODING[/FILENAME]]",
|
||||
help=_(
|
||||
"Output to a file linkchecker-out.TYPE, $HOME/.linkchecker/failures for\n"
|
||||
"'failures' output, or FILENAME if specified.\n"
|
||||
"The ENCODING specifies the output encoding, the default is that of your\n"
|
||||
"locale.\n"
|
||||
"Valid encodings are listed at "
|
||||
"https://docs.python.org/library/codecs.html#standard-encodings.\n"
|
||||
"The FILENAME and ENCODING parts of the 'none' output type will be ignored,\n"
|
||||
"else if the file already exists, it will be overwritten.\n"
|
||||
"You can specify this option more than once. Valid file output types\n"
|
||||
"are %(loggertypes)s. You can specify this option multiple times to output\n"
|
||||
"to more than one file. Default is no file output. Note that you can\n"
|
||||
"suppress all console output with the option '-o none'."
|
||||
)
|
||||
% {"loggertypes": logger.LoggerKeys},
|
||||
)
|
||||
group.add_argument(
|
||||
"--no-status",
|
||||
action="store_false",
|
||||
default=None,
|
||||
dest="status",
|
||||
help=_("Do not print check status messages."),
|
||||
)
|
||||
group.add_argument(
|
||||
"--no-warnings",
|
||||
action="store_false",
|
||||
dest="warnings",
|
||||
help=_("Don't log warnings. Default is to log warnings."),
|
||||
)
|
||||
group.add_argument(
|
||||
"-o",
|
||||
"--output",
|
||||
dest="output",
|
||||
metavar="TYPE[/ENCODING]",
|
||||
help=_(
|
||||
"Specify output as %(loggertypes)s. Default output type is text.\n"
|
||||
"The ENCODING specifies the output encoding, the default is that of your\n"
|
||||
"locale.\n"
|
||||
"Valid encodings are listed at "
|
||||
"https://docs.python.org/library/codecs.html#standard-encodings."
|
||||
)
|
||||
% {"loggertypes": logger.LoggerKeys},
|
||||
)
|
||||
group.add_argument(
|
||||
"--profile", action="store_true", dest="profile", help=argparse.SUPPRESS
|
||||
)
|
||||
group.add_argument(
|
||||
"-q",
|
||||
"--quiet",
|
||||
action="store_true",
|
||||
dest="quiet",
|
||||
help=_(
|
||||
"Quiet operation, an alias for '-o none'.\n"
|
||||
"This is only useful with -F."
|
||||
),
|
||||
)
|
||||
group.add_argument(
|
||||
"--trace", action="store_true", dest="trace", help=argparse.SUPPRESS)
|
||||
group.add_argument(
|
||||
"-v",
|
||||
"--verbose",
|
||||
action="store_true",
|
||||
dest="verbose",
|
||||
help=_("Log all URLs. Default is to log only errors and warnings."),
|
||||
)
|
||||
|
||||
# =================== checking options ====================
|
||||
group = self.add_argument_group(_("Checking options"))
|
||||
group.add_argument(
|
||||
"--cookiefile",
|
||||
dest="cookiefile",
|
||||
metavar="FILENAME",
|
||||
help=_(
|
||||
"Read a file with initial cookie data. The cookie data format is\n"
|
||||
"explained below."
|
||||
),
|
||||
)
|
||||
# const because store_false doesn't detect absent flags
|
||||
group.add_argument(
|
||||
"--no-robots",
|
||||
action="store_const",
|
||||
const=False,
|
||||
dest="norobotstxt",
|
||||
help=_("Disable robots.txt checks"),
|
||||
)
|
||||
group.add_argument(
|
||||
"--check-extern",
|
||||
action="store_true",
|
||||
dest="checkextern",
|
||||
help=_("""Check external URLs."""),
|
||||
)
|
||||
group.add_argument(
|
||||
"--ignore-url",
|
||||
action="append",
|
||||
metavar="REGEX",
|
||||
dest="externstrict",
|
||||
help=_(
|
||||
"Only check syntax of URLs matching the given regular expression.\n"
|
||||
"This option can be given multiple times."
|
||||
),
|
||||
)
|
||||
group.add_argument(
|
||||
"--no-follow-url",
|
||||
action="append",
|
||||
metavar="REGEX",
|
||||
dest="extern",
|
||||
help=_(
|
||||
"Check but do not recurse into URLs matching the given regular\n"
|
||||
"expression. This option can be given multiple times."
|
||||
),
|
||||
)
|
||||
group.add_argument(
|
||||
"-N",
|
||||
"--nntp-server",
|
||||
dest="nntpserver",
|
||||
metavar="STRING",
|
||||
help=_(
|
||||
"Specify an NNTP server for 'news:...' links. Default is the\n"
|
||||
"environment variable NNTP_SERVER. If no host is given,\n"
|
||||
"only the syntax of the link is checked."
|
||||
),
|
||||
)
|
||||
group.add_argument(
|
||||
"-p",
|
||||
"--password",
|
||||
action="store_false",
|
||||
dest="password",
|
||||
default=False,
|
||||
help=_(
|
||||
"Read a password from console and use it for HTTP and FTP authorization.\n"
|
||||
"For FTP the default password is 'anonymous@'. For HTTP there is\n"
|
||||
"no default password. See also -u."
|
||||
),
|
||||
)
|
||||
group.add_argument(
|
||||
"-r",
|
||||
"--recursion-level",
|
||||
type=int,
|
||||
dest="recursionlevel",
|
||||
metavar="NUMBER",
|
||||
help=_(
|
||||
"Check recursively all links up to given depth. A negative depth\n"
|
||||
"will enable infinite recursion. Default depth is infinite."
|
||||
),
|
||||
)
|
||||
group.add_argument(
|
||||
"--timeout",
|
||||
type=int,
|
||||
dest="timeout",
|
||||
metavar="NUMBER",
|
||||
help=_(
|
||||
"Set the timeout for connection attempts in seconds."
|
||||
)
|
||||
)
|
||||
group.add_argument(
|
||||
"-u",
|
||||
"--user",
|
||||
dest="username",
|
||||
metavar="STRING",
|
||||
help=_(
|
||||
"Try the given username for HTTP and FTP authorization.\n"
|
||||
"For FTP the default username is 'anonymous'. For HTTP there is\n"
|
||||
"no default username. See also -p."
|
||||
),
|
||||
)
|
||||
group.add_argument(
|
||||
"--user-agent",
|
||||
dest="useragent",
|
||||
metavar="STRING",
|
||||
help=_(
|
||||
"Specify the User-Agent string to send to the HTTP server, for example\n"
|
||||
'"Mozilla/4.0". The default is "LinkChecker/X.Y" where X.Y is the current\n'
|
||||
"version of LinkChecker."
|
||||
),
|
||||
)
|
||||
|
||||
self.add_argument("url", nargs="*")
|
||||
228
linkcheck/command/linkchecker.py
Normal file
228
linkcheck/command/linkchecker.py
Normal file
|
|
@ -0,0 +1,228 @@
|
|||
# Copyright (C) 2000-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.
|
||||
#
|
||||
# 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.
|
||||
"""
|
||||
Check HTML pages for broken links. This is the commandline
|
||||
client. Run this file with the -h option to see how it's done.
|
||||
"""
|
||||
|
||||
|
||||
import os
|
||||
import pprint
|
||||
import signal
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
from .arg_parser import ArgParser
|
||||
from .setup_config import setup_config
|
||||
|
||||
from .. import configuration
|
||||
from .. import fileutil
|
||||
from .. import log
|
||||
from .. import logconf
|
||||
from .. import LinkCheckerError
|
||||
from ..cmdline import aggregate_url, print_usage
|
||||
from ..director import console, check_urls, get_aggregate
|
||||
from ..logconf import LOG_CHECK, LOG_CMDLINE, LOG_THREAD
|
||||
from ..strformat import stripurl
|
||||
|
||||
|
||||
def drop_privileges():
|
||||
"""Make sure to drop root privileges on POSIX systems."""
|
||||
if os.name != 'posix':
|
||||
return
|
||||
if os.geteuid() == 0:
|
||||
log.warn(
|
||||
LOG_CHECK,
|
||||
_(
|
||||
"Running as root user; "
|
||||
"dropping privileges by changing user to nobody."
|
||||
),
|
||||
)
|
||||
import pwd
|
||||
|
||||
os.seteuid(pwd.getpwnam('nobody')[3])
|
||||
|
||||
|
||||
def linkchecker():
|
||||
if hasattr(signal, "SIGUSR1"):
|
||||
# install SIGUSR1 handler
|
||||
from ..decorators import signal_handler
|
||||
|
||||
@signal_handler(signal.SIGUSR1)
|
||||
def print_threadstacks(sig, frame):
|
||||
"""Print stack traces of all running threads."""
|
||||
log.warn(LOG_THREAD, "*** STACKTRACE START ***")
|
||||
for threadId, stack in sys._current_frames().items():
|
||||
log.warn(LOG_THREAD, "# ThreadID: %s" % threadId)
|
||||
for filename, lineno, name, line in traceback.extract_stack(stack):
|
||||
log.warn(
|
||||
LOG_THREAD,
|
||||
'File: "%s", line %d, in %s' % (filename, lineno, name)
|
||||
)
|
||||
line = line.strip()
|
||||
if line:
|
||||
log.warn(LOG_THREAD, " %s" % line)
|
||||
log.warn(LOG_THREAD, "*** STACKTRACE END ***")
|
||||
|
||||
logconf.init_log_config()
|
||||
|
||||
# optional modules
|
||||
has_argcomplete = fileutil.has_module("argcomplete")
|
||||
has_profile = fileutil.has_module("yappi")
|
||||
has_meliae = fileutil.has_module("meliae")
|
||||
|
||||
# default profiling filename
|
||||
_profile = "linkchecker.prof"
|
||||
|
||||
def read_stdin_urls():
|
||||
"""Read list of URLs, separated by white-space, from stdin."""
|
||||
num = 0
|
||||
while True:
|
||||
lines = sys.stdin.readlines(8 * 1024)
|
||||
if not lines:
|
||||
break
|
||||
for line in lines:
|
||||
for url in line.split():
|
||||
num += 1
|
||||
if num % 10000 == 0:
|
||||
log.info(LOG_CMDLINE, "Read %d URLs from stdin", num)
|
||||
yield url
|
||||
|
||||
# instantiate command line option parser
|
||||
argparser = ArgParser()
|
||||
|
||||
# build a config object for this check session
|
||||
config = configuration.Configuration()
|
||||
config.set_status_logger(console.StatusLogger())
|
||||
|
||||
# ================= auto completion =====================
|
||||
if has_argcomplete:
|
||||
import argcomplete
|
||||
|
||||
argcomplete.autocomplete(argparser)
|
||||
|
||||
# read and parse command line options and arguments
|
||||
options = argparser.parse_args()
|
||||
# initialize logging
|
||||
if options.debug:
|
||||
allowed_debugs = logconf.lognames.keys()
|
||||
for _name in options.debug:
|
||||
if _name not in allowed_debugs:
|
||||
print_usage(_("Invalid debug level %(level)r") % {"level": _name})
|
||||
logconf.set_debug(options.debug)
|
||||
elif options.quiet:
|
||||
logconf.reset_loglevel()
|
||||
log.debug(
|
||||
LOG_CMDLINE,
|
||||
_("Python %(version)s on %(platform)s")
|
||||
% {"version": sys.version, "platform": sys.platform},
|
||||
)
|
||||
# read configuration files
|
||||
try:
|
||||
files = []
|
||||
if options.configfile:
|
||||
path = configuration.normpath(options.configfile)
|
||||
if os.path.isfile(path):
|
||||
files.append(path)
|
||||
else:
|
||||
log.warn(
|
||||
LOG_CMDLINE, _("Unreadable config file: %r"), options.configfile)
|
||||
config.read(files=files)
|
||||
except LinkCheckerError as msg:
|
||||
# config error
|
||||
print_usage(str(msg))
|
||||
drop_privileges()
|
||||
# set up config object using options
|
||||
setup_config(config, options)
|
||||
# now sanitize the configuration
|
||||
config.sanitize()
|
||||
|
||||
log.debug(LOG_CMDLINE, "configuration: %s", pprint.pformat(sorted(config.items())))
|
||||
|
||||
# prepare checking queue
|
||||
aggregate = get_aggregate(config)
|
||||
if options.trace:
|
||||
# enable thread tracing
|
||||
config["trace"] = True
|
||||
# start trace in mainthread
|
||||
from .. import trace
|
||||
|
||||
trace.trace_filter([r"^linkcheck"])
|
||||
trace.trace_on()
|
||||
# add urls to queue
|
||||
if options.stdin:
|
||||
for url in read_stdin_urls():
|
||||
aggregate_url(aggregate, url)
|
||||
elif options.url:
|
||||
for url in options.url:
|
||||
aggregate_url(aggregate, stripurl(url))
|
||||
else:
|
||||
log.warn(LOG_CMDLINE, _("no files or URLs given"))
|
||||
# set up profiling
|
||||
do_profile = False
|
||||
if options.profile:
|
||||
if has_profile:
|
||||
if os.path.exists(_profile):
|
||||
print(
|
||||
_(
|
||||
"Overwrite profiling file %(file)r?\n"
|
||||
"Press Ctrl-C to cancel, RETURN to continue."
|
||||
)
|
||||
% {"file": _profile}
|
||||
)
|
||||
try:
|
||||
input()
|
||||
except KeyboardInterrupt:
|
||||
print("", _("Canceled."), file=sys.stderr, sep="\n")
|
||||
sys.exit(1)
|
||||
do_profile = True
|
||||
else:
|
||||
log.warn(
|
||||
LOG_CMDLINE,
|
||||
_(
|
||||
"The `yappi' Python module is not installed,"
|
||||
" therefore the --profile option is disabled."
|
||||
),
|
||||
)
|
||||
|
||||
# finally, start checking
|
||||
if do_profile:
|
||||
import yappi
|
||||
|
||||
yappi.start()
|
||||
check_urls(aggregate)
|
||||
yappi.stop()
|
||||
yappi.get_func_stats().save(_profile)
|
||||
else:
|
||||
check_urls(aggregate)
|
||||
if config["debugmemory"]:
|
||||
from .. import memoryutil
|
||||
|
||||
if has_meliae:
|
||||
log.info(LOG_CMDLINE, _("Dumping memory statistics..."))
|
||||
filename = memoryutil.write_memory_dump()
|
||||
message = _("The memory dump has been written to `%(filename)s'.")
|
||||
log.info(LOG_CMDLINE, message % dict(filename=filename))
|
||||
else:
|
||||
log.warn(LOG_CMDLINE, memoryutil.MemoryDebugMsg)
|
||||
|
||||
stats = config["logger"].stats
|
||||
# on internal errors, exit with status 2
|
||||
if stats.internal_errors:
|
||||
sys.exit(2)
|
||||
# on errors or printed warnings, exit with status 1
|
||||
if stats.errors or (stats.warnings_printed and config["warnings"]):
|
||||
sys.exit(1)
|
||||
214
linkcheck/command/setup_config.py
Normal file
214
linkcheck/command/setup_config.py
Normal file
|
|
@ -0,0 +1,214 @@
|
|||
# Copyright (C) 2000-2016 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.
|
||||
#
|
||||
# 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.
|
||||
"""
|
||||
Configure linkchecker using command-line options and configuration.
|
||||
"""
|
||||
|
||||
import codecs
|
||||
import getpass
|
||||
|
||||
from .. import fileutil
|
||||
from .. import i18n
|
||||
from .. import logger
|
||||
|
||||
from .. import LOG_CMDLINE
|
||||
from .. import get_link_pat, log
|
||||
|
||||
from ..cmdline import print_version, print_usage, print_plugins
|
||||
from ..director import console
|
||||
|
||||
|
||||
def has_encoding(encoding):
|
||||
"""Detect if Python can encode in a certain encoding."""
|
||||
try:
|
||||
codecs.lookup(encoding)
|
||||
return True
|
||||
except LookupError:
|
||||
return False
|
||||
|
||||
|
||||
def setup_config(config, options):
|
||||
"""Set up linkchecker based on command-line options and configuration"""
|
||||
_username = None
|
||||
_password = None
|
||||
|
||||
# test if running with -O
|
||||
if options.debug and not __debug__:
|
||||
log.warn(LOG_CMDLINE, _("Running with python -O disables debugging."))
|
||||
# apply commandline options and arguments to configuration
|
||||
constructauth = False
|
||||
if options.version:
|
||||
print_version()
|
||||
if not options.warnings:
|
||||
config["warnings"] = options.warnings
|
||||
if options.externstrict:
|
||||
pats = [get_link_pat(arg, strict=True) for arg in options.externstrict]
|
||||
config["externlinks"].extend(pats)
|
||||
if options.extern:
|
||||
pats = [get_link_pat(arg) for arg in options.extern]
|
||||
config["externlinks"].extend(pats)
|
||||
if options.norobotstxt is not None:
|
||||
config["robotstxt"] = options.norobotstxt
|
||||
if options.checkextern:
|
||||
config["checkextern"] = True
|
||||
elif not config["checkextern"]:
|
||||
log.info(
|
||||
LOG_CMDLINE,
|
||||
"Checking intern URLs only; use --check-extern to check extern URLs.",
|
||||
)
|
||||
|
||||
if options.output:
|
||||
if "/" in options.output:
|
||||
logtype, encoding = options.output.split("/", 1)
|
||||
else:
|
||||
logtype, encoding = options.output, i18n.default_encoding
|
||||
logtype = logtype.lower()
|
||||
if logtype == "blacklist":
|
||||
log.warn(
|
||||
LOG_CMDLINE,
|
||||
_("blacklist is deprecated for option %(option)s, "
|
||||
"using failures instead") % {"option": "'-o, --output'"}
|
||||
)
|
||||
logtype = "failures"
|
||||
if logtype not in logger.LoggerNames:
|
||||
print_usage(
|
||||
_("Unknown logger type %(type)r in %(output)r for option %(option)s")
|
||||
% {"type": logtype,
|
||||
"output": options.output,
|
||||
"option": "'-o, --output'"}
|
||||
)
|
||||
if logtype != "none" and not has_encoding(encoding):
|
||||
print_usage(
|
||||
_("Unknown encoding %(encoding)r in %(output)r for option %(option)s")
|
||||
% {
|
||||
"encoding": encoding,
|
||||
"output": options.output,
|
||||
"option": "'-o, --output'",
|
||||
}
|
||||
)
|
||||
config["output"] = logtype
|
||||
config["logger"] = config.logger_new(logtype, encoding=encoding)
|
||||
if options.fileoutput:
|
||||
ns = {"fileoutput": 1}
|
||||
for arg in options.fileoutput:
|
||||
ftype = arg
|
||||
# look for (optional) filename and encoding
|
||||
if "/" in ftype:
|
||||
ftype, suffix = ftype.split("/", 1)
|
||||
if suffix:
|
||||
if has_encoding(suffix):
|
||||
# it was an encoding
|
||||
ns["encoding"] = suffix
|
||||
elif "/" in suffix:
|
||||
# look for (optional) encoding
|
||||
encoding, filename = suffix.split("/", 1)
|
||||
if has_encoding(encoding):
|
||||
ns["encoding"] = encoding
|
||||
ns["filename"] = filename
|
||||
else:
|
||||
ns["filename"] = suffix
|
||||
else:
|
||||
ns["filename"] = suffix
|
||||
if ftype == "blacklist":
|
||||
log.warn(
|
||||
LOG_CMDLINE,
|
||||
_("blacklist logger is deprecated for option %(option)s, "
|
||||
"using failures instead") % {"option": "'-F, --file-output'"}
|
||||
)
|
||||
ftype = "failures"
|
||||
if ftype not in logger.LoggerNames:
|
||||
print_usage(
|
||||
_("Unknown logger type %(type)r in %(output)r"
|
||||
" for option %(option)s")
|
||||
% {
|
||||
"type": ftype,
|
||||
"output": options.fileoutput,
|
||||
"option": "'-F, --file-output'",
|
||||
}
|
||||
)
|
||||
if ftype != "none" and "encoding" in ns \
|
||||
and not has_encoding(ns["encoding"]):
|
||||
print_usage(
|
||||
_("Unknown encoding %(encoding)r in %(output)r"
|
||||
" for option %(option)s")
|
||||
% {
|
||||
"encoding": ns["encoding"],
|
||||
"output": options.fileoutput,
|
||||
"option": "'-F, --file-output'",
|
||||
}
|
||||
)
|
||||
new_logger = config.logger_new(ftype, **ns)
|
||||
config["fileoutput"].append(new_logger)
|
||||
if options.nntpserver:
|
||||
config["nntpserver"] = options.nntpserver
|
||||
if options.username:
|
||||
_username = options.username
|
||||
constructauth = True
|
||||
if options.password:
|
||||
if _username:
|
||||
msg = _("Enter LinkChecker HTTP/FTP password for user %(user)s:") % {
|
||||
"user": _username
|
||||
}
|
||||
else:
|
||||
msg = _("Enter LinkChecker HTTP/FTP password:")
|
||||
_password = getpass.getpass(console.encode(msg))
|
||||
constructauth = True
|
||||
if options.quiet:
|
||||
config["logger"] = config.logger_new("none")
|
||||
if options.recursionlevel is not None:
|
||||
config["recursionlevel"] = options.recursionlevel
|
||||
if options.status is not None:
|
||||
config["status"] = options.status
|
||||
if options.threads is not None:
|
||||
if options.threads < 1:
|
||||
options.threads = 0
|
||||
config["threads"] = options.threads
|
||||
if options.timeout is not None:
|
||||
if options.timeout > 0:
|
||||
config["timeout"] = options.timeout
|
||||
else:
|
||||
print_usage(
|
||||
_("Illegal argument %(arg)r for option %(option)s")
|
||||
% {"arg": options.timeout, "option": "'--timeout'"}
|
||||
)
|
||||
if options.listplugins:
|
||||
print_plugins(config["pluginfolders"])
|
||||
if options.verbose:
|
||||
if options.verbose:
|
||||
config["verbose"] = True
|
||||
config["warnings"] = True
|
||||
if options.cookiefile is not None:
|
||||
config["cookiefile"] = options.cookiefile
|
||||
if constructauth:
|
||||
config.add_auth(pattern=".+", user=_username, password=_password)
|
||||
# read missing passwords
|
||||
for entry in config["authentication"]:
|
||||
if entry["password"] is None:
|
||||
attrs = entry.copy()
|
||||
attrs["strpattern"] = attrs["pattern"].pattern
|
||||
msg = (
|
||||
_("Enter LinkChecker password for user %(user)s at %(strpattern)s:")
|
||||
% attrs
|
||||
)
|
||||
entry["password"] = getpass.getpass(msg)
|
||||
if options.useragent is not None:
|
||||
config["useragent"] = options.useragent
|
||||
if options.cookiefile is not None:
|
||||
if fileutil.is_readable(options.cookiefile):
|
||||
config["cookiefile"] = options.cookiefile
|
||||
else:
|
||||
msg = _("Could not read cookie file %s") % options.cookiefile
|
||||
log.error(LOG_CMDLINE, msg)
|
||||
|
|
@ -19,9 +19,9 @@ A failures logger.
|
|||
|
||||
import os
|
||||
|
||||
from linkcheck.configuration import get_user_data
|
||||
from . import _Logger
|
||||
from .. import log, LOG_CHECK
|
||||
from ..configuration import get_user_data
|
||||
|
||||
|
||||
class FailuresLogger(_Logger):
|
||||
|
|
|
|||
795
linkchecker
795
linkchecker
|
|
@ -1,795 +0,0 @@
|
|||
#!/usr/bin/python3 -u
|
||||
# Copyright (C) 2000-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.
|
||||
#
|
||||
# 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.
|
||||
"""
|
||||
Check HTML pages for broken links. This is the commandline
|
||||
client. Run this file with the -h option to see how it's done.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import codecs
|
||||
import os
|
||||
import pprint
|
||||
import argparse
|
||||
import getpass
|
||||
|
||||
# installs _() and _n() gettext functions into global namespace
|
||||
import linkcheck
|
||||
from linkcheck import log, logconf
|
||||
LOG_CMDLINE = linkcheck.LOG_CMDLINE
|
||||
|
||||
logconf.init_log_config()
|
||||
# override argparse gettext method with the one from linkcheck.init_i18n()
|
||||
# argparse._ = _
|
||||
# now import the rest of the linkchecker gang
|
||||
from linkcheck.cmdline import (
|
||||
print_version,
|
||||
print_usage,
|
||||
aggregate_url,
|
||||
LCArgumentParser,
|
||||
print_plugins,
|
||||
)
|
||||
import linkcheck.checker
|
||||
import linkcheck.configuration
|
||||
import linkcheck.fileutil
|
||||
import linkcheck.logger
|
||||
import linkcheck.ansicolor
|
||||
from linkcheck.director import console, check_urls, get_aggregate
|
||||
from linkcheck.strformat import stripurl
|
||||
|
||||
# optional modules
|
||||
has_argcomplete = linkcheck.fileutil.has_module("argcomplete")
|
||||
has_profile = linkcheck.fileutil.has_module("yappi")
|
||||
has_meliae = linkcheck.fileutil.has_module("meliae")
|
||||
|
||||
# default profiling filename
|
||||
_profile = "linkchecker.prof"
|
||||
_username = None
|
||||
_password = None
|
||||
|
||||
# usage texts
|
||||
Notes = _(
|
||||
"""NOTES
|
||||
o URLs on the command line starting with "ftp." are treated like
|
||||
"ftp://ftp.", URLs starting with "www." are treated like "http://www.".
|
||||
You can also give local files as arguments.
|
||||
o If you have your system configured to automatically establish a
|
||||
connection to the internet (e.g. with diald), it will connect when
|
||||
checking links not pointing to your local system.
|
||||
See the --ignore-url option on how to prevent this.
|
||||
o Javascript links are currently ignored.
|
||||
o If your platform does not support threading, LinkChecker disables it
|
||||
automatically.
|
||||
o You can supply multiple user/password pairs in a configuration file.
|
||||
o When checking 'news:' links the given NNTP host doesn't need to be the
|
||||
same as the host of the user browsing your pages.
|
||||
"""
|
||||
)
|
||||
|
||||
ProxySupport = _(
|
||||
"""PROXY SUPPORT
|
||||
To use a proxy on Unix or Windows set $http_proxy or $https_proxy
|
||||
to the proxy URL. The URL should be of the form
|
||||
"http://[<user>:<pass>@]<host>[:<port>]".
|
||||
LinkChecker also detects manual proxy settings of Internet Explorer under
|
||||
Windows systems, and GNOME or KDE on Linux systems.
|
||||
On a Mac use the Internet Config to select a proxy.
|
||||
|
||||
LinkChecker honors the $no_proxy environment variable. It can be a list
|
||||
of domain names for which no proxy will be used.
|
||||
|
||||
Setting a HTTP proxy on Unix for example looks like this:
|
||||
|
||||
export http_proxy="http://proxy.example.com:8080"
|
||||
|
||||
Proxy authentication is also supported:
|
||||
|
||||
export http_proxy="http://user1:mypass@proxy.example.org:8081"
|
||||
|
||||
Setting a proxy on the Windows command prompt:
|
||||
|
||||
set http_proxy=http://proxy.example.com:8080
|
||||
|
||||
"""
|
||||
)
|
||||
|
||||
RegularExpressions = _(
|
||||
"""REGULAR EXPRESSIONS
|
||||
Only Python regular expressions are accepted by LinkChecker.
|
||||
See https://docs.python.org/howto/regex.html for an introduction in
|
||||
regular expressions.
|
||||
|
||||
The only addition is that a leading exclamation mark negates
|
||||
the regular expression.
|
||||
"""
|
||||
)
|
||||
|
||||
CookieFormat = _(
|
||||
"""COOKIE FILES
|
||||
A cookie file contains standard RFC 805 header data with the following
|
||||
possible names:
|
||||
Scheme (optional)
|
||||
Sets the scheme the cookies are valid for; default scheme is 'http'.
|
||||
Host (required)
|
||||
Sets the domain the cookies are valid for.
|
||||
Path (optional)
|
||||
Gives the path the cookies are value for; default path is '/'.
|
||||
Set-cookie (optional)
|
||||
Set cookie name/value. Can be given more than once.
|
||||
|
||||
Multiple entries are separated by a blank line.
|
||||
|
||||
The example below will send two cookies to all URLs starting with
|
||||
'http://example.org/hello/' and one to all URLs starting
|
||||
with 'https://example.com/':
|
||||
|
||||
Host: example.org
|
||||
Path: /hello
|
||||
Set-cookie: ID="smee"
|
||||
Set-cookie: spam="egg"
|
||||
|
||||
Scheme: https
|
||||
Host: example.com
|
||||
Set-cookie: baggage="elitist"; comment="hologram"
|
||||
"""
|
||||
)
|
||||
|
||||
Retval = _(
|
||||
r"""RETURN VALUE
|
||||
The return value is non-zero when
|
||||
o invalid links were found or
|
||||
o warnings were found warnings are enabled
|
||||
o a program error occurred
|
||||
"""
|
||||
)
|
||||
|
||||
Examples = _(
|
||||
r"""EXAMPLES
|
||||
The most common use checks the given domain recursively, plus any
|
||||
single URL pointing outside of the domain:
|
||||
linkchecker http://www.example.org/
|
||||
Beware that this checks the whole site which can have several hundred
|
||||
thousands URLs. Use the -r option to restrict the recursion depth.
|
||||
|
||||
Don't connect to mailto: hosts, only check their URL syntax. All other
|
||||
links are checked as usual:
|
||||
linkchecker --ignore-url=^mailto: www.example.org
|
||||
|
||||
Checking local HTML files on Unix:
|
||||
linkchecker ../bla.html subdir/blubber.html
|
||||
|
||||
Checking a local HTML file on Windows:
|
||||
linkchecker c:\temp\test.html
|
||||
|
||||
You can skip the "http://" url part if the domain starts with "www.":
|
||||
linkchecker www.example.de
|
||||
|
||||
You can skip the "ftp://" url part if the domain starts with "ftp.":
|
||||
linkchecker -r0 ftp.example.org
|
||||
"""
|
||||
)
|
||||
|
||||
LoggerTypes = _(
|
||||
r"""OUTPUT TYPES
|
||||
Note that by default only errors and warnings are logged.
|
||||
You should use the --verbose option to see valid URLs,
|
||||
and when outputting a sitemap graph format.
|
||||
|
||||
text Standard text output, logging URLs in keyword: argument fashion.
|
||||
html Log URLs in keyword: argument fashion, formatted as HTML.
|
||||
Additionally has links to the referenced pages. Invalid URLs have
|
||||
HTML and CSS syntax check links appended.
|
||||
csv Log check result in CSV format with one URL per line.
|
||||
gml Log parent-child relations between linked URLs as a GML sitemap
|
||||
graph.
|
||||
dot Log parent-child relations between linked URLs as a DOT sitemap
|
||||
graph.
|
||||
gxml Log check result as a GraphXML sitemap graph.
|
||||
xml Log check result as machine-readable XML.
|
||||
sql Log check result as SQL script with INSERT commands. An example
|
||||
script to create the initial SQL table is included as create.sql.
|
||||
failures
|
||||
Suitable for cron jobs. Logs the check result into a file
|
||||
~/.linkchecker/failures which only contains entries with invalid
|
||||
URLs and the number of times they have failed.
|
||||
none Logs nothing. Suitable for debugging or checking the exit code.
|
||||
"""
|
||||
)
|
||||
|
||||
Warnings = (
|
||||
_(
|
||||
r"""IGNORE WARNINGS
|
||||
The following warnings are recognized in the 'ignorewarnings' config
|
||||
file entry:
|
||||
"""
|
||||
)
|
||||
+ "\n".join(
|
||||
[
|
||||
" o %s - %s" % (tag, desc)
|
||||
for tag, desc in sorted(linkcheck.checker.const.Warnings.items())
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
Epilog = "\n".join(
|
||||
(
|
||||
Examples,
|
||||
LoggerTypes,
|
||||
RegularExpressions,
|
||||
CookieFormat,
|
||||
ProxySupport,
|
||||
Notes,
|
||||
Retval,
|
||||
Warnings,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def has_encoding(encoding):
|
||||
"""Detect if Python can encode in a certain encoding."""
|
||||
try:
|
||||
codecs.lookup(encoding)
|
||||
return True
|
||||
except LookupError:
|
||||
return False
|
||||
|
||||
|
||||
# instantiate option parser and configure options
|
||||
argparser = LCArgumentParser(
|
||||
epilog=Epilog, formatter_class=argparse.RawDescriptionHelpFormatter
|
||||
)
|
||||
|
||||
|
||||
# build a config object for this check session
|
||||
config = linkcheck.configuration.Configuration()
|
||||
config.set_status_logger(console.StatusLogger())
|
||||
|
||||
# ================== general options =====================
|
||||
group = argparser.add_argument_group(_("General options"))
|
||||
group.add_argument(
|
||||
"-f",
|
||||
"--config",
|
||||
dest="configfile",
|
||||
metavar="FILENAME",
|
||||
help=_(
|
||||
"Use FILENAME as configuration file. Per default LinkChecker uses\n"
|
||||
"~/.linkchecker/linkcheckerrc (under Windows\n"
|
||||
"%%HOMEPATH%%\\.linkchecker\\linkcheckerrc)."
|
||||
),
|
||||
)
|
||||
group.add_argument(
|
||||
"-t",
|
||||
"--threads",
|
||||
type=int,
|
||||
metavar="NUMBER",
|
||||
help=_(
|
||||
"Generate no more than the given number of threads. Default number\n"
|
||||
"of threads is 10. To disable threading specify a non-positive number."
|
||||
),
|
||||
)
|
||||
group.add_argument(
|
||||
"-V", "--version", action="store_true", help=_("Print version and exit.")
|
||||
)
|
||||
group.add_argument(
|
||||
"--list-plugins",
|
||||
action="store_true",
|
||||
dest="listplugins",
|
||||
help=_("Print available check plugins and exit."),
|
||||
)
|
||||
group.add_argument(
|
||||
"--stdin",
|
||||
action="store_true",
|
||||
help=_("Read list of white-space separated URLs to check from stdin."),
|
||||
)
|
||||
|
||||
# ================== output options =====================
|
||||
group = argparser.add_argument_group(_("Output options"))
|
||||
group.add_argument(
|
||||
"-D",
|
||||
"--debug",
|
||||
action="append",
|
||||
metavar="STRING",
|
||||
help=_(
|
||||
"Print debugging output for the given logger.\n"
|
||||
"Available loggers are %(lognamelist)s.\n"
|
||||
"Specifying 'all' is an alias for specifying all available loggers.\n"
|
||||
"The option can be given multiple times to debug with more\n"
|
||||
"than one logger.\n"
|
||||
"\n"
|
||||
"For accurate results, threading will be disabled during debug runs."
|
||||
)
|
||||
% {"lognamelist": logconf.lognamelist},
|
||||
)
|
||||
group.add_argument(
|
||||
"-F",
|
||||
"--file-output",
|
||||
action="append",
|
||||
dest="fileoutput",
|
||||
metavar="TYPE[/ENCODING[/FILENAME]]",
|
||||
help=_(
|
||||
"Output to a file linkchecker-out.TYPE, $HOME/.linkchecker/failures for\n"
|
||||
"'failures' output, or FILENAME if specified.\n"
|
||||
"The ENCODING specifies the output encoding, the default is that of your\n"
|
||||
"locale.\n"
|
||||
"Valid encodings are listed at "
|
||||
"https://docs.python.org/library/codecs.html#standard-encodings.\n"
|
||||
"The FILENAME and ENCODING parts of the 'none' output type will be ignored,\n"
|
||||
"else if the file already exists, it will be overwritten.\n"
|
||||
"You can specify this option more than once. Valid file output types\n"
|
||||
"are %(loggertypes)s. You can specify this option multiple times to output\n"
|
||||
"to more than one file. Default is no file output. Note that you can\n"
|
||||
"suppress all console output with the option '-o none'."
|
||||
)
|
||||
% {"loggertypes": linkcheck.logger.LoggerKeys},
|
||||
)
|
||||
group.add_argument(
|
||||
"--no-status",
|
||||
action="store_false",
|
||||
default=None,
|
||||
dest="status",
|
||||
help=_("Do not print check status messages."),
|
||||
)
|
||||
group.add_argument(
|
||||
"--no-warnings",
|
||||
action="store_false",
|
||||
dest="warnings",
|
||||
help=_("Don't log warnings. Default is to log warnings."),
|
||||
)
|
||||
group.add_argument(
|
||||
"-o",
|
||||
"--output",
|
||||
dest="output",
|
||||
metavar="TYPE[/ENCODING]",
|
||||
help=_(
|
||||
"Specify output as %(loggertypes)s. Default output type is text.\n"
|
||||
"The ENCODING specifies the output encoding, the default is that of your\n"
|
||||
"locale.\n"
|
||||
"Valid encodings are listed at "
|
||||
"https://docs.python.org/library/codecs.html#standard-encodings."
|
||||
)
|
||||
% {"loggertypes": linkcheck.logger.LoggerKeys},
|
||||
)
|
||||
group.add_argument(
|
||||
"--profile", action="store_true", dest="profile", help=argparse.SUPPRESS
|
||||
)
|
||||
group.add_argument(
|
||||
"-q",
|
||||
"--quiet",
|
||||
action="store_true",
|
||||
dest="quiet",
|
||||
help=_(
|
||||
"Quiet operation, an alias for '-o none'.\n"
|
||||
"This is only useful with -F."
|
||||
),
|
||||
)
|
||||
group.add_argument("--trace", action="store_true", dest="trace", help=argparse.SUPPRESS)
|
||||
group.add_argument(
|
||||
"-v",
|
||||
"--verbose",
|
||||
action="store_true",
|
||||
dest="verbose",
|
||||
help=_("Log all URLs. Default is to log only errors and warnings."),
|
||||
)
|
||||
|
||||
# =================== checking options ====================
|
||||
group = argparser.add_argument_group(_("Checking options"))
|
||||
group.add_argument(
|
||||
"--cookiefile",
|
||||
dest="cookiefile",
|
||||
metavar="FILENAME",
|
||||
help=_(
|
||||
"Read a file with initial cookie data. The cookie data format is\n"
|
||||
"explained below."
|
||||
),
|
||||
)
|
||||
# const because store_false doesn't detect absent flags
|
||||
group.add_argument(
|
||||
"--no-robots",
|
||||
action="store_const",
|
||||
const=False,
|
||||
dest="norobotstxt",
|
||||
help=_("Disable robots.txt checks"),
|
||||
)
|
||||
group.add_argument(
|
||||
"--check-extern",
|
||||
action="store_true",
|
||||
dest="checkextern",
|
||||
help=_("""Check external URLs."""),
|
||||
)
|
||||
group.add_argument(
|
||||
"--ignore-url",
|
||||
action="append",
|
||||
metavar="REGEX",
|
||||
dest="externstrict",
|
||||
help=_(
|
||||
"Only check syntax of URLs matching the given regular expression.\n"
|
||||
"This option can be given multiple times."
|
||||
),
|
||||
)
|
||||
group.add_argument(
|
||||
"--no-follow-url",
|
||||
action="append",
|
||||
metavar="REGEX",
|
||||
dest="extern",
|
||||
help=_(
|
||||
"Check but do not recurse into URLs matching the given regular\n"
|
||||
"expression. This option can be given multiple times."
|
||||
),
|
||||
)
|
||||
group.add_argument(
|
||||
"-N",
|
||||
"--nntp-server",
|
||||
dest="nntpserver",
|
||||
metavar="STRING",
|
||||
help=_(
|
||||
"Specify an NNTP server for 'news:...' links. Default is the\n"
|
||||
"environment variable NNTP_SERVER. If no host is given,\n"
|
||||
"only the syntax of the link is checked."
|
||||
),
|
||||
)
|
||||
group.add_argument(
|
||||
"-p",
|
||||
"--password",
|
||||
action="store_false",
|
||||
dest="password",
|
||||
default=False,
|
||||
help=_(
|
||||
"Read a password from console and use it for HTTP and FTP authorization.\n"
|
||||
"For FTP the default password is 'anonymous@'. For HTTP there is\n"
|
||||
"no default password. See also -u."
|
||||
),
|
||||
)
|
||||
group.add_argument(
|
||||
"-r",
|
||||
"--recursion-level",
|
||||
type=int,
|
||||
dest="recursionlevel",
|
||||
metavar="NUMBER",
|
||||
help=_(
|
||||
"Check recursively all links up to given depth. A negative depth\n"
|
||||
"will enable infinite recursion. Default depth is infinite."
|
||||
),
|
||||
)
|
||||
group.add_argument(
|
||||
"--timeout",
|
||||
type=int,
|
||||
dest="timeout",
|
||||
metavar="NUMBER",
|
||||
help=_(
|
||||
"Set the timeout for connection attempts in seconds. The default\n"
|
||||
"timeout is %d seconds."
|
||||
)
|
||||
% config["timeout"],
|
||||
)
|
||||
group.add_argument(
|
||||
"-u",
|
||||
"--user",
|
||||
dest="username",
|
||||
metavar="STRING",
|
||||
help=_(
|
||||
"Try the given username for HTTP and FTP authorization.\n"
|
||||
"For FTP the default username is 'anonymous'. For HTTP there is\n"
|
||||
"no default username. See also -p."
|
||||
),
|
||||
)
|
||||
group.add_argument(
|
||||
"--user-agent",
|
||||
dest="useragent",
|
||||
metavar="STRING",
|
||||
help=_(
|
||||
"Specify the User-Agent string to send to the HTTP server, for example\n"
|
||||
'"Mozilla/4.0". The default is "LinkChecker/X.Y" where X.Y is the current\n'
|
||||
"version of LinkChecker."
|
||||
),
|
||||
)
|
||||
|
||||
argparser.add_argument("url", nargs="*")
|
||||
# ================= auto completion =====================
|
||||
if has_argcomplete:
|
||||
import argcomplete
|
||||
|
||||
argcomplete.autocomplete(argparser)
|
||||
|
||||
|
||||
def read_stdin_urls():
|
||||
"""Read list of URLs, separated by white-space, from stdin."""
|
||||
num = 0
|
||||
while True:
|
||||
lines = sys.stdin.readlines(8 * 1024)
|
||||
if not lines:
|
||||
break
|
||||
for line in lines:
|
||||
for url in line.split():
|
||||
num += 1
|
||||
if num % 10000 == 0:
|
||||
log.info(LOG_CMDLINE, "Read %d URLs from stdin", num)
|
||||
yield url
|
||||
|
||||
|
||||
# read and parse command line options and arguments
|
||||
options = argparser.parse_args()
|
||||
|
||||
# initialize logging
|
||||
if options.debug:
|
||||
allowed_debugs = logconf.lognames.keys()
|
||||
for _name in options.debug:
|
||||
if _name not in allowed_debugs:
|
||||
print_usage(_("Invalid debug level %(level)r") % {"level": _name})
|
||||
logconf.set_debug(options.debug)
|
||||
elif options.quiet:
|
||||
logconf.reset_loglevel()
|
||||
log.debug(
|
||||
LOG_CMDLINE,
|
||||
_("Python %(version)s on %(platform)s")
|
||||
% {"version": sys.version, "platform": sys.platform},
|
||||
)
|
||||
# read configuration files
|
||||
try:
|
||||
files = []
|
||||
if options.configfile:
|
||||
path = linkcheck.configuration.normpath(options.configfile)
|
||||
if os.path.isfile(path):
|
||||
files.append(path)
|
||||
else:
|
||||
log.warn(LOG_CMDLINE, _("Unreadable config file: %r"), options.configfile)
|
||||
config.read(files=files)
|
||||
except linkcheck.LinkCheckerError as msg:
|
||||
# config error
|
||||
print_usage(str(msg))
|
||||
linkcheck.drop_privileges()
|
||||
# test if running with -O
|
||||
if options.debug and not __debug__:
|
||||
log.warn(LOG_CMDLINE, _("Running with python -O disables debugging."))
|
||||
# apply commandline options and arguments to configuration
|
||||
constructauth = False
|
||||
do_profile = False
|
||||
if options.version:
|
||||
print_version()
|
||||
if not options.warnings:
|
||||
config["warnings"] = options.warnings
|
||||
if options.externstrict:
|
||||
pats = [linkcheck.get_link_pat(arg, strict=True) for arg in options.externstrict]
|
||||
config["externlinks"].extend(pats)
|
||||
if options.extern:
|
||||
pats = [linkcheck.get_link_pat(arg) for arg in options.extern]
|
||||
config["externlinks"].extend(pats)
|
||||
if options.norobotstxt is not None:
|
||||
config["robotstxt"] = options.norobotstxt
|
||||
if options.checkextern:
|
||||
config["checkextern"] = True
|
||||
elif not config["checkextern"]:
|
||||
log.info(
|
||||
LOG_CMDLINE,
|
||||
"Checking intern URLs only; use --check-extern to check extern URLs.",
|
||||
)
|
||||
|
||||
if options.output:
|
||||
if "/" in options.output:
|
||||
logtype, encoding = options.output.split("/", 1)
|
||||
else:
|
||||
logtype, encoding = options.output, linkcheck.i18n.default_encoding
|
||||
logtype = logtype.lower()
|
||||
if logtype == "blacklist":
|
||||
log.warn(
|
||||
LOG_CMDLINE,
|
||||
_("blacklist is deprecated for option %(option)s, "
|
||||
"using failures instead") % {"option": "'-o, --output'"}
|
||||
)
|
||||
logtype = "failures"
|
||||
if logtype not in linkcheck.logger.LoggerNames:
|
||||
print_usage(
|
||||
_("Unknown logger type %(type)r in %(output)r for option %(option)s")
|
||||
% {"type": logtype, "output": options.output, "option": "'-o, --output'"}
|
||||
)
|
||||
if logtype != "none" and not has_encoding(encoding):
|
||||
print_usage(
|
||||
_("Unknown encoding %(encoding)r in %(output)r for option %(option)s")
|
||||
% {
|
||||
"encoding": encoding,
|
||||
"output": options.output,
|
||||
"option": "'-o, --output'",
|
||||
}
|
||||
)
|
||||
config["output"] = logtype
|
||||
config["logger"] = config.logger_new(logtype, encoding=encoding)
|
||||
if options.fileoutput:
|
||||
ns = {"fileoutput": 1}
|
||||
for arg in options.fileoutput:
|
||||
ftype = arg
|
||||
# look for (optional) filename and encoding
|
||||
if "/" in ftype:
|
||||
ftype, suffix = ftype.split("/", 1)
|
||||
if suffix:
|
||||
if has_encoding(suffix):
|
||||
# it was an encoding
|
||||
ns["encoding"] = suffix
|
||||
elif "/" in suffix:
|
||||
# look for (optional) encoding
|
||||
encoding, filename = suffix.split("/", 1)
|
||||
if has_encoding(encoding):
|
||||
ns["encoding"] = encoding
|
||||
ns["filename"] = filename
|
||||
else:
|
||||
ns["filename"] = suffix
|
||||
else:
|
||||
ns["filename"] = suffix
|
||||
if ftype == "blacklist":
|
||||
log.warn(
|
||||
LOG_CMDLINE,
|
||||
_("blacklist logger is deprecated for option %(option)s, "
|
||||
"using failures instead") % {"option": "'-F, --file-output'"}
|
||||
)
|
||||
ftype = "failures"
|
||||
if ftype not in linkcheck.logger.LoggerNames:
|
||||
print_usage(
|
||||
_("Unknown logger type %(type)r in %(output)r for option %(option)s")
|
||||
% {
|
||||
"type": ftype,
|
||||
"output": options.fileoutput,
|
||||
"option": "'-F, --file-output'",
|
||||
}
|
||||
)
|
||||
if ftype != "none" and "encoding" in ns and not has_encoding(ns["encoding"]):
|
||||
print_usage(
|
||||
_("Unknown encoding %(encoding)r in %(output)r for option %(option)s")
|
||||
% {
|
||||
"encoding": ns["encoding"],
|
||||
"output": options.fileoutput,
|
||||
"option": "'-F, --file-output'",
|
||||
}
|
||||
)
|
||||
logger = config.logger_new(ftype, **ns)
|
||||
config["fileoutput"].append(logger)
|
||||
if options.nntpserver:
|
||||
config["nntpserver"] = options.nntpserver
|
||||
if options.username:
|
||||
_username = options.username
|
||||
constructauth = True
|
||||
if options.password:
|
||||
if _username:
|
||||
msg = _("Enter LinkChecker HTTP/FTP password for user %(user)s:") % {
|
||||
"user": _username
|
||||
}
|
||||
else:
|
||||
msg = _("Enter LinkChecker HTTP/FTP password:")
|
||||
_password = getpass.getpass(console.encode(msg))
|
||||
constructauth = True
|
||||
if options.profile:
|
||||
do_profile = options.profile
|
||||
if options.quiet:
|
||||
config["logger"] = config.logger_new("none")
|
||||
if options.recursionlevel is not None:
|
||||
config["recursionlevel"] = options.recursionlevel
|
||||
if options.status is not None:
|
||||
config["status"] = options.status
|
||||
if options.threads is not None:
|
||||
if options.threads < 1:
|
||||
options.threads = 0
|
||||
config["threads"] = options.threads
|
||||
if options.timeout is not None:
|
||||
if options.timeout > 0:
|
||||
config["timeout"] = options.timeout
|
||||
else:
|
||||
print_usage(
|
||||
_("Illegal argument %(arg)r for option %(option)s")
|
||||
% {"arg": options.timeout, "option": "'--timeout'"}
|
||||
)
|
||||
if options.listplugins:
|
||||
print_plugins(config["pluginfolders"])
|
||||
if options.verbose:
|
||||
if options.verbose:
|
||||
config["verbose"] = True
|
||||
config["warnings"] = True
|
||||
if options.cookiefile is not None:
|
||||
config["cookiefile"] = options.cookiefile
|
||||
if constructauth:
|
||||
config.add_auth(pattern=".+", user=_username, password=_password)
|
||||
# read missing passwords
|
||||
for entry in config["authentication"]:
|
||||
if entry["password"] is None:
|
||||
attrs = entry.copy()
|
||||
attrs["strpattern"] = attrs["pattern"].pattern
|
||||
msg = (
|
||||
_("Enter LinkChecker password for user %(user)s at %(strpattern)s:")
|
||||
% attrs
|
||||
)
|
||||
entry["password"] = getpass.getpass(msg)
|
||||
if options.useragent is not None:
|
||||
config["useragent"] = options.useragent
|
||||
if options.cookiefile is not None:
|
||||
if linkcheck.fileutil.is_readable(options.cookiefile):
|
||||
config["cookiefile"] = options.cookiefile
|
||||
else:
|
||||
msg = _("Could not read cookie file %s") % options.cookiefile
|
||||
log.error(LOG_CMDLINE, msg)
|
||||
# now sanitize the configuration
|
||||
config.sanitize()
|
||||
|
||||
log.debug(LOG_CMDLINE, "configuration: %s", pprint.pformat(sorted(config.items())))
|
||||
|
||||
# prepare checking queue
|
||||
aggregate = get_aggregate(config)
|
||||
if options.trace:
|
||||
# enable thread tracing
|
||||
config["trace"] = True
|
||||
# start trace in mainthread
|
||||
import linkcheck.trace
|
||||
|
||||
linkcheck.trace.trace_filter([r"^linkcheck"])
|
||||
linkcheck.trace.trace_on()
|
||||
# add urls to queue
|
||||
if options.stdin:
|
||||
for url in read_stdin_urls():
|
||||
aggregate_url(aggregate, url)
|
||||
elif options.url:
|
||||
for url in options.url:
|
||||
aggregate_url(aggregate, stripurl(url))
|
||||
else:
|
||||
log.warn(LOG_CMDLINE, _("no files or URLs given"))
|
||||
# set up profiling
|
||||
if do_profile:
|
||||
if has_profile:
|
||||
if os.path.exists(_profile):
|
||||
print(
|
||||
_(
|
||||
"Overwrite profiling file %(file)r?\n"
|
||||
"Press Ctrl-C to cancel, RETURN to continue."
|
||||
)
|
||||
% {"file": _profile}
|
||||
)
|
||||
try:
|
||||
input()
|
||||
except KeyboardInterrupt:
|
||||
print("", _("Canceled."), file=sys.stderr, sep="\n")
|
||||
sys.exit(1)
|
||||
else:
|
||||
log.warn(
|
||||
LOG_CMDLINE,
|
||||
_(
|
||||
"The `yappi' Python module is not installed,"
|
||||
" therefore the --profile option is disabled."
|
||||
),
|
||||
)
|
||||
do_profile = False
|
||||
|
||||
# finally, start checking
|
||||
if do_profile:
|
||||
import yappi
|
||||
|
||||
yappi.start()
|
||||
check_urls(aggregate)
|
||||
yappi.stop()
|
||||
yappi.get_func_stats().save(_profile)
|
||||
else:
|
||||
check_urls(aggregate)
|
||||
if config["debugmemory"]:
|
||||
import linkcheck.memoryutil
|
||||
|
||||
if has_meliae:
|
||||
log.info(LOG_CMDLINE, _("Dumping memory statistics..."))
|
||||
filename = linkcheck.memoryutil.write_memory_dump()
|
||||
message = _("The memory dump has been written to `%(filename)s'.")
|
||||
log.info(LOG_CMDLINE, message % dict(filename=filename))
|
||||
else:
|
||||
log.warn(LOG_CMDLINE, linkcheck.memoryutil.MemoryDebugMsg)
|
||||
|
||||
stats = config["logger"].stats
|
||||
# on internal errors, exit with status 2
|
||||
if stats.internal_errors:
|
||||
sys.exit(2)
|
||||
# on errors or printed warnings, exit with status 1
|
||||
if stats.errors or (stats.warnings_printed and config["warnings"]):
|
||||
sys.exit(1)
|
||||
|
|
@ -22,7 +22,6 @@ ignore =
|
|||
[flake8]
|
||||
filename =
|
||||
*.py
|
||||
./linkchecker
|
||||
extend-exclude =
|
||||
build/
|
||||
_LinkChecker_configdata.py
|
||||
|
|
@ -37,7 +36,6 @@ per-file-ignores =
|
|||
# In several files imports intentionally cause:
|
||||
# E402: module level import not at top of file
|
||||
# F401: module imported but unused
|
||||
linkchecker: E402
|
||||
setup.py: E402
|
||||
doc/src/conf.py: E402,F821
|
||||
linkcheck/__init__.py: E402,F401
|
||||
|
|
@ -48,6 +46,7 @@ per-file-ignores =
|
|||
# E501: line too long
|
||||
linkcheck/ftpparse.py: E501
|
||||
linkcheck/checker/unknownurl.py: E501
|
||||
linkcheck/command/arg_parser.py: E501
|
||||
scripts/update_iana_uri_schemes.py: E501
|
||||
tests/test_ftpparse.py: E501
|
||||
# F821 undefined name
|
||||
|
|
|
|||
14
setup.py
14
setup.py
|
|
@ -217,11 +217,6 @@ class MyInstallData(install_data):
|
|||
class MyDistribution(Distribution):
|
||||
"""Custom distribution class generating config file."""
|
||||
|
||||
def __init__(self, attrs):
|
||||
"""Set console and windows scripts."""
|
||||
super().__init__(attrs)
|
||||
self.console = ["linkchecker"]
|
||||
|
||||
def run_commands(self):
|
||||
"""Generate config file and run commands."""
|
||||
cwd = os.getcwd()
|
||||
|
|
@ -306,8 +301,6 @@ class MyClean(clean):
|
|||
|
||||
|
||||
# scripts
|
||||
scripts = ["linkchecker"]
|
||||
|
||||
myname = "LinkChecker Authors"
|
||||
myemail = ""
|
||||
|
||||
|
|
@ -370,7 +363,11 @@ setup(
|
|||
"clean": MyClean,
|
||||
},
|
||||
packages=find_packages(include=["linkcheck", "linkcheck.*"]),
|
||||
scripts=scripts,
|
||||
entry_points={
|
||||
"console_scripts": [
|
||||
"linkchecker = linkcheck.command.linkchecker:linkchecker"
|
||||
]
|
||||
},
|
||||
data_files=data_files,
|
||||
classifiers=[
|
||||
"Topic :: Internet :: WWW/HTTP :: Site Management :: Link Checking",
|
||||
|
|
@ -388,6 +385,7 @@ setup(
|
|||
python_requires=">= 3.6",
|
||||
setup_requires=["setuptools_scm"],
|
||||
install_requires=[
|
||||
"importlib_metadata;python_version<'3.8'",
|
||||
"requests >= 2.4",
|
||||
"dnspython >= 2.0",
|
||||
"beautifulsoup4 >= 4.8.1",
|
||||
|
|
|
|||
|
|
@ -24,10 +24,6 @@ from functools import lru_cache, wraps
|
|||
from linkcheck import LinkCheckerInterrupt
|
||||
|
||||
|
||||
basedir = os.path.dirname(__file__)
|
||||
linkchecker_cmd = os.path.join(os.path.dirname(basedir), "linkchecker")
|
||||
|
||||
|
||||
def run(cmd, verbosity=0, **kwargs):
|
||||
"""Run command without error checking.
|
||||
@return: command return code"""
|
||||
|
|
|
|||
|
|
@ -14,12 +14,12 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
import unittest
|
||||
import sys
|
||||
from . import linkchecker_cmd, run_checked
|
||||
from . import run_checked
|
||||
|
||||
|
||||
def run_with_options(options, cmd=linkchecker_cmd):
|
||||
def run_with_options(options):
|
||||
"""Run a command with given options."""
|
||||
run_checked([sys.executable, cmd] + options)
|
||||
run_checked([sys.executable, "-m", "linkcheck"] + options)
|
||||
|
||||
|
||||
class TestLinkchecker(unittest.TestCase):
|
||||
|
|
@ -27,7 +27,16 @@ class TestLinkchecker(unittest.TestCase):
|
|||
|
||||
def test_linkchecker(self):
|
||||
# test some single options
|
||||
for option in ("-V", "--version", "-h", "--help", "--list-plugins", "-Dall"):
|
||||
for option in (
|
||||
"-V",
|
||||
"--version",
|
||||
"-h",
|
||||
"--help",
|
||||
"--list-plugins",
|
||||
"-Dall",
|
||||
"-ocsv",
|
||||
"-Fhtml",
|
||||
):
|
||||
run_with_options([option])
|
||||
# unknown option
|
||||
self.assertRaises(OSError, run_with_options, ["--imadoofus"])
|
||||
|
|
|
|||
Loading…
Reference in a new issue