##// END OF EJS Templates
add comment clarifying that `out is None` when verbose=True
MinRK -
Show More
@@ -1,58 +1,60 b''
1 1 """
2 2 Contains writer for writing nbconvert output to PDF.
3 3 """
4 4 #-----------------------------------------------------------------------------
5 5 #Copyright (c) 2013, the IPython Development Team.
6 6 #
7 7 #Distributed under the terms of the Modified BSD License.
8 8 #
9 9 #The full license is in the file COPYING.txt, distributed with this software.
10 10 #-----------------------------------------------------------------------------
11 11
12 12 #-----------------------------------------------------------------------------
13 13 # Imports
14 14 #-----------------------------------------------------------------------------
15 15
16 16 import subprocess
17 17 import os
18 18
19 19 from IPython.utils.traitlets import Integer, List, Bool
20 20
21 21 from .base import PostProcessorBase
22 22
23 23 #-----------------------------------------------------------------------------
24 24 # Classes
25 25 #-----------------------------------------------------------------------------
26 26 class PDFPostProcessor(PostProcessorBase):
27 27 """Writer designed to write to PDF files"""
28 28
29 29 iteration_count = Integer(3, config=True, help="""
30 30 How many times pdflatex will be called.
31 31 """)
32 32
33 33 command = List(["pdflatex", "{filename}"], config=True, help="""
34 34 Shell command used to compile PDF.""")
35 35
36 36 verbose = Bool(False, config=True, help="""
37 37 Whether or not to display the output of the compile call.
38 38 """)
39 39
40 40 def call(self, input):
41 41 """
42 42 Consume and write Jinja output a PDF.
43 43 See files.py for more...
44 44 """
45 45 command = [c.format(filename=input) for c in self.command]
46 46 self.log.info("Building PDF: %s", command)
47 47 with open(os.devnull, 'rb') as null:
48 48 stdout = subprocess.PIPE if not self.verbose else None
49 49 for index in range(self.iteration_count):
50 50 p = subprocess.Popen(command, stdout=stdout, stdin=null)
51 51 out, err = p.communicate()
52 52 if p.returncode:
53 53 if self.verbose:
54 # verbose means I didn't capture stdout with PIPE,
55 # so it's already been displayed and `out` is None.
54 56 out = u''
55 57 else:
56 58 out = out.decode('utf-8', 'replace')
57 59 self.log.critical(u"PDF conversion failed: %s\n%s", command, out)
58 60 return
General Comments 0
You need to be logged in to leave comments. Login now