db2html: add support for tables
[gtk-doc.git] / gtkdoc / mkpdf.py
blob75cf926da115734b79ae7d5dd51bac758ebd80fe
1 # -*- python; coding: utf-8 -*-
3 # gtk-doc - GTK DocBook documentation generator.
4 # Copyright (C) 2009-2017 Stefan Sauer
5 # 2017 Jussi Pakkanen
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 # Support both Python 2 and 3
23 from __future__ import print_function
25 import logging
26 import os
27 import sys
28 import subprocess
30 from . import config
33 def run_xsltproc(options, args):
34 command = [config.xsltproc]
35 # we could do "--path $PWD " to avoid needing rewriting entities that are
36 # copied from the header into docs under xml
37 for path in options.path:
38 command += ['--path', path]
39 logging.info('running "%s"', ' '.join(command + args))
40 pc = subprocess.Popen(command + args, stderr=subprocess.PIPE)
41 (o, stde) = pc.communicate()
42 with open('profile.txt', 'wb') as h:
43 h.write(stde)
44 return pc.returncode
47 def run(options):
48 module = options.args[0]
49 document = options.args[1]
51 if options.uninstalled:
52 # this does not work from buiddir!=srcdir
53 # we could try this
54 # MAKE_SCRDIR=$(abs_srcdir) MAKE_BUILDDIR=$(abs_builddir) gtkdoc-mkpdf ...
55 gtkdocdir = os.path.split(sys.argv[0])[0]
56 else:
57 gtkdocdir = os.path.join(config.datadir, 'gtk-doc/data')
59 if config.dblatex != '':
60 # extra options to consider
61 # -I FIG_PATH
62 # -V is useful for debugging
63 # -T db2latex : different style
64 # -d : keep transient files (for debugging)
65 # -P abc.def=$quiet : once the stylesheets have a quiet mode
66 # xsltproc is already called with --xinclude
67 # does not work: --xslt-opts "--path $searchpath --nonet $@"
68 dblatex_options = ['-o', module + '.pdf']
69 for i in options.imgdir:
70 dblatex_options += ['-I', i]
71 dblatex_options.append(document)
72 if not options.verbose:
73 pc = subprocess.Popen([config.dblatex, '--help'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
74 (stdo, stde) = pc.communicate()
75 if b'--quiet' in stdo or b'--quiet' in stde:
76 dblatex_options = ['--quiet'] + dblatex_options
77 dbcmd = [config.dblatex] + dblatex_options
78 pc = subprocess.Popen(dbcmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
79 (stde, _) = pc.communicate()
80 for line in stde.decode('utf-8').split('\n'):
81 if not line.strip():
82 continue
83 if 'programlisting or screen' in line:
84 continue
85 # This happens when dblatex has no support for some special chars
86 if 'Missing character' in line:
87 continue
88 print(line)
89 res = pc.returncode
90 elif config.fop != '':
91 if options.verbose:
92 quiet = '0'
93 else:
94 quiet = '1'
95 res = run_xsltproc(options, ['--nonet',
96 '--xinclude',
97 '--stringparam',
98 'gtkdoc.bookname',
99 module,
100 '--stringparam',
101 'gtkdoc.version',
102 config.version,
103 '--stringparam',
104 'chunk.quietly',
105 quiet,
106 '--stringparam',
107 'chunker.output.quiet',
108 quiet,
109 module,
110 document,
111 '-o',
112 module + '.fo',
113 gtkdocdir + '/gtk-doc-fo.xsl',
114 document])
115 # TODO: fop dies too easily :(
116 # res = subprocess.call([config.fop, module + '.fo', module + '.pdf'))
117 fname = module + '.fo'
118 if os.path.exists(fname):
119 os.unlink(fname)
120 else:
121 print("dblatex or fop must be installed to use gtkdoc-mkpdf.")
122 res = 1
124 with open('pdf.stamp', 'w') as h:
125 h.write('timestamp')
126 return res