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