##// END OF EJS Templates
add output flag to nbconvert...
Matthias BUSSONNIER -
Show More
@@ -23,11 +23,13 b' import glob'
23 23
24 24 # From IPython
25 25 from IPython.core.application import BaseIPythonApplication, base_aliases, base_flags
26 from IPython.core.error import UsageError
26 27 from IPython.config import catch_config_error, Configurable
27 28 from IPython.utils.traitlets import (
28 29 Unicode, List, Instance, DottedObjectName, Type, CaselessStrEnum,
29 30 )
30 31 from IPython.utils.importstring import import_item
32 from IPython.utils.text import dedent
31 33
32 34 from .exporters.export import export_by_name, get_export_names, ExporterNameError
33 35 from IPython.nbconvert import exporters, transformers, writers, post_processors
@@ -58,7 +60,8 b' nbconvert_aliases.update({'
58 60 'template' : 'Exporter.template_file',
59 61 'notebooks' : 'NbConvertApp.notebooks',
60 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 67 nbconvert_flags = {}
@@ -93,6 +96,10 b' class NbConvertApp(BaseIPythonApplication):'
93 96
94 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 103 examples = Unicode(u"""
97 104 The simplest way to use nbconvert is
98 105
@@ -253,11 +260,21 b' class NbConvertApp(BaseIPythonApplication):'
253 260 """
254 261 # Export each notebook
255 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 271 for notebook_filename in self.notebooks:
257 272
258 273 # Get a unique key for the notebook and set it in the resources object.
259 274 basename = os.path.basename(notebook_filename)
260 275 notebook_name = basename[:basename.rfind('.')]
276 if self.output_base:
277 notebook_name = self.output_base
261 278 resources = {}
262 279 resources['unique_key'] = notebook_name
263 280 resources['output_files_dir'] = '%s_files' % notebook_name
General Comments 0
You need to be logged in to leave comments. Login now