Show More
@@ -131,7 +131,7 b' class Exporter(Configurable):' | |||||
131 |
|
131 | |||
132 | default_transformers = List([nbtransformers.coalesce_streams, |
|
132 | default_transformers = List([nbtransformers.coalesce_streams, | |
133 | nbtransformers.SVG2PDFTransformer, |
|
133 | nbtransformers.SVG2PDFTransformer, | |
134 |
nbtransformers.Extract |
|
134 | nbtransformers.ExtractOutputTransformer, | |
135 | nbtransformers.CSSHTMLHeaderTransformer, |
|
135 | nbtransformers.CSSHTMLHeaderTransformer, | |
136 | nbtransformers.RevealHelpTransformer, |
|
136 | nbtransformers.RevealHelpTransformer, | |
137 | nbtransformers.LatexTransformer, |
|
137 | nbtransformers.LatexTransformer, |
@@ -88,7 +88,7 b' class LatexExporter(Exporter):' | |||||
88 | 'NbConvertBase': { |
|
88 | 'NbConvertBase': { | |
89 | 'display_data_priority' : ['latex', 'pdf', 'png', 'jpg', 'svg', 'jpeg', 'text'] |
|
89 | 'display_data_priority' : ['latex', 'pdf', 'png', 'jpg', 'svg', 'jpeg', 'text'] | |
90 | }, |
|
90 | }, | |
91 |
'Extract |
|
91 | 'ExtractOutputTransformer': { | |
92 | 'enabled':True |
|
92 | 'enabled':True | |
93 | }, |
|
93 | }, | |
94 | 'SVG2PDFTransformer': { |
|
94 | 'SVG2PDFTransformer': { |
@@ -37,6 +37,6 b' class RSTExporter(Exporter):' | |||||
37 |
|
37 | |||
38 | @property |
|
38 | @property | |
39 | def default_config(self): |
|
39 | def default_config(self): | |
40 |
c = Config({'Extract |
|
40 | c = Config({'ExtractOutputTransformer':{'enabled':True}}) | |
41 | c.merge(super(RSTExporter,self).default_config) |
|
41 | c.merge(super(RSTExporter,self).default_config) | |
42 | return c |
|
42 | return c |
@@ -45,16 +45,16 b' class TestExporter(ExportersTestsBase):' | |||||
45 | assert len(output) > 0 |
|
45 | assert len(output) > 0 | |
46 |
|
46 | |||
47 |
|
47 | |||
48 |
def test_extract_ |
|
48 | def test_extract_outputs(self): | |
49 | """ |
|
49 | """ | |
50 |
If the Extract |
|
50 | If the ExtractOutputTransformer is enabled, are outputs extracted? | |
51 | """ |
|
51 | """ | |
52 |
config = Config({'Extract |
|
52 | config = Config({'ExtractOutputTransformer': {'enabled': True}}) | |
53 | exporter = self._make_exporter(config=config) |
|
53 | exporter = self._make_exporter(config=config) | |
54 | (output, resources) = exporter.from_filename(self._get_notebook()) |
|
54 | (output, resources) = exporter.from_filename(self._get_notebook()) | |
55 | assert resources is not None |
|
55 | assert resources is not None | |
56 |
assert ' |
|
56 | assert 'outputs' in resources | |
57 |
assert len(resources[' |
|
57 | assert len(resources['outputs']) > 0 | |
58 |
|
58 | |||
59 |
|
59 | |||
60 | def test_transformer_class(self): |
|
60 | def test_transformer_class(self): |
@@ -15,13 +15,13 b' Command-line interface for the NbConvert conversion utility.' | |||||
15 | #Imports |
|
15 | #Imports | |
16 | #----------------------------------------------------------------------------- |
|
16 | #----------------------------------------------------------------------------- | |
17 |
|
17 | |||
18 | #Stdlib imports |
|
18 | # Stdlib imports | |
19 | from __future__ import print_function |
|
19 | from __future__ import print_function | |
20 | import sys |
|
20 | import sys | |
21 | import os |
|
21 | import os | |
22 | import glob |
|
22 | import glob | |
23 |
|
23 | |||
24 | #From IPython |
|
24 | # From IPython | |
25 | from IPython.core.application import BaseIPythonApplication, base_aliases, base_flags |
|
25 | from IPython.core.application import BaseIPythonApplication, base_aliases, base_flags | |
26 | from IPython.config import catch_config_error, Configurable |
|
26 | from IPython.config import catch_config_error, Configurable | |
27 | from IPython.utils.traitlets import ( |
|
27 | from IPython.utils.traitlets import ( | |
@@ -103,7 +103,7 b' class NbConvertApp(BaseIPythonApplication):' | |||||
103 |
|
103 | |||
104 | > ipython nbconvert --config mycfg.py |
|
104 | > ipython nbconvert --config mycfg.py | |
105 | """.format(get_export_names())) |
|
105 | """.format(get_export_names())) | |
106 | #Writer specific variables |
|
106 | # Writer specific variables | |
107 | writer = Instance('IPython.nbconvert.writers.base.WriterBase', |
|
107 | writer = Instance('IPython.nbconvert.writers.base.WriterBase', | |
108 | help="""Instance of the writer class used to write the |
|
108 | help="""Instance of the writer class used to write the | |
109 | results of the conversion.""") |
|
109 | results of the conversion.""") | |
@@ -121,7 +121,7 b' class NbConvertApp(BaseIPythonApplication):' | |||||
121 | self.writer_factory = import_item(new) |
|
121 | self.writer_factory = import_item(new) | |
122 |
|
122 | |||
123 |
|
123 | |||
124 | #Other configurable variables |
|
124 | # Other configurable variables | |
125 | export_format = CaselessStrEnum(get_export_names(), |
|
125 | export_format = CaselessStrEnum(get_export_names(), | |
126 | default_value="full_html", |
|
126 | default_value="full_html", | |
127 | config=True, |
|
127 | config=True, | |
@@ -153,7 +153,7 b' class NbConvertApp(BaseIPythonApplication):' | |||||
153 | else: |
|
153 | else: | |
154 | patterns = self.notebooks |
|
154 | patterns = self.notebooks | |
155 |
|
155 | |||
156 | #Use glob to replace all the notebook patterns with filenames. |
|
156 | # Use glob to replace all the notebook patterns with filenames. | |
157 | filenames = [] |
|
157 | filenames = [] | |
158 | for pattern in patterns: |
|
158 | for pattern in patterns: | |
159 | for filename in glob.glob(pattern): |
|
159 | for filename in glob.glob(pattern): | |
@@ -179,17 +179,18 b' class NbConvertApp(BaseIPythonApplication):' | |||||
179 | """ |
|
179 | """ | |
180 | Convert the notebooks in the self.notebook traitlet |
|
180 | Convert the notebooks in the self.notebook traitlet | |
181 | """ |
|
181 | """ | |
182 | #Export each notebook |
|
182 | # Export each notebook | |
183 | conversion_success = 0 |
|
183 | conversion_success = 0 | |
184 | for notebook_filename in self.notebooks: |
|
184 | for notebook_filename in self.notebooks: | |
185 |
|
185 | |||
186 | #Get a unique key for the notebook and set it in the resources object. |
|
186 | # Get a unique key for the notebook and set it in the resources object. | |
187 | basename = os.path.basename(notebook_filename) |
|
187 | basename = os.path.basename(notebook_filename) | |
188 | notebook_name = basename[:basename.rfind('.')] |
|
188 | notebook_name = basename[:basename.rfind('.')] | |
189 | resources = {} |
|
189 | resources = {} | |
190 | resources['unique_key'] = notebook_name |
|
190 | resources['unique_key'] = notebook_name | |
|
191 | resources['output_files_dir'] = '%s_files' % notebook_name | |||
191 |
|
192 | |||
192 | #Try to export |
|
193 | # Try to export | |
193 | try: |
|
194 | try: | |
194 | output, resources = export_by_name(self.export_format, |
|
195 | output, resources = export_by_name(self.export_format, | |
195 | notebook_filename, |
|
196 | notebook_filename, | |
@@ -202,22 +203,22 b' class NbConvertApp(BaseIPythonApplication):' | |||||
202 | "\n\t" + "\n\t".join(get_export_names()), |
|
203 | "\n\t" + "\n\t".join(get_export_names()), | |
203 | file=sys.stderr) |
|
204 | file=sys.stderr) | |
204 | sys.exit(-1) |
|
205 | sys.exit(-1) | |
205 | #except Exception as e: |
|
206 | # except Exception as e: | |
206 | #print("Error: could not export '%s'" % notebook_filename, file=sys.stderr) |
|
207 | # print("Error: could not export '%s'" % notebook_filename, file=sys.stderr) | |
207 | #print(e, file=sys.stderr) |
|
208 | # print(e, file=sys.stderr) | |
208 | else: |
|
209 | else: | |
209 | self.writer.write(output, resources, notebook_name=notebook_name) |
|
210 | self.writer.write(output, resources, notebook_name=notebook_name) | |
210 | conversion_success += 1 |
|
211 | conversion_success += 1 | |
211 |
|
212 | |||
212 | #If nothing was converted successfully, help the user. |
|
213 | # If nothing was converted successfully, help the user. | |
213 | if conversion_success == 0: |
|
214 | if conversion_success == 0: | |
214 |
|
215 | |||
215 | #No notebooks were specified, show help. |
|
216 | # No notebooks were specified, show help. | |
216 | if len(self.notebooks) == 0: |
|
217 | if len(self.notebooks) == 0: | |
217 | self.print_help() |
|
218 | self.print_help() | |
218 |
|
219 | |||
219 | #Notebooks were specified, but not converted successfully. Show how |
|
220 | # Notebooks were specified, but not converted successfully. Show how | |
220 | #to access help. |
|
221 | # to access help. | |
221 | else: |
|
222 | else: | |
222 | print('For help, use "ipython nbconvert --help"') |
|
223 | print('For help, use "ipython nbconvert --help"') | |
223 |
|
224 |
@@ -23,7 +23,7 b' from IPython.utils import py3compat' | |||||
23 | # Constants |
|
23 | # Constants | |
24 | #----------------------------------------------------------------------------- |
|
24 | #----------------------------------------------------------------------------- | |
25 |
|
25 | |||
26 | #Define ipython commandline name |
|
26 | # Define ipython commandline name | |
27 | if py3compat.PY3: |
|
27 | if py3compat.PY3: | |
28 | IPYTHON = 'ipython3' |
|
28 | IPYTHON = 'ipython3' | |
29 | else: |
|
29 | else: | |
@@ -53,8 +53,8 b' class TestNbConvertApp(TestsBase):' | |||||
53 | with self.create_temp_cwd(['notebook*.ipynb']): |
|
53 | with self.create_temp_cwd(['notebook*.ipynb']): | |
54 | assert not 'error' in self.call([IPYTHON, 'nbconvert', |
|
54 | assert not 'error' in self.call([IPYTHON, 'nbconvert', | |
55 | '--format="python"', '--notebooks=["*.ipynb"]']).lower() |
|
55 | '--format="python"', '--notebooks=["*.ipynb"]']).lower() | |
56 |
assert os.path.isfile( |
|
56 | assert os.path.isfile('notebook1.py') | |
57 |
assert os.path.isfile( |
|
57 | assert os.path.isfile('notebook2.py') | |
58 |
|
58 | |||
59 |
|
59 | |||
60 | def test_glob_subdir(self): |
|
60 | def test_glob_subdir(self): | |
@@ -65,8 +65,8 b' class TestNbConvertApp(TestsBase):' | |||||
65 | self.copy_files_to(['notebook*.ipynb'], 'subdir/') |
|
65 | self.copy_files_to(['notebook*.ipynb'], 'subdir/') | |
66 | assert not 'error' in self.call([IPYTHON, 'nbconvert', '--format="python"', |
|
66 | assert not 'error' in self.call([IPYTHON, 'nbconvert', '--format="python"', | |
67 | '--notebooks=["%s"]' % os.path.join('subdir', '*.ipynb')]).lower() |
|
67 | '--notebooks=["%s"]' % os.path.join('subdir', '*.ipynb')]).lower() | |
68 |
assert os.path.isfile( |
|
68 | assert os.path.isfile('notebook1.py') | |
69 |
assert os.path.isfile( |
|
69 | assert os.path.isfile('notebook2.py') | |
70 |
|
70 | |||
71 |
|
71 | |||
72 | def test_explicit(self): |
|
72 | def test_explicit(self): | |
@@ -76,8 +76,8 b' class TestNbConvertApp(TestsBase):' | |||||
76 | with self.create_temp_cwd(['notebook*.ipynb']): |
|
76 | with self.create_temp_cwd(['notebook*.ipynb']): | |
77 | assert not 'error' in self.call([IPYTHON, 'nbconvert', '--format="python"', |
|
77 | assert not 'error' in self.call([IPYTHON, 'nbconvert', '--format="python"', | |
78 | '--notebooks=["notebook2.ipynb"]']).lower() |
|
78 | '--notebooks=["notebook2.ipynb"]']).lower() | |
79 |
assert not os.path.isfile( |
|
79 | assert not os.path.isfile('notebook1.py') | |
80 |
assert os.path.isfile( |
|
80 | assert os.path.isfile('notebook2.py') | |
81 |
|
81 | |||
82 |
|
82 | |||
83 | def test_glob_explicit(self): |
|
83 | def test_glob_explicit(self): | |
@@ -87,8 +87,8 b' class TestNbConvertApp(TestsBase):' | |||||
87 | with self.create_temp_cwd(['notebook*.ipynb']): |
|
87 | with self.create_temp_cwd(['notebook*.ipynb']): | |
88 | assert not 'error' in self.call([IPYTHON, 'nbconvert', '--format="python"', |
|
88 | assert not 'error' in self.call([IPYTHON, 'nbconvert', '--format="python"', | |
89 | '--notebooks=["*.ipynb", "notebook1.ipynb", "notebook2.ipynb"]']).lower() |
|
89 | '--notebooks=["*.ipynb", "notebook1.ipynb", "notebook2.ipynb"]']).lower() | |
90 |
assert os.path.isfile( |
|
90 | assert os.path.isfile('notebook1.py') | |
91 |
assert os.path.isfile( |
|
91 | assert os.path.isfile('notebook2.py') | |
92 |
|
92 | |||
93 |
|
93 | |||
94 | def test_explicit_glob(self): |
|
94 | def test_explicit_glob(self): | |
@@ -98,8 +98,8 b' class TestNbConvertApp(TestsBase):' | |||||
98 | with self.create_temp_cwd(['notebook*.ipynb']): |
|
98 | with self.create_temp_cwd(['notebook*.ipynb']): | |
99 | assert not 'error' in self.call([IPYTHON, 'nbconvert', '--format="python"', |
|
99 | assert not 'error' in self.call([IPYTHON, 'nbconvert', '--format="python"', | |
100 | '--notebooks=["notebook1.ipynb", "notebook2.ipynb", "*.ipynb"]']).lower() |
|
100 | '--notebooks=["notebook1.ipynb", "notebook2.ipynb", "*.ipynb"]']).lower() | |
101 |
assert os.path.isfile( |
|
101 | assert os.path.isfile('notebook1.py') | |
102 |
assert os.path.isfile( |
|
102 | assert os.path.isfile('notebook2.py') | |
103 |
|
103 | |||
104 |
|
104 | |||
105 | def test_default_config(self): |
|
105 | def test_default_config(self): | |
@@ -108,8 +108,8 b' class TestNbConvertApp(TestsBase):' | |||||
108 | """ |
|
108 | """ | |
109 | with self.create_temp_cwd(['notebook*.ipynb', 'ipython_nbconvert_config.py']): |
|
109 | with self.create_temp_cwd(['notebook*.ipynb', 'ipython_nbconvert_config.py']): | |
110 | assert not 'error' in self.call([IPYTHON, 'nbconvert']).lower() |
|
110 | assert not 'error' in self.call([IPYTHON, 'nbconvert']).lower() | |
111 |
assert os.path.isfile( |
|
111 | assert os.path.isfile('notebook1.py') | |
112 |
assert not os.path.isfile( |
|
112 | assert not os.path.isfile('notebook2.py') | |
113 |
|
113 | |||
114 |
|
114 | |||
115 | def test_override_config(self): |
|
115 | def test_override_config(self): | |
@@ -119,5 +119,5 b' class TestNbConvertApp(TestsBase):' | |||||
119 | with self.create_temp_cwd(['notebook*.ipynb', 'ipython_nbconvert_config.py', |
|
119 | with self.create_temp_cwd(['notebook*.ipynb', 'ipython_nbconvert_config.py', | |
120 | 'override.py']): |
|
120 | 'override.py']): | |
121 | assert not 'error' in self.call([IPYTHON, 'nbconvert', '--config="override.py"']).lower() |
|
121 | assert not 'error' in self.call([IPYTHON, 'nbconvert', '--config="override.py"']).lower() | |
122 |
assert not os.path.isfile( |
|
122 | assert not os.path.isfile('notebook1.py') | |
123 |
assert os.path.isfile( |
|
123 | assert os.path.isfile('notebook2.py') |
@@ -2,7 +2,7 b'' | |||||
2 | from .base import Transformer |
|
2 | from .base import Transformer | |
3 | from .convertfigures import ConvertFiguresTransformer |
|
3 | from .convertfigures import ConvertFiguresTransformer | |
4 | from .svg2pdf import SVG2PDFTransformer |
|
4 | from .svg2pdf import SVG2PDFTransformer | |
5 |
from .extract |
|
5 | from .extractoutput import ExtractOutputTransformer | |
6 | from .revealhelp import RevealHelpTransformer |
|
6 | from .revealhelp import RevealHelpTransformer | |
7 | from .latex import LatexTransformer |
|
7 | from .latex import LatexTransformer | |
8 | from .sphinx import SphinxTransformer |
|
8 | from .sphinx import SphinxTransformer |
@@ -46,10 +46,10 b' class ConvertFiguresTransformer(Transformer):' | |||||
46 | See base.py |
|
46 | See base.py | |
47 | """ |
|
47 | """ | |
48 |
|
48 | |||
49 | #Loop through all of the datatypes of the outputs in the cell. |
|
49 | # Loop through all of the datatypes of the outputs in the cell. | |
50 | for index, cell_out in enumerate(cell.get('outputs', [])): |
|
50 | for index, cell_out in enumerate(cell.get('outputs', [])): | |
51 | for data_type, data in cell_out.items(): |
|
51 | for data_type, data in cell_out.items(): | |
52 |
# this must run *before* extract |
|
52 | # this must run *before* extract outputs, | |
53 | # so figure_name and filename do not exist |
|
53 | # so figure_name and filename do not exist | |
54 | self._convert_figure(cell_out, resources, data_type, data) |
|
54 | self._convert_figure(cell_out, resources, data_type, data) | |
55 | return cell, resources |
|
55 | return cell, resources |
@@ -1,5 +1,5 b'' | |||||
1 |
"""Module containing a transformer that extracts all of the |
|
1 | """Module containing a transformer that extracts all of the outputs from the | |
2 |
notebook file. The extracted |
|
2 | notebook file. The extracted outputs are returned in the 'resources' dictionary. | |
3 | """ |
|
3 | """ | |
4 | #----------------------------------------------------------------------------- |
|
4 | #----------------------------------------------------------------------------- | |
5 | # Copyright (c) 2013, the IPython Development Team. |
|
5 | # Copyright (c) 2013, the IPython Development Team. | |
@@ -15,6 +15,7 b" notebook file. The extracted figures are returned in the 'resources' dictionary" | |||||
15 |
|
15 | |||
16 | import base64 |
|
16 | import base64 | |
17 | import sys |
|
17 | import sys | |
|
18 | import os | |||
18 |
|
19 | |||
19 | from IPython.utils.traitlets import Unicode |
|
20 | from IPython.utils.traitlets import Unicode | |
20 | from .base import Transformer |
|
21 | from .base import Transformer | |
@@ -24,10 +25,10 b' from IPython.utils import py3compat' | |||||
24 | # Classes |
|
25 | # Classes | |
25 | #----------------------------------------------------------------------------- |
|
26 | #----------------------------------------------------------------------------- | |
26 |
|
27 | |||
27 |
class Extract |
|
28 | class ExtractOutputTransformer(Transformer): | |
28 | """ |
|
29 | """ | |
29 |
Extracts all of the |
|
30 | Extracts all of the outputs from the notebook file. The extracted | |
30 |
|
|
31 | outputs are returned in the 'resources' dictionary. | |
31 | """ |
|
32 | """ | |
32 |
|
33 | |||
33 | figure_filename_template = Unicode( |
|
34 | figure_filename_template = Unicode( | |
@@ -50,12 +51,14 b' class ExtractFigureTransformer(Transformer):' | |||||
50 | """ |
|
51 | """ | |
51 |
|
52 | |||
52 | #Get the unique key from the resource dict if it exists. If it does not |
|
53 | #Get the unique key from the resource dict if it exists. If it does not | |
53 | #exist, use 'figure' as the default. |
|
54 | #exist, use 'figure' as the default. Also, get files directory if it | |
|
55 | #has been specified | |||
54 | unique_key = resources.get('unique_key', 'figure') |
|
56 | unique_key = resources.get('unique_key', 'figure') | |
|
57 | output_files_dir = resources.get('output_files_dir', None) | |||
55 |
|
58 | |||
56 |
#Make sure |
|
59 | #Make sure outputs key exists | |
57 |
if not ' |
|
60 | if not 'outputs' in resources: | |
58 |
resources[' |
|
61 | resources['outputs'] = {} | |
59 |
|
62 | |||
60 | #Loop through all of the outputs in the cell |
|
63 | #Loop through all of the outputs in the cell | |
61 | for index, out in enumerate(cell.get('outputs', [])): |
|
64 | for index, out in enumerate(cell.get('outputs', [])): | |
@@ -77,7 +80,7 b' class ExtractFigureTransformer(Transformer):' | |||||
77 | data = data.encode("UTF-8") |
|
80 | data = data.encode("UTF-8") | |
78 |
|
81 | |||
79 | #Build a figure name |
|
82 | #Build a figure name | |
80 |
fi |
|
83 | filename = self.figure_filename_template.format( | |
81 | unique_key=unique_key, |
|
84 | unique_key=unique_key, | |
82 | cell_index=cell_index, |
|
85 | cell_index=cell_index, | |
83 | index=index, |
|
86 | index=index, | |
@@ -87,10 +90,12 b' class ExtractFigureTransformer(Transformer):' | |||||
87 | # cell.outputs[i].svg_filename ... etc (svg in example) |
|
90 | # cell.outputs[i].svg_filename ... etc (svg in example) | |
88 | # Where |
|
91 | # Where | |
89 | # cell.outputs[i].svg contains the data |
|
92 | # cell.outputs[i].svg contains the data | |
90 | out[out_type + '_filename'] = figure_name |
|
93 | if output_files_dir is not None: | |
|
94 | filename = os.path.join(output_files_dir, filename) | |||
|
95 | out[out_type + '_filename'] = filename | |||
91 |
|
96 | |||
92 | #In the resources, make the figure available via |
|
97 | #In the resources, make the figure available via | |
93 |
# resources[' |
|
98 | # resources['outputs']['filename'] = data | |
94 |
resources[' |
|
99 | resources['outputs'][filename] = data | |
95 |
|
100 | |||
96 | return cell, resources |
|
101 | return cell, resources |
@@ -34,10 +34,10 b' class DebugWriter(WriterBase):' | |||||
34 | See base for more... |
|
34 | See base for more... | |
35 | """ |
|
35 | """ | |
36 |
|
36 | |||
37 |
if ' |
|
37 | if 'outputs' in resources: | |
38 |
print(" |
|
38 | print("outputs extracted from %s" % notebook_name) | |
39 | print('-' * 80) |
|
39 | print('-' * 80) | |
40 |
pprint.pprint(resources[' |
|
40 | pprint.pprint(resources['outputs'], indent=2, width=70) | |
41 | else: |
|
41 | else: | |
42 |
print("No |
|
42 | print("No outputs extracted from %s" % notebook_name) | |
43 | print('=' * 80) |
|
43 | print('=' * 80) |
@@ -31,12 +31,12 b' class FilesWriter(WriterBase):' | |||||
31 | """Consumes nbconvert output and produces files.""" |
|
31 | """Consumes nbconvert output and produces files.""" | |
32 |
|
32 | |||
33 |
|
33 | |||
34 |
build_directory = Unicode(" |
|
34 | build_directory = Unicode(".", config=True, | |
35 | help="""Directory to write output to. Leave blank |
|
35 | help="""Directory to write output to. Leave blank | |
36 | to output to the current directory""") |
|
36 | to output to the current directory""") | |
37 |
|
37 | |||
38 |
|
38 | |||
39 | #Make sure that the output directory exists. |
|
39 | # Make sure that the output directory exists. | |
40 | def _build_directory_changed(self, name, old, new): |
|
40 | def _build_directory_changed(self, name, old, new): | |
41 | if new and not os.path.isdir(new): |
|
41 | if new and not os.path.isdir(new): | |
42 | os.makedirs(new) |
|
42 | os.makedirs(new) | |
@@ -57,42 +57,46 b' class FilesWriter(WriterBase):' | |||||
57 | See base for more... |
|
57 | See base for more... | |
58 | """ |
|
58 | """ | |
59 |
|
59 | |||
60 | #Pull the extension from the resources dict. |
|
60 | # Pull the extension and subdir from the resources dict. | |
61 | output_extension = resources['output_extension'] |
|
61 | output_extension = resources['output_extension'] | |
62 |
|
62 | |||
63 | #Write all of the extracted resources to the destination directory. |
|
63 | # Write all of the extracted resources to the destination directory. | |
64 | #NOTE: WE WRITE EVERYTHING AS-IF IT'S BINARY. THE EXTRACT FIG |
|
64 | # NOTE: WE WRITE EVERYTHING AS-IF IT'S BINARY. THE EXTRACT FIG | |
65 | #TRANSFORMER SHOULD HANDLE UNIX/WINDOWS LINE ENDINGS... |
|
65 | # TRANSFORMER SHOULD HANDLE UNIX/WINDOWS LINE ENDINGS... | |
66 |
for filename, data in resources.get(' |
|
66 | for filename, data in resources.get('outputs', {}).items(): | |
67 |
|
67 | |||
68 | #Determine where to write the file to |
|
68 | # Determine where to write the file to | |
69 | dest = os.path.join(self.build_directory, filename) |
|
69 | dest = os.path.join(self.build_directory, filename) | |
|
70 | path = os.path.dirname(dest) | |||
|
71 | if not os.path.isdir(path): | |||
|
72 | os.makedirs(path) | |||
70 |
|
73 | |||
71 | #Write file |
|
74 | # Write file | |
72 | with io.open(dest, 'wb') as f: |
|
75 | with io.open(dest, 'wb') as f: | |
73 | f.write(data) |
|
76 | f.write(data) | |
74 |
|
77 | |||
75 | #Copy referenced files to output directory |
|
78 | # Copy referenced files to output directory | |
76 | if self.build_directory: |
|
79 | if self.build_directory: | |
77 | for filename in self.files: |
|
80 | for filename in self.files: | |
78 |
|
81 | |||
79 | #Copy files that match search pattern |
|
82 | # Copy files that match search pattern | |
80 | for matching_filename in glob.glob(filename): |
|
83 | for matching_filename in glob.glob(filename): | |
81 |
|
84 | |||
82 | #Make sure folder exists. |
|
85 | # Make sure folder exists. | |
83 | dest = os.path.join(self.build_directory, filename) |
|
86 | dest = os.path.join(self.build_directory, filename) | |
84 | path = os.path.dirname(dest) |
|
87 | path = os.path.dirname(dest) | |
85 | if not os.path.isdir(path): |
|
88 | if not os.path.isdir(path): | |
86 | os.makedirs(path) |
|
89 | os.makedirs(path) | |
87 |
|
90 | |||
88 | #Copy |
|
91 | # Copy if destination is different. | |
89 |
s |
|
92 | if not os.path.normpath(dest) == os.path.normpath(matching_filename): | |
|
93 | shutil.copyfile(matching_filename, dest) | |||
90 |
|
94 | |||
91 | #Determine where to write conversion results. |
|
95 | # Determine where to write conversion results. | |
92 | dest = notebook_name + '.' + output_extension |
|
96 | dest = notebook_name + '.' + output_extension | |
93 | if self.build_directory: |
|
97 | if self.build_directory: | |
94 | dest = os.path.join(self.build_directory, dest) |
|
98 | dest = os.path.join(self.build_directory, dest) | |
95 |
|
99 | |||
96 | #Write conversion results. |
|
100 | # Write conversion results. | |
97 | with io.open(dest, 'w') as f: |
|
101 | with io.open(dest, 'w') as f: | |
98 | f.write(output) |
|
102 | f.write(output) |
@@ -22,9 +22,7 b' from .base import WriterBase' | |||||
22 |
|
22 | |||
23 | class StdoutWriter(WriterBase): |
|
23 | class StdoutWriter(WriterBase): | |
24 | """Consumes output from nbconvert export...() methods and writes to the |
|
24 | """Consumes output from nbconvert export...() methods and writes to the | |
25 | stdout stream. Allows for quick debuging of nbconvert output. Using the |
|
25 | stdout stream.""" | |
26 | debug flag makes the writer pretty-print the figures contained within the |
|
|||
27 | notebook.""" |
|
|||
28 |
|
26 | |||
29 |
|
27 | |||
30 | def write(self, output, resources, **kw): |
|
28 | def write(self, output, resources, **kw): |
General Comments 0
You need to be logged in to leave comments.
Login now