Lines Matching +full:stdout +full:- +full:path
1 # -*- coding: utf-8; mode: python -*-
14 handling from the author's POV. Directives like ``kernel-figure`` implement
15 methods *to* always get the best output-format even if some tools are not
19 * ``.. kernel-image``: for image handling / a ``.. image::`` replacement
21 * ``.. kernel-figure``: for figure handling / a ``.. figure::`` replacement
23 * ``.. kernel-render``: for render markup / a concept to embed *render*
26 - ``DOT``: render embedded Graphviz's **DOC**
27 - ``SVG``: render embedded Scalable Vector Graphics (**SVG**)
28 - ... *developable*
33 available, the DOT language is inserted as literal-block.
34 For conversion to PDF, ``rsvg-convert(1)`` of librsvg
39 - ``convert(1)``: ImageMagick (https://www.imagemagick.org)
40 - ``inkscape(1)``: Inkscape (https://inkscape.org/)
46 * generate SVG (html-builder) and PDF (latex-builder) from DOT files.
47 DOT: see https://www.graphviz.org/content/dot-language
52 from os import path
69 # -------------
72 """Searches the ``cmd`` in the ``PATH`` environment.
74 This *which* searches the PATH for executable ``cmd`` . First match is
77 envpath = os.environ.get('PATH', None) or os.defpath
80 if path.isfile(fname):
84 if not path.isdir(folder):
99 return (path.exists(path1)
106 # -------------------------------------------
110 # dot(1) -Tpdf should be used
116 # librsvg's rsvg-convert(1) support
127 app.connect('builder-inited', setupTools)
130 app.add_directive("kernel-image", KernelImage)
139 app.add_directive("kernel-figure", KernelFigure)
148 app.add_directive('kernel-render', KernelRender)
156 app.connect('doctree-read', add_kernel_figure_to_std_domain)
177 rsvg_convert_cmd = which('rsvg-convert')
184 dot_Thelp_list = subprocess.check_output([dot_cmd, '-Thelp'],
185 stderr=subprocess.STDOUT)
197 inkscape_ver = subprocess.check_output([inkscape_cmd, '--version'],
216 kernellog.verbose(app, "use rsvg-convert(1) from: " + rsvg_convert_cmd)
217 kernellog.verbose(app, "use 'dot -Tsvg' and rsvg-convert(1) for DOT -> PDF conversion")
221 "rsvg-convert(1) not found.\n"
222 " SVG rendering of convert(1) is done by ImageMagick-native renderer.")
224 kernellog.verbose(app, "use 'dot -Tpdf' for DOT -> PDF conversion")
226 kernellog.verbose(app, "use 'dot -Tsvg' and convert(1) for DOT -> PDF conversion")
230 # --------------------------
250 fname, in_ext = path.splitext(path.basename(img_node['uri']))
252 src_fname = path.join(translator.builder.srcdir, img_node['uri'])
253 if not path.exists(src_fname):
254 src_fname = path.join(translator.builder.outdir, img_node['uri'])
258 # in kernel builds, use 'make SPHINXOPTS=-v' to see verbose messages
270 dst_fname = path.join(translator.builder.outdir, fname + '.pdf')
276 dst_fname = path.join(
280 img_node['uri'] = path.join(
283 '*': path.join(translator.builder.imgpath, fname + '.svg')}
299 dst_fname = path.join(translator.builder.outdir, fname + '.pdf')
314 mkdir(path.dirname(dst_fname))
319 svg_fname = path.join(translator.builder.outdir, fname + '.svg')
342 option ``-Txxx``). Normally you will use one of the following extensions:
344 - ``.ps`` for PostScript,
345 - ``.svg`` or ``svgz`` for Structured Vector Graphics,
346 - ``.fig`` for XFIG graphics and
347 - ``.png`` or ``gif`` for common bitmap graphics.
350 out_format = path.splitext(out_fname)[1][1:]
351 cmd = [dot_cmd, '-T%s' % out_format, dot_fname]
355 exit_code = subprocess.call(cmd, stdout = out)
378 cmd = [inkscape_cmd, '-o', pdf_fname, svg_fname]
380 cmd = [inkscape_cmd, '-z', '--export-pdf=%s' % pdf_fname, svg_fname]
383 warning_msg = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
394 % (cmd_name, str(warning_msg, 'utf-8')))
397 % (cmd_name, str(warning_msg, 'utf-8')))
402 """Convert SVG to PDF with ``rsvg-convert(1)`` command.
408 SVG -> PDF conversion is done by ``rsvg-convert(1)``.
410 If ``rsvg-convert(1)`` is unavailable, fall back to ``svg2pdf()``.
417 cmd = [rsvg_convert_cmd, '--format=pdf', '-o', pdf_fname, svg_fname]
418 # use stdout and stderr from parent
428 # ---------------------
433 Handles the ``image`` child-node with the ``convert_image(...)``.
439 """Node for ``kernel-image`` directive."""
452 if uri.endswith('.*') or uri.find('://') != -1:
465 # ---------------------
470 Handles the ``image`` child-node with the ``convert_image(...)``.
476 """Node for ``kernel-figure`` directive."""
488 if uri.endswith('.*') or uri.find('://') != -1:
503 # ---------------------
511 image child-node with the ``convert_image(...)``.
516 kernellog.verbose(app, 'visit kernel-render node lang: "%s"' % (srclang))
520 kernellog.warn(app, 'kernel-render: "%s" unknown / include raw.' % (srclang))
530 hashobj = code.encode('utf-8') # str(node.attributes)
531 fname = path.join('%s-%s' % (srclang, sha1(hashobj).hexdigest()))
533 tmp_fname = path.join(
536 if not path.isfile(tmp_fname):
537 mkdir(path.dirname(tmp_fname))
542 img_node['uri'] = path.join(self.builder.imgpath, fname + tmp_ext)
544 '*': path.join(self.builder.imgpath, fname + tmp_ext)}
551 """Node for ``kernel-render`` directive."""
621 """Add kernel-figure anchors to 'std' domain.
624 the caption (label) of ``kernel-figure`` directive (it only knows about
626 this will result in a 'undefined label' for kernel-figures.
628 This handle adds labels of kernel-figure to the 'std' domain labels.