[gtk-doc] mkpdf: split into wrapper and module
- From: Stefan Sauer <stefkost src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk-doc] mkpdf: split into wrapper and module
- Date: Fri, 31 Mar 2017 19:57:01 +0000 (UTC)
commit c46f59c7681b9c0409bf1eb071c0773db0a047f1
Author: Stefan Sauer <ensonic users sf net>
Date: Fri Mar 31 21:56:35 2017 +0200
mkpdf: split into wrapper and module
Makefile.am | 6 +-
gtkdoc-mkpdf.in | 179 ++++++++++++--------------------------------------
gtkdoc/config.py.in | 2 +
gtkdoc/mkpdf.py | 122 ++++++++++++++++++++++++++++++++++
4 files changed, 171 insertions(+), 138 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 8ee64b9..baab3cb 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -40,7 +40,8 @@ pylibdata_DATA = \
gtkdoc/check.py \
gtkdoc/config.py \
gtkdoc/mkhtml.py \
- gtkdoc/mkman.py
+ gtkdoc/mkman.py \
+ gtkdoc/mkpdf.py
pkgconfigdir = $(datadir)/pkgconfig
pkgconfig_DATA = gtk-doc.pc
@@ -82,7 +83,8 @@ CLEANFILES = \
gtkdoc/check.pyc \
gtkdoc/config.pyc \
gtkdoc/mkhtml.pyc \
- gtkdoc/mkman.pyc
+ gtkdoc/mkman.pyc \
+ gtkdoc/mkpdf.pyc
DISTCLEANFILES = \
gtkdoc-check \
diff --git a/gtkdoc-mkpdf.in b/gtkdoc-mkpdf.in
index 8041551..b6377dc 100755
--- a/gtkdoc-mkpdf.in
+++ b/gtkdoc-mkpdf.in
@@ -1,137 +1,44 @@
#!@PYTHON@
-
-# Support both Python 2 and 3
-from __future__ import print_function
-
-import os, sys, argparse, subprocess
-import logging
-
-version = '@VERSION@'
-xsltproc = '@XSLTPROC@'
-dblatex = '@DBLATEX@'
-fop = '@FOP@'
-
-parser = argparse.ArgumentParser(description='gtkdoc-mkpdf version %s - generate documentation in pdf
format' % version)
-
-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')
-
-def cleanexit(exitval):
- global module
- fname = module + '.fo'
- if os.path.exists(fname):
- os.unlink(fname)
- sys.exit(exitval)
-
-options = parser.parse_args()
-
-if options.version:
- print(version)
- sys.exit(0)
-
-module=options.args[0]
-document=options.args[1]
-
-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 vars are needed to resolve datadir
- prefix='@prefix@'
- datarootdir="@datarootdir@".replace('${prefix}', prefix)
- datadir="@datadir@".replace('${datarootdir}', datarootdir)
- gtkdocdir=os.path.join(datadir, 'gtk-doc/data')
-
-# 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
-def run_xsltproc(args):
- global options, xsltproc
- # we could do "--path $PWD "
- # to avoid needing rewriting entities that are copied from the header
- # into docs under xml
- if len(options.path) == 0:
- cmd = [xsltproc] + args
- else:
- cmd = [xsltproc, '--path'] + 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 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 $searchpath --nonet $@"
- dblatex_options=['-o', module + '.pdf']
- for i in options.imgdir:
- dblatex_options += ['-I', i]
- dblatex_options.append(document)
- 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 not line.strip():
- continue
- if 'programlisting or screen' in line:
- continue
- # This happens when dblatex has no support for some special chars
- if 'Missing character' in line:
- continue
- print(line)
-elif fop != '':
- if options.verbose:
- quiet = '0'
- else:
- quiet = '1'
- run_xsltproc(['--nonet',
- '--xinclude',
- '--stringparam',
- 'gtkdoc.bookname',
- module,
- '--stringparam',
- 'gtkdoc.version',
- version,
- '--stringparam',
- 'chunk.quietly',
- 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)
-
-open('pdf.stamp', 'w').write('timestamp')
-cleanexit(0)
+# -*- python; coding: utf-8 -*-
+#
+# gtk-doc - GTK DocBook documentation generator.
+# Copyright (C) 2009-2017 Stefan Sauer
+# 2017 Jussi Pakkanen
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+
+import argparse, sys
+sys.path.append('@PYTHON_PACKAGE_DIR@')
+
+from gtkdoc import config, mkpdf
+
+if __name__== '__main__':
+ parser = argparse.ArgumentParser(
+ description='gtkdoc-mkpdf version %s - generate documentation in pdf format' % config.version)
+ parser.add_argument('--version', action='version', version=config.version)
+ 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('--uninstalled', action='store_true', default=False,
+ help='???')
+ parser.add_argument('args', nargs=2,
+ help='MODULE DRIVER_FILE')
+
+ options = parser.parse_args()
+ sys.exit(mkpdf.run(options))
diff --git a/gtkdoc/config.py.in b/gtkdoc/config.py.in
index 30d959e..08dc7ec 100644
--- a/gtkdoc/config.py.in
+++ b/gtkdoc/config.py.in
@@ -2,6 +2,8 @@ version = "@VERSION@"
# tools
xsltproc = '@XSLTPROC@'
+dblatex = '@DBLATEX@'
+fop = '@FOP@'
# configured directories
prefix='@prefix@'
diff --git a/gtkdoc/mkpdf.py b/gtkdoc/mkpdf.py
new file mode 100755
index 0000000..0b456aa
--- /dev/null
+++ b/gtkdoc/mkpdf.py
@@ -0,0 +1,122 @@
+#!@PYTHON@
+# -*- python; coding: utf-8 -*-
+#
+# gtk-doc - GTK DocBook documentation generator.
+# Copyright (C) 2009-2017 Stefan Sauer
+# 2017 Jussi Pakkanen
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+
+# Support both Python 2 and 3
+from __future__ import print_function
+
+import os, sys, argparse, subprocess
+
+from . import config
+
+
+def run_xsltproc(options, args):
+ # we could do "--path $PWD " to avoid needing rewriting entities that are
+ # copied from the header into docs under xml
+ if len(options.path) == 0:
+ cmd = [config.xsltproc] + args
+ else:
+ cmd = [config.xsltproc, '--path'] + options.searchpath + args
+ pc = subprocess.Popen(cmd, stderr=subprocess.PIPE)
+ (o, stde) = pc.communicate()
+ open('profile.txt', 'wb').write(stde)
+ return pc.returncode
+
+
+def run(options):
+ module = options.args[0]
+ document = options.args[1]
+
+ 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]
+ else:
+ gtkdocdir = os.path.join(config.datadir, 'gtk-doc/data')
+
+ if config.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 $searchpath --nonet $@"
+ dblatex_options = ['-o', module + '.pdf']
+ for i in options.imgdir:
+ dblatex_options += ['-I', i]
+ dblatex_options.append(document)
+ if not options.verbose:
+ pc = subprocess.Popen([config.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 = [config.dblatex] + dblatex_options
+ pc = subprocess.Popen(dbcmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ (stde, _) = pc.communicate()
+ for line in stde.split('\n'):
+ if not line.strip():
+ continue
+ if 'programlisting or screen' in line:
+ continue
+ # This happens when dblatex has no support for some special chars
+ if 'Missing character' in line:
+ continue
+ print(line)
+ res = pc.returncode
+ elif config.fop != '':
+ if options.verbose:
+ quiet = '0'
+ else:
+ quiet = '1'
+ res = run_xsltproc(options, ['--nonet',
+ '--xinclude',
+ '--stringparam',
+ 'gtkdoc.bookname',
+ module,
+ '--stringparam',
+ 'gtkdoc.version',
+ config.version,
+ '--stringparam',
+ 'chunk.quietly',
+ quiet,
+ '--stringparam',
+ 'chunker.output.quiet',
+ quiet,
+ module,
+ document,
+ '-o',
+ module + '.fo',
+ gtkdocdir + '/gtk-doc-fo.xsl',
+ document])
+ # fop dies too easily :(
+ # config.fop $module.fo $module.pdf
+ fname = module + '.fo'
+ if os.path.exists(fname):
+ os.unlink(fname)
+ else:
+ print("dblatex or fop must be installed to use gtkdoc-mkpdf.")
+ res = 1
+
+ open('pdf.stamp', 'w').write('timestamp')
+ return res
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]