##// END OF EJS Templates
add output flag to nbconvert...
Matthias BUSSONNIER -
Show More
@@ -23,11 +23,13 b' 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.core.error import UsageError
26 from IPython.config import catch_config_error, Configurable
27 from IPython.config import catch_config_error, Configurable
27 from IPython.utils.traitlets import (
28 from IPython.utils.traitlets import (
28 Unicode, List, Instance, DottedObjectName, Type, CaselessStrEnum,
29 Unicode, List, Instance, DottedObjectName, Type, CaselessStrEnum,
29 )
30 )
30 from IPython.utils.importstring import import_item
31 from IPython.utils.importstring import import_item
32 from IPython.utils.text import dedent
31
33
32 from .exporters.export import export_by_name, get_export_names, ExporterNameError
34 from .exporters.export import export_by_name, get_export_names, ExporterNameError
33 from IPython.nbconvert import exporters, transformers, writers, post_processors
35 from IPython.nbconvert import exporters, transformers, writers, post_processors
@@ -58,7 +60,8 b' nbconvert_aliases.update({'
58 'template' : 'Exporter.template_file',
60 'template' : 'Exporter.template_file',
59 'notebooks' : 'NbConvertApp.notebooks',
61 'notebooks' : 'NbConvertApp.notebooks',
60 'writer' : 'NbConvertApp.writer_class',
62 'writer' : 'NbConvertApp.writer_class',
61 'post': 'NbConvertApp.post_processor_class'
63 'post': 'NbConvertApp.post_processor_class',
64 'output': 'NbConvertApp.output_base'
62 })
65 })
63
66
64 nbconvert_flags = {}
67 nbconvert_flags = {}
@@ -93,6 +96,10 b' class NbConvertApp(BaseIPythonApplication):'
93
96
94 WARNING: THE COMMANDLINE INTERFACE MAY CHANGE IN FUTURE RELEASES.""")
97 WARNING: THE COMMANDLINE INTERFACE MAY CHANGE IN FUTURE RELEASES.""")
95
98
99 output_base = Unicode('', config=True, help='''overwrite base name use for output files.
100 can only be use when converting one notebook at a time.
101 ''')
102
96 examples = Unicode(u"""
103 examples = Unicode(u"""
97 The simplest way to use nbconvert is
104 The simplest way to use nbconvert is
98
105
@@ -253,11 +260,21 b' class NbConvertApp(BaseIPythonApplication):'
253 """
260 """
254 # Export each notebook
261 # Export each notebook
255 conversion_success = 0
262 conversion_success = 0
263
264 if self.output_base != '' and len(self.notebooks) > 1:
265 print(dedent(
266 """UsageError: --output flag or `NbConvertApp.output_base` config option
267 cannot be used when converting multiple notebooks.
268 """))
269 self.exit(1)
270
256 for notebook_filename in self.notebooks:
271 for notebook_filename in self.notebooks:
257
272
258 # Get a unique key for the notebook and set it in the resources object.
273 # Get a unique key for the notebook and set it in the resources object.
259 basename = os.path.basename(notebook_filename)
274 basename = os.path.basename(notebook_filename)
260 notebook_name = basename[:basename.rfind('.')]
275 notebook_name = basename[:basename.rfind('.')]
276 if self.output_base:
277 notebook_name = self.output_base
261 resources = {}
278 resources = {}
262 resources['unique_key'] = notebook_name
279 resources['unique_key'] = notebook_name
263 resources['output_files_dir'] = '%s_files' % notebook_name
280 resources['output_files_dir'] = '%s_files' % notebook_name
General Comments 0
You need to be logged in to leave comments. Login now