##// END OF EJS Templates
Merge pull request #3583 from ivanov/nb-small-things...
Jonathan Frederic -
r11292:d99b6cf7 merge
parent child Browse files
Show More
@@ -84,7 +84,8 __all__ = [
84 'export_python',
84 'export_python',
85 'export_reveal',
85 'export_reveal',
86 'export_rst',
86 'export_rst',
87 'export_by_name'
87 'export_by_name',
88 'get_export_names'
88 ]
89 ]
89
90
90 @DocDecorator
91 @DocDecorator
@@ -211,5 +212,12 def export_by_name(template_name, nb, config=None, transformers=None, filters=No
211 if function_name in globals():
212 if function_name in globals():
212 return globals()[function_name](nb, config, transformers, filters)
213 return globals()[function_name](nb, config, transformers, filters)
213 else:
214 else:
214 raise NameError("template not found")
215 raise NameError("template for `%s` not found" % function_name)
215
216
217 def get_export_names():
218 "Return a list of the currently supported export targets"
219 # grab everything after 'export_'
220 l = [x[len('export_'):] for x in __all__ if x.startswith('export_')]
221 # filter out the one method that is not a template
222 l = [x for x in l if 'by_name' not in x]
223 return sorted(l)
@@ -24,9 +24,9 import os
24
24
25 #From IPython
25 #From IPython
26 from IPython.config.application import Application
26 from IPython.config.application import Application
27 from IPython.utils.traitlets import Bool
27 from IPython.utils.traitlets import Bool, Unicode
28
28
29 from .exporters.export import export_by_name
29 from .exporters.export import export_by_name, get_export_names
30 from .exporters.exporter import Exporter
30 from .exporters.exporter import Exporter
31 from .transformers import extractfigure
31 from .transformers import extractfigure
32 from .utils.config import GlobalConfigurable
32 from .utils.config import GlobalConfigurable
@@ -39,18 +39,35 from .utils.config import GlobalConfigurable
39 KEYS_PROMPT_HEAD = "====================== Keys in Resources =================================="
39 KEYS_PROMPT_HEAD = "====================== Keys in Resources =================================="
40 KEYS_PROMPT_BODY = """
40 KEYS_PROMPT_BODY = """
41 ===========================================================================
41 ===========================================================================
42 You are responsible for writting these files into the appropriate
42 You are responsible for writing these files into the appropriate
43 directorie(s) if need be. If you do not want to see this message, enable
43 directory(ies) if need be. If you do not want to see this message, enable
44 the 'write' (boolean) flag of the converter.
44 the 'write' (boolean) flag of the converter.
45 ===========================================================================
45 ===========================================================================
46 """
46 """
47
47
48 _examples = """
49 ipython nbconvert rst Untitled0.ipynb # convert ipynb to ReStructured Text
50 ipython nbconvert latex Untitled0.ipynb # convert ipynb to LaTeX
51 ipython nbconvert reveal Untitled0.ipynb # convert to Reveal (HTML/JS) slideshow
52 """
53
54
48 #-----------------------------------------------------------------------------
55 #-----------------------------------------------------------------------------
49 #Classes and functions
56 #Classes and functions
50 #-----------------------------------------------------------------------------
57 #-----------------------------------------------------------------------------
51
58
52 class NbConvertApp(Application):
59 class NbConvertApp(Application):
53 """Application used to convert to and from notebook file type (*.ipynb)"""
60 __doc__ = """IPython notebook conversion utility
61
62 Convert to and from notebook file type (*.ipynb)
63
64 ipython nbconvert TARGET FILENAME
65
66 Supported export TARGETs are: %s
67 """ % (" ".join(get_export_names()))
68 description = Unicode(__doc__)
69
70 examples = _examples
54
71
55 stdout = Bool(
72 stdout = Bool(
56 False, config=True,
73 False, config=True,
@@ -118,10 +135,15 class NbConvertApp(Application):
118 ipynb_file = (self.extra_args)[2]
135 ipynb_file = (self.extra_args)[2]
119
136
120 #Export
137 #Export
121 return_value = export_by_name(export_type, ipynb_file)
138 try:
122 if return_value is None:
139 return_value = export_by_name(export_type, ipynb_file)
123 print("Error: '%s' template not found." % export_type)
140 except NameError as e:
124 return
141 print("Error: '%s' exporter not found." % export_type,
142 file=sys.stderr)
143 print("Known exporters are:",
144 "\n\t" + "\n\t".join(get_export_names()),
145 file=sys.stderr)
146 sys.exit(-1)
125 else:
147 else:
126 (output, resources, exporter) = return_value
148 (output, resources, exporter) = return_value
127
149
General Comments 0
You need to be logged in to leave comments. Login now