diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2017-03-02 15:06:04 +0200 |
---|---|---|
committer | Stefan Sauer <ensonic@users.sf.net> | 2017-03-20 20:31:50 +0100 |
commit | 91bc782d50e035c5c2818d503426824d176322ff (patch) | |
tree | 63f49662c48e7f87e910be606741f9c8fe92e576 /gtkdoc-mkpdf.in | |
parent | 1db161bd708cdfb88b362ea0b5d047034d9c3272 (diff) | |
download | gtk-doc-91bc782d50e035c5c2818d503426824d176322ff.tar.gz |
Converted mkpdf, mkman and mkhtml to Python.
https://bugzilla.gnome.org/show_bug.cgi?id=779566
Diffstat (limited to 'gtkdoc-mkpdf.in')
-rwxr-xr-x[-rw-r--r--] | gtkdoc-mkpdf.in | 230 |
1 files changed, 117 insertions, 113 deletions
diff --git a/gtkdoc-mkpdf.in b/gtkdoc-mkpdf.in index 9b39ddf..5dcf758 100644..100755 --- a/gtkdoc-mkpdf.in +++ b/gtkdoc-mkpdf.in @@ -1,137 +1,141 @@ -#!/bin/sh -# +#!@PYTHON@ -usage() { -cat <<EOF -gtkdoc-mkpdf version @VERSION@ - generate documentation in pdf format +# Support both Python 2 and 3 +from __future__ import print_function ---verbose Print extra output while processing ---path=SEARCH_PATH Extra source directories ---imgdir=DIR Extra image directories -MODULE Name of the doc module being parsed -DRIVER_FILE File containing the toplevel DocBook file. ---version Print the version of this program ---help Print this help -EOF -} +import os, sys, argparse, subprocess +import logging -#echo "args $0\n"; +version = '@VERSION@' +xsltproc = '@XSLTPROC@' +dblatex = '@DBLATEX@' +fop = '@FOP@' -cleanexit() { - rm -f $module.fo - exit $1 -} +parser = argparse.ArgumentParser(description='gtkdoc-mkpdf version %s - generate documentation in pdf format' % version) -# parse options, ignore unknown options for future extensions +parser.add_argument('--verbose', default=False, action='store_true', + help='Print extra output while processing.') +parser.add_argument('--path', default=[], action='append', + help='Extra source directories.') +parser.add_argument('--imgdir', default=[], action='append', + help='Extra image directories.') +parser.add_argument('--version', default=False, action='store_true', + help='Print the version of this program') +parser.add_argument('--uninstalled', action='store_true', default=False, + help='???') +parser.add_argument('args', nargs=2, + help='MODULE DRIVER_FILE') -verbose="0" -searchpath= -uninstalled=no -imgdirs= -while true; do - case "X$1" in - X--version) echo "@VERSION@"; exit 0;; - X--help) usage; exit 0;; - X--uninstalled) uninstalled=yes; shift;; - X--verbose) verbose="1"; shift;; - X--path=*) searchpath=`echo "$1" | sed s/.*=//`; shift;; - X--imgdir=*) imgdirs="$imgdirs -I `echo "$1" | sed s/.*=//`"; shift;; - X--*) shift;; - X*) break;; - esac -done +def cleanexit(exitval): + global module + fname = module + '.fo' + if os.path.exists(fname): + os.unlink(fname) + sys.exit(exitval) -if test $# -lt 2; then - usage 1>&2 - exit 1 -fi +options = parser.parse_args() -module="$1" -shift -document="$1" -shift +if options.version: + print(version) + sys.exit(0) -quiet="1" -if test $verbose = "1"; then - quiet="0" -fi +module=options.args[0] +document=options.args[1] -if test $uninstalled = yes; then - # this does not work from buiddir!=srcdir - # we could try this - # MAKE_SCRDIR=$(abs_srcdir) MAKE_BUILDDIR=$(abs_builddir) gtkdoc-mkpdf ... - gtkdocdir=`dirname $0` - #echo "uninstalled, gtkdocdir=$gtkdocdir" -else - # the first two are needed to resolve datadir - prefix=@prefix@ - datarootdir=@datarootdir@ - gtkdocdir=@datadir@/gtk-doc/data -fi +if options.uninstalled: + # this does not work from buiddir!=srcdir + # we could try this + # MAKE_SCRDIR=$(abs_srcdir) MAKE_BUILDDIR=$(abs_builddir) gtkdoc-mkpdf ... + gtkdocdir=os.path.split(sys.argv[0])[0] + logging.debug("uninstalled, gtkdocdir=" + gtkdocdir) +else: + # the first two are needed to resolve datadir + prefix='@prefix@' + datarootdir='@datarootdir@' + gtkdocdir='@datadir@'/gtk-doc/data -if head -n 1 $document | grep "<?xml" > /dev/null; then - is_xml=true +if "<?xml" in open(document).readline(): + is_xml=True path_option='--path' -else - is_xml=false +else: + is_xml=False path_option='--directory' -fi # We need to use a wrapper because there's no other way to conditionally pass # a `--path $searchpath` argument with proper quoting for the path -run_xsltproc() { +def run_xsltproc(args): + global options, xsltproc # we could do "$path_option $PWD " # to avoid needing rewriting entities that are copied from the header # into docs under xml - if test "X$searchpath" = "X"; then - @XSLTPROC@ 2>profile.txt "$@" - else - @XSLTPROC@ 2>profile.txt "$path_option" "$searchpath" "$@" - fi -} + if len(options.path) == 0: + cmd = [xsltproc] + args + else: + cmd = [xsltproc, path_option] + options.searchpath + args + pc = subprocess.Popen(cmd, stderr=subprocess.PIPE) + (o, stde) = pc.communicate() + open('profile.txt', 'wb').write(stde) + if pc.returncode != 0: + cleanexit(pc.returncode) -if $is_xml; then - if test -n "@DBLATEX@"; then - # extra options to consider - # -I FIG_PATH - # -V is useful for debugging - # -T db2latex : different style - # -d : keep transient files (for debugging) - # -P abc.def=$quiet : once the stylesheets have a quiet mode - # xsltproc is already called with --xinclude - # does not work: --xslt-opts "$path_option $searchpath --nonet $@" - dblatex_options="-o $module.pdf $imgdirs $document" - #echo "calling: @DBLATEX@ $dblatex_options" - if test $verbose = "0"; then - @DBLATEX@ 2>&1 --help | grep >/dev/null "\-\-quiet" - if test "$?" = "0"; then - dblatex_options="--quiet $dblatex_options"; - fi; - @DBLATEX@ 2>&1 >/dev/null $dblatex_options | grep -v 'programlisting or screen' - else - { @DBLATEX@ 2>&1 >&3 $dblatex_options | grep -v 'programlisting or screen' >&2; } 3>&1 - fi - else - if test -n "@FOP@"; then - run_xsltproc --nonet --xinclude \ - --stringparam gtkdoc.bookname "$module" \ - --stringparam gtkdoc.version "@VERSION@" \ - --stringparam chunk.quietly $quiet \ - --stringparam chunker.output.quiet $quiet \ - "$@" -o "$module.fo" "$gtkdocdir/gtk-doc-fo.xsl" "$document" || cleanexit $? - # fop dies too easily :( - # @FOP@ $module.fo $module.pdf - else - echo "dblatex or fop must be installed to use gtkdoc-mkpdf." >&2 - cleanexit 1 - fi - fi -else +if is_xml: + if dblatex != '': + # extra options to consider + # -I FIG_PATH + # -V is useful for debugging + # -T db2latex : different style + # -d : keep transient files (for debugging) + # -P abc.def=$quiet : once the stylesheets have a quiet mode + # xsltproc is already called with --xinclude + # does not work: --xslt-opts "$path_option $searchpath --nonet $@" + dblatex_options=['-o', module + '.pdf'] + for i in options.imgdir: + dblatex_options += ['-I', i] + dblatex_options.append(document) + #echo "calling: @DBLATEX@ $dblatex_options" + if not options.verbose: + pc = subprocess.Popen([dblatex, '--help'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + (stdo, stde) = pc.communicate() + if b'--quiet' in stdo or b'--quiet' in stde: + dblatex_options= ['--quiet'] + dblatex_options + dbcmd = [dblatex] + dblatex_options + pc = subprocess.Popen(dbcmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + (stde, _) = pc.communicate() + for line in stde.split('\n'): + if 'programlisting or screen' not in line and line.strip(): + print(line) + else: + if fop != '': + run_xsltproc(['--nonet', + '--xinclude', + '--stringparam', + 'gtkdoc.bookname', + module, + '--stringparam', + 'gtkdoc.version', + version, + '--stringparam', + 'chunk.quietly', + options.quiet, + '--stringparam', + 'chunker.output.quiet', + quiet, + module, + document, + '-o', + module + '.fo', + gtkdocdir + '/gtk-doc-fo.xsl', + document]) + # fop dies too easily :( + # @FOP@ $module.fo $module.pdf + else: + print("dblatex or fop must be installed to use gtkdoc-mkpdf.") + cleanexit(1) +else: # not very good output # also for xxx-docs.sgml it will produce xxx-docs.pdf - docbook2pdf -e no-valid "$document" -fi + subprocess.check_call(['docbook2pdf', '-e', 'no-valid', document]) -echo "timestamp" > pdf.stamp -cleanexit 0 +open('pdf.stamp', 'w').write('timestamp') +cleanexit(0) |