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