mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
In linkcheck builder, return status code 1 on error, and emit warnings if -q
is given.
This commit is contained in:
parent
4aaac2ca70
commit
1353cc42dd
@ -14,6 +14,7 @@
|
||||
|
||||
import sys
|
||||
import posixpath
|
||||
from cStringIO import StringIO
|
||||
|
||||
from docutils import nodes
|
||||
from docutils.parsers.rst import directives, roles
|
||||
@ -83,12 +84,23 @@ class Sphinx(object):
|
||||
self.outdir = outdir
|
||||
self.doctreedir = doctreedir
|
||||
|
||||
self._status = status
|
||||
self._warning = warning
|
||||
if status is None:
|
||||
self._status = StringIO()
|
||||
self.quiet = True
|
||||
else:
|
||||
self._status = status
|
||||
self.quiet = False
|
||||
if warning is None:
|
||||
self._warning = StringIO()
|
||||
else:
|
||||
self._warning = warning
|
||||
self._warncount = 0
|
||||
|
||||
self._events = events.copy()
|
||||
|
||||
# status code for command-line application
|
||||
self.statuscode = 0
|
||||
|
||||
# read config
|
||||
self.config = Config(confdir, CONFIG_FILENAME, confoverrides)
|
||||
|
||||
|
@ -14,7 +14,6 @@ import sys
|
||||
import getopt
|
||||
import traceback
|
||||
from os import path
|
||||
from cStringIO import StringIO
|
||||
|
||||
from docutils.utils import SystemMessage
|
||||
|
||||
@ -134,10 +133,10 @@ def main(argv):
|
||||
elif opt == '-E':
|
||||
freshenv = True
|
||||
elif opt == '-q':
|
||||
status = StringIO()
|
||||
status = None
|
||||
elif opt == '-Q':
|
||||
status = StringIO()
|
||||
warning = StringIO()
|
||||
status = None
|
||||
warning = None
|
||||
elif opt == '-P':
|
||||
use_pdb = True
|
||||
confoverrides['html_context'] = htmlcontext
|
||||
@ -146,6 +145,7 @@ def main(argv):
|
||||
app = Sphinx(srcdir, confdir, outdir, doctreedir, buildername,
|
||||
confoverrides, status, warning, freshenv)
|
||||
app.build(all_files, filenames)
|
||||
return app.statuscode
|
||||
except KeyboardInterrupt:
|
||||
if use_pdb:
|
||||
import pdb
|
||||
|
@ -84,20 +84,25 @@ class CheckExternalLinksBuilder(Builder):
|
||||
self.good.add(uri)
|
||||
elif r == 2:
|
||||
self.info(' - ' + red('broken: ') + s)
|
||||
self.broken[uri] = (r, s)
|
||||
self.write_entry('broken', docname, lineno, uri + ': ' + s)
|
||||
self.broken[uri] = (r, s)
|
||||
if self.app.quiet:
|
||||
self.warn('%s:%s: broken link: %s' % (docname, lineno, uri))
|
||||
else:
|
||||
self.info(' - ' + purple('redirected') + ' to ' + s)
|
||||
self.redirected[uri] = (r, s)
|
||||
self.write_entry('redirected', docname, lineno, uri + ' to ' + s)
|
||||
|
||||
self.redirected[uri] = (r, s)
|
||||
elif len(uri) == 0 or uri[0:7] == 'mailto:' or uri[0:4] == 'ftp:':
|
||||
return
|
||||
else:
|
||||
self.info(uri + ' - ' + red('malformed!'))
|
||||
self.warn(uri + ' - ' + red('malformed!'))
|
||||
self.write_entry('malformed', docname, lineno, uri)
|
||||
if self.app.quiet:
|
||||
self.warn('%s:%s: malformed link: %s' % (docname, lineno, uri))
|
||||
self.app.statuscode = 1
|
||||
|
||||
return
|
||||
if self.broken:
|
||||
self.app.statuscode = 1
|
||||
|
||||
def write_entry(self, what, docname, line, uri):
|
||||
output = open(path.join(self.outdir, 'output.txt'), 'a')
|
||||
|
Loading…
Reference in New Issue
Block a user