From patchwork Tue Oct 18 17:19:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Heiser X-Patchwork-Id: 9382741 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1937760839 for ; Tue, 18 Oct 2016 17:20:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 262EB296C2 for ; Tue, 18 Oct 2016 17:20:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1AD65296C7; Tue, 18 Oct 2016 17:20:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 630B0296C2 for ; Tue, 18 Oct 2016 17:20:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1034092AbcJRRT5 (ORCPT ); Tue, 18 Oct 2016 13:19:57 -0400 Received: from smtp3-1.goneo.de ([85.220.129.38]:45954 "EHLO smtp3-1.goneo.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1034085AbcJRRTw (ORCPT ); Tue, 18 Oct 2016 13:19:52 -0400 Received: from localhost (localhost [127.0.0.1]) by smtp3.goneo.de (Postfix) with ESMTP id D8D1123F2AD; Tue, 18 Oct 2016 19:19:48 +0200 (CEST) X-Virus-Scanned: by goneo Received: from smtp3.goneo.de ([127.0.0.1]) by localhost (smtp3.goneo.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QX3V9RajMCLy; Tue, 18 Oct 2016 19:19:38 +0200 (CEST) Received: from ubu1604.fritz.box (dyndsl-091-248-141-026.ewe-ip-backbone.de [91.248.141.26]) by smtp3.goneo.de (Postfix) with ESMTPSA id 7D4D823FB03; Tue, 18 Oct 2016 19:19:38 +0200 (CEST) From: Markus Heiser To: Mauro Carvalho Chehab Cc: Markus Heiser , Linux Media Mailing List , linux-doc@vger.kernel.org Subject: [PATCH] doc-rst: reST-directive kernel-cmd parse with tabs Date: Tue, 18 Oct 2016 19:19:28 +0200 Message-Id: <1476811168-2651-2-git-send-email-markus.heiser@darmarit.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1476811168-2651-1-git-send-email-markus.heiser@darmarit.de> References: <1476811168-2651-1-git-send-email-markus.heiser@darmarit.de> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add a 'tab-width' option to the kernel-cmd, and convert whitespace (tabs) well. The default 'tab-width' is 8. This is also a bugfix, since without this patch, tabs in command's output are not handled. Signed-off-by: Markus Heiser --- Documentation/sphinx/kernel_cmd.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Documentation/sphinx/kernel_cmd.py b/Documentation/sphinx/kernel_cmd.py index 43f02b0..bbe8fa9 100644 --- a/Documentation/sphinx/kernel_cmd.py +++ b/Documentation/sphinx/kernel_cmd.py @@ -27,6 +27,10 @@ u""" PATH=$(srctree)/scripts:$(srctree)/Documentation/sphinx:... + ``tab-width`` + + Tabulator width of output, default is 8. + ``depends `` If the stdout of the command line depends on files, you can add them as @@ -70,7 +74,7 @@ from sphinx.ext.autodoc import AutodocReporter from docutils import nodes from docutils.parsers.rst import Directive, directives -from docutils.statemachine import ViewList +from docutils import statemachine from docutils.utils.error_reporting import ErrorString @@ -105,7 +109,8 @@ class KernelCmd(Directive): option_spec = { "depends" : directives.unchanged, "code-block": directives.unchanged, - "debug" : directives.flag + "debug" : directives.flag, + "tab-width" : directives.nonnegative_int } def warn(self, message, **replace): @@ -148,6 +153,7 @@ class KernelCmd(Directive): shell_env["srctree"] = srctree lines = self.runCmd(cmd, shell=True, cwd=cwd, env=shell_env) + nodeList = self.nestedParse(lines, fname) return nodeList @@ -176,7 +182,7 @@ class KernelCmd(Directive): return unicode(out) def nestedParse(self, lines, fname): - content = ViewList() + content = statemachine.ViewList() node = nodes.section() if "code-block" in self.options: @@ -191,7 +197,10 @@ class KernelCmd(Directive): code_block += "\n " + l lines = code_block + "\n\n" - for c, l in enumerate(lines.split("\n")): + tab_width = self.options.get('tab-width', 8) + lines = statemachine.string2lines(lines, tab_width, convert_whitespace=True) + + for c, l in enumerate(lines): content.append(l, fname, c) buf = self.state.memo.title_styles, self.state.memo.section_level, self.state.memo.reporter