From patchwork Thu Mar 2 21:22:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 9601909 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 2026C60453 for ; Fri, 3 Mar 2017 01:52:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1146428402 for ; Fri, 3 Mar 2017 01:52:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 05FEC28595; Fri, 3 Mar 2017 01:52:23 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4A95F28402 for ; Fri, 3 Mar 2017 01:52:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 72F5C6EC8A; Fri, 3 Mar 2017 01:51:43 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from osg.samsung.com (ec2-52-27-115-49.us-west-2.compute.amazonaws.com [52.27.115.49]) by gabe.freedesktop.org (Postfix) with ESMTP id E719D6EC59 for ; Thu, 2 Mar 2017 21:22:45 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by osg.samsung.com (Postfix) with ESMTP id A2882A0DE2; Thu, 2 Mar 2017 21:23:07 +0000 (UTC) X-Virus-Scanned: amavisd-new at osg.samsung.com Received: from osg.samsung.com ([127.0.0.1]) by localhost (s-opensource.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3zdpLYbXj6OQ; Thu, 2 Mar 2017 21:23:06 +0000 (UTC) Received: from vento.lan (177.41.125.80.dynamic.adsl.gvt.net.br [177.41.125.80]) by osg.samsung.com (Postfix) with ESMTPSA id 28D09A0C73; Thu, 2 Mar 2017 21:23:03 +0000 (UTC) Date: Thu, 2 Mar 2017 18:22:38 -0300 From: Mauro Carvalho Chehab To: Markus Heiser Subject: Re: [PATCH] docs-rst: automatically convert Graphviz and SVG images Message-ID: <20170302182238.25dac63a@vento.lan> In-Reply-To: <5313AA1D-E8E1-4EB3-AE0A-42E411EC67CB@darmarit.de> References: <20170302151638.1882-2-daniel.vetter@ffwll.ch> <20170302154002.4552-1-daniel.vetter@ffwll.ch> <20170302150603.6c97765f@vento.lan> <20170302163422.2fbd1385@vento.lan> <5313AA1D-E8E1-4EB3-AE0A-42E411EC67CB@darmarit.de> Organization: Samsung X-Mailer: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-redhat-linux-gnu) MIME-Version: 1.0 X-Mailman-Approved-At: Fri, 03 Mar 2017 01:51:38 +0000 Cc: Jonathan Corbet , Daniel Vetter , DRI Development , Linux Doc Mailing List , Laurent Pinchart , Daniel Vetter X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Em Thu, 2 Mar 2017 22:16:49 +0100 Markus Heiser escreveu: > > Am 02.03.2017 um 20:34 schrieb Mauro Carvalho Chehab : > > > > Em Thu, 2 Mar 2017 20:06:39 +0100 > > Markus Heiser escreveu: > > > >> Hi Mauro, > >> > >>> Tested here with the enclosed patch. > >> > >> great, big step forward making /media/Makefile smaller ... thanks a lot!!!! > >> > >>> It crashed: > >>> Exception occurred: > >>> File "/devel/v4l/patchwork/Documentation/sphinx/kfigure.py", line 222, in dot2format > >>> sys.stderr.write(err) > >>> TypeError: write() argument must be str, not bytes > >>> The full traceback has been saved in /tmp/sphinx-err-_1vahbmg.log, if you want to report the issue to the developers. > >>> Please also report this if it was a user error, so that a better error message can be provided next time. > >>> A bug report can be filed in the tracker at . Thanks! > >>> Documentation/Makefile.sphinx:69: recipe for target 'htmldocs' failed > >>> make[1]: *** [htmldocs] Error 1 > >>> Makefile:1450: recipe for target 'htmldocs' failed > >>> make: *** [htmldocs] Error 2 > >>> > >>> Weird enough, it produced a Documentation/output/media/uapi/v4l/pipeline.svg file. > >> > >> I guess that the dot command writes something to stderr. This is captured > >> by the extension and printed to stderr ... > >> > >> +def dot2format(dot_fname, out_fname): > >> ... > >> + exit_code = 42 > >> + with open(out_fname, "w") as out: > >> + p = subprocess.Popen( > >> + cmd, stdout = out, stderr = subprocess.PIPE ) > >> + nil, err = p.communicate() > >> + > >> + sys.stderr.write(err) > >> + > >> + exit_code = p.returncode > >> + out.flush() > >> + return bool(exit_code == 0) > >> > >>> File "/devel/v4l/patchwork/Documentation/sphinx/kfigure.py", line 222, in dot2format > >>> sys.stderr.write(err) > >>> TypeError: write() argument must be str, not bytes > >> > >> Do we need this stderr output? For a first test, uncomment the > >> "sys.stderr.write(err)“ in line 222. Or, if we really need the > >> stderr, try: > >> > >> - sys.stderr.write(err) > >> + sys.stderr.write(str(err)) > > > > Yes, this fixed. I actually did: > > > > - sys.stderr.write(err) > > + sys.stderr.write(str(err)) > > + sys.stderr.write("\n") > > > > It is now printing: > > b'' > > > > I added the \n print to avoid it to be mixed with the "writing output" > > prints. > > No idea how to make sense from it - but clearly, the error report > > logic require some care ;-) > > > Aargh, I’am a idiot ... I guess 'sys.stderr.write(err)‘ is a artefact > of my development, simply drop it and the subprocess.PIPE of stderr > also. > > + with open(out_fname, "w") as out: > + p = subprocess.Popen( > - cmd, stdout = out, stderr = subprocess.PIPE ) > + cmd, stdout = out) > + nil, err = p.communicate() > - > - sys.stderr.write(err) > - > + exit_code = p.returncode > + out.flush() > + return bool(exit_code == 0) > > I can’t test it ATM, but without redirect stderr, the stderr > of the parent process is inherited. > > https://docs.python.org/3.6/library/subprocess.html#popen-constructor > > The Popen.communicate() always returns a tuple (stdout_data, stderr_data) > with above the tuple is always (None, None). > > https://docs.python.org/3.6/library/subprocess.html#subprocess.Popen.communicate > > """to get anything other than None in the result tuple, > you need to give stdout=PIPE and/or stderr=PIPE too.""" > > Sorry, that I made all this mistakes, but „here“ I have only mail > and web, no dev-env and I miss my emacs ;) > > If the suggestion above does not work, I have to investigate > more time next weekend. Hmm... I would be more verbose on output the error code, printing from where the error came, e. g. printing a message like: Error #0 when calling dot for '/devel/v4l/patchwork/Documentation/media/uapi/v4l/pipeline.dot': None As on this patch: diff --git a/Documentation/sphinx/kfigure.py b/Documentation/sphinx/kfigure.py index 32eab0f4cfba..a366a89f4f98 100644 --- a/Documentation/sphinx/kfigure.py +++ b/Documentation/sphinx/kfigure.py @@ -217,11 +217,13 @@ def dot2format(dot_fname, out_fname): with open(out_fname, "w") as out: p = subprocess.Popen( cmd, stdout = out, stderr = subprocess.PIPE ) - nil, err = p.communicate() - - sys.stderr.write(err) + err = p.communicate() exit_code = p.returncode + + if exit_code != 0: + sys.stderr.write("Error #%d when calling dot for '%s': %s\n" % (exit_code, dot_fname, repr(err[0]))) + out.flush() return bool(exit_code == 0) @@ -239,11 +241,13 @@ def svg2pdf(svg_fname, pdf_fname): cmd = [convert_cmd, svg_fname, pdf_fname] p = subprocess.Popen( cmd, stdout = out, stderr = subprocess.PIPE ) - nil, err = p.communicate() - - sys.stderr.write(err) + err = p.communicate() exit_code = p.returncode + + if exit_code != 0: + sys.stderr.write("Error #%d when calling convert for '%s': %s\n" % (exit_code, dot_fname, repr(err[0]))) + return bool(exit_code == 0)