All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab@s-opensource.com>
To: Markus Heiser <markus.heiser@darmarit.de>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>,
	Linux Doc Mailing List <linux-doc@vger.kernel.org>,
	DRI Development <dri-devel@lists.freedesktop.org>,
	Jonathan Corbet <corbet@lwn.net>,
	Jani Nikula <jani.nikula@linux.intel.com>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Daniel Vetter <daniel.vetter@intel.com>
Subject: Re: [PATCH] docs-rst: automatically convert Graphviz and SVG images
Date: Thu, 2 Mar 2017 16:56:42 -0300	[thread overview]
Message-ID: <20170302165642.7d25d51b@vento.lan> (raw)
In-Reply-To: <20170302163422.2fbd1385@vento.lan>

Em Thu, 2 Mar 2017 16:34:22 -0300
Mauro Carvalho Chehab <mchehab@s-opensource.com> escreveu:

> Em Thu, 2 Mar 2017 20:06:39 +0100
> Markus Heiser <markus.heiser@darmarit.de> 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 <https://github.com/sphinx-doc/sphinx/issues>. 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 ;-)

I'm not a Python programmer, but googling about the right syntax for
p.communicate(), I suspect that the fix should be similar to this code
snippet below.

Without the if, this code:

	sys.stderr.write("Error:" + repr(p.communicate()[0]) + "\n")

prints:
	Error:None

So, I guess the code below is ok.

Markus, please check. 

Daniel, Feel free to merge it with the original patch if OK.

diff --git a/Documentation/sphinx/kfigure.py b/Documentation/sphinx/kfigure.py
index 32eab0f4cfba..b154c5f17752 100644
--- a/Documentation/sphinx/kfigure.py
+++ b/Documentation/sphinx/kfigure.py
@@ -217,11 +217,12 @@ 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)
 
         exit_code = p.returncode
+
+        if exit_code == 0:
+            sys.stderr.write("Error:" + repr(p.communicate()[0]) + "\n")
+
         out.flush()
     return bool(exit_code == 0)
 
@@ -239,11 +240,12 @@ 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)
 
     exit_code = p.returncode
+
+    if exit_code == 0:
+        sys.stderr.write("Error:" + repr(p.communicate()[0]) + "\n")
+
     return bool(exit_code == 0)
 
 


  reply	other threads:[~2017-03-02 19:56 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-02 15:16 [PATCH 1/6] doc: Explain light-handed markup preference a bit better Daniel Vetter
2017-03-02 15:16 ` [PATCH 2/6] docs-rst: automatically convert Graphviz and SVG images Daniel Vetter
2017-03-02 15:20   ` Laurent Pinchart
2017-03-02 15:40   ` [PATCH] " Daniel Vetter
2017-03-02 18:06     ` Mauro Carvalho Chehab
2017-03-02 19:06       ` Markus Heiser
2017-03-02 19:34         ` Mauro Carvalho Chehab
2017-03-02 19:56           ` Mauro Carvalho Chehab [this message]
2017-03-02 21:16           ` Markus Heiser
2017-03-02 21:22             ` Mauro Carvalho Chehab
2017-03-02 19:52         ` Daniel Vetter
2017-03-02 20:04           ` Mauro Carvalho Chehab
2017-03-02 20:54             ` Mauro Carvalho Chehab
2017-03-02 21:29     ` Mauro Carvalho Chehab
2017-03-02 21:36       ` Mauro Carvalho Chehab
2017-03-02 21:47         ` Mauro Carvalho Chehab
2017-03-02 21:54           ` Markus Heiser
2017-03-03  8:54         ` Daniel Vetter
2017-03-02 22:15   ` [PATCH 2/6] " Markus Heiser
2017-03-02 23:19     ` Mauro Carvalho Chehab
2017-03-02 15:16 ` [PATCH 3/6] drm/doc: Add KMS overview graphs Daniel Vetter
2017-03-02 15:16 ` [PATCH 4/6] drm/doc: Consistent kerneldoc include order Daniel Vetter
2017-03-02 15:16 ` [PATCH 5/6] drm/doc: diagram for mode objects and properties Daniel Vetter
2017-03-02 15:16 ` [PATCH 6/6] drm/doc: atomic overview, with graph Daniel Vetter
2017-03-02 15:24   ` Gabriel Krisman Bertazi
2017-03-14 14:14     ` Daniel Vetter
2017-03-07 16:40 ` [PATCH 1/6] doc: Explain light-handed markup preference a bit better Daniel Vetter
2017-03-07 16:55   ` Jonathan Corbet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170302165642.7d25d51b@vento.lan \
    --to=mchehab@s-opensource.com \
    --cc=corbet@lwn.net \
    --cc=daniel.vetter@ffwll.ch \
    --cc=daniel.vetter@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=markus.heiser@darmarit.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.