Georg Brandl avatar Georg Brandl committed 39d715b

In linkcheck builder, return status code 1 on error, and emit warnings if -q
is given.

Comments (0)

Files changed (3)

sphinx/application.py

 
 import sys
 import posixpath
+from cStringIO import StringIO
 
 from docutils import nodes
 from docutils.parsers.rst import directives, roles
         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)
 

sphinx/cmdline.py

 import getopt
 import traceback
 from os import path
-from cStringIO import StringIO
 
 from docutils.utils import SystemMessage
 
         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
         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

sphinx/linkcheck.py

                 self.good.add(uri)
             elif r == 2:
                 self.info(' - ' + red('broken: ') + s)
+                self.write_entry('broken', docname, lineno, uri + ': ' + s)
                 self.broken[uri] = (r, s)
-                self.write_entry('broken', docname, lineno, uri + ': ' + s)
+                if self.app.quiet:
+                    self.warn('%s:%s: broken link: %s' % (docname, lineno, uri))
             else:
                 self.info(' - ' + purple('redirected') + ' to ' + s)
+                self.write_entry('redirected', docname, lineno, uri + ' to ' + s)
                 self.redirected[uri] = (r, s)
-                self.write_entry('redirected', docname, lineno, uri + ' to ' + 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')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.