##// END OF EJS Templates
Move extracted files into their own subdir
Jonathan Frederic -
Show More
@@ -188,6 +188,7 b' class NbConvertApp(BaseIPythonApplication):'
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:
@@ -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
@@ -50,8 +51,10 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 figures key exists
59 #Make sure figures key exists
57 if not 'figures' in resources:
60 if not 'figures' in resources:
@@ -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 figure_name = self.figure_filename_template.format(
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['figures']['filename'] = data
98 # resources['figures']['filename'] = data
94 resources['figures'][figure_name] = data
99 resources['figures'][filename] = data
95
100
96 return cell, resources
101 return cell, resources
General Comments 0
You need to be logged in to leave comments. Login now