sphinxext: Print output to logs, not to file

The functionality previously added here was broken as it did not include
a required newline. Rather than fix it, modify the whole thing to print
to logs instead of a temporary file. This should achieve the same effect
with less side effects.

Change-Id: I74d11a54d57d30aab7f97f4fcce9fee0b7d87cbc
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Closes-Bug: #1782316
This commit is contained in:
Stephen Finucane 2018-07-18 09:50:49 +01:00
parent fbb9611454
commit a31cce7fde
1 changed files with 12 additions and 24 deletions

View File

@ -10,10 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import print_function
import tempfile
from docutils import nodes
from docutils.parsers import rst
from docutils.parsers.rst import directives
@ -308,27 +304,19 @@ class ShowOptionsDirective(rst.Directive):
result = ViewList()
source_name = self.state.document.current_source
with tempfile.NamedTemporaryFile(suffix='.rst', delete=False) as tmp:
# NOTE(stephenfin): We dump the output to a tempfile to assist
# people in debugging their broken config options. It would be good
# to conditionalize this but that would require access to error
# state from the directive, which we don't have, and would
# necessitate holding the whole file, which could be rather large,
# in memory while we wait on the decision.
LOG.info('dumping output to %r', tmp.name)
offset = 0
for count, line in enumerate(_format_option_help(
namespaces, split_namespaces)):
# FIXME(stephenfin): Some lines emitted are actually multiple
# lines. This throws off our counter, which is rather annoying.
# We handle this here but we should really handle it higher up.
parts = line.split('\n')
if len(parts) > 1:
offset += len(parts) - 1
offset = 0
for count, line in enumerate(_format_option_help(
namespaces, split_namespaces)):
# FIXME(stephenfin): Some lines emitted are actually multiple
# lines. This throws off our counter, which is rather annoying.
# We handle this here but we should really handle it higher up.
parts = line.split('\n')
if len(parts) > 1:
offset += len(parts) - 1
for part in parts:
result.append(part, source_name, count + offset)
tmp.write(line.encode('utf-8') + b'\n')
for part in parts:
result.append(part, source_name, count + offset)
LOG.debug(' '.join(['%5d' % (count + offset), part]))
node = nodes.section()
node.document = self.state.document