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: 37656 Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bwY3j-0000m5-KH; Tue, 18 Oct 2016 17:20:15 +0000 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.84_2/mailfrontend-8) with esmtp id 1bwY3h-0006p0-kW; Tue, 18 Oct 2016 19:20:15 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1034092AbcJRRT5 (ORCPT + 1 other); 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 X-Spam-Flag: NO X-Spam-Score: -2.608 X-Spam-Level: X-Spam-Status: No, score=-2.608 tagged_above=-999 tests=[ALL_TRUSTED=-1, AWL=0.292, BAYES_00=-1.9] autolearn=unavailable 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-PMX-Version: 6.0.0.2142326, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2016.10.18.171217 X-PMX-Spam: Gauge=IIIIIIII, Probability=8%, Report=' MULTIPLE_RCPTS 0.1, HTML_00_01 0.05, HTML_00_10 0.05, BODYTEXTP_SIZE_3000_LESS 0, BODY_SIZE_2000_2999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, IN_REP_TO 0, LEGITIMATE_NEGATE 0, LEGITIMATE_SIGNS 0, MSG_THREAD 0, MULTIPLE_REAL_RCPTS 0, NO_URI_HTTPS 0, REFERENCES 0, SINGLE_URI_IN_BODY 0, URI_ENDS_IN_HTML 0, __ANY_URI 0, __CC_NAME 0, __CC_NAME_DIFF_FROM_ACC 0, __CC_REAL_NAMES 0, __CP_URI_IN_BODY 0, __FRAUD_MONEY_CURRENCY 0, __FRAUD_MONEY_CURRENCY_DOLLAR 0, __FROM_DOMAIN_IN_ANY_CC2 0, __FROM_DOMAIN_IN_RCPT 0, __HAS_CC_HDR 0, __HAS_FROM 0, __HAS_MSGID 0, __HAS_X_MAILER 0, __HAS_X_MAILING_LIST 0, __IN_REP_TO 0, __MIME_TEXT_ONLY 0, __MIME_TEXT_P 0, __MIME_TEXT_P1 0, __MULTIPLE_RCPTS_CC_X2 0, __REFERENCES 0, __SANE_MSGID 0, __SINGLE_URI_TEXT 0, __SUBJ_ALPHA_END 0, __TO_MALFORMED_2 0, __TO_NAME 0, __TO_NAME_DIFF_FROM_ACC 0, __TO_REAL_NAMES 0, __URI_IN_BODY 0, __URI_NO_WWW 0, __URI_NS , __URI_WITH_PATH 0' 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