common: return dicts not tuples
[gtk-doc.git] / gtkdoc / mkpdf.py
blob56d0f62355ed77f8817683fdfe3f8fa047e041b7
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 os
26 import sys
27 import subprocess
29 from . import config
32 def run_xsltproc(options, args):
33 # we could do "--path $PWD " to avoid needing rewriting entities that are
34 # copied from the header into docs under xml
35 if len(options.path) == 0:
36 cmd = [config.xsltproc] + args
37 else:
38 cmd = [config.xsltproc, '--path'] + options.searchpath + args
39 pc = subprocess.Popen(cmd, stderr=subprocess.PIPE)
40 (o, stde) = pc.communicate()
41 open('profile.txt', 'wb').write(stde)
42 return pc.returncode
45 def run(options):
46 module = options.args[0]
47 document = options.args[1]
49 if options.uninstalled:
50 # this does not work from buiddir!=srcdir
51 # we could try this
52 # MAKE_SCRDIR=$(abs_srcdir) MAKE_BUILDDIR=$(abs_builddir) gtkdoc-mkpdf ...
53 gtkdocdir = os.path.split(sys.argv[0])[0]
54 else:
55 gtkdocdir = os.path.join(config.datadir, 'gtk-doc/data')
57 if config.dblatex != '':
58 # extra options to consider
59 # -I FIG_PATH
60 # -V is useful for debugging
61 # -T db2latex : different style
62 # -d : keep transient files (for debugging)
63 # -P abc.def=$quiet : once the stylesheets have a quiet mode
64 # xsltproc is already called with --xinclude
65 # does not work: --xslt-opts "--path $searchpath --nonet $@"
66 dblatex_options = ['-o', module + '.pdf']
67 for i in options.imgdir:
68 dblatex_options += ['-I', i]
69 dblatex_options.append(document)
70 if not options.verbose:
71 pc = subprocess.Popen([config.dblatex, '--help'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
72 (stdo, stde) = pc.communicate()
73 if b'--quiet' in stdo or b'--quiet' in stde:
74 dblatex_options = ['--quiet'] + dblatex_options
75 dbcmd = [config.dblatex] + dblatex_options
76 pc = subprocess.Popen(dbcmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
77 (stde, _) = pc.communicate()
78 for line in stde.split('\n'):
79 if not line.strip():
80 continue
81 if 'programlisting or screen' in line:
82 continue
83 # This happens when dblatex has no support for some special chars
84 if 'Missing character' in line:
85 continue
86 print(line)
87 res = pc.returncode
88 elif config.fop != '':
89 if options.verbose:
90 quiet = '0'
91 else:
92 quiet = '1'
93 res = run_xsltproc(options, ['--nonet',
94 '--xinclude',
95 '--stringparam',
96 'gtkdoc.bookname',
97 module,
98 '--stringparam',
99 'gtkdoc.version',
100 config.version,
101 '--stringparam',
102 'chunk.quietly',
103 quiet,
104 '--stringparam',
105 'chunker.output.quiet',
106 quiet,
107 module,
108 document,
109 '-o',
110 module + '.fo',
111 gtkdocdir + '/gtk-doc-fo.xsl',
112 document])
113 # TODO: fop dies too easily :(
114 # res = subprocess.call([config.fop, module + '.fo', module + '.pdf'))
115 fname = module + '.fo'
116 if os.path.exists(fname):
117 os.unlink(fname)
118 else:
119 print("dblatex or fop must be installed to use gtkdoc-mkpdf.")
120 res = 1
122 open('pdf.stamp', 'w').write('timestamp')
123 return res