|
24 | 24 |
|
25 | 25 | #From IPython |
26 | 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 | 30 | from .exporters.exporter import Exporter |
31 | 31 | from .transformers import extractfigure |
32 | 32 | from .utils.config import GlobalConfigurable |
|
39 | 39 | KEYS_PROMPT_HEAD = "====================== Keys in Resources ==================================" |
40 | 40 | KEYS_PROMPT_BODY = """ |
41 | 41 | =========================================================================== |
42 | | -You are responsible for writting these files into the appropriate |
43 | | -directorie(s) if need be. If you do not want to see this message, enable |
| 42 | +You are responsible for writing these files into the appropriate |
| 43 | +directory(ies) if need be. If you do not want to see this message, enable |
44 | 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 | 56 | #Classes and functions |
50 | 57 | #----------------------------------------------------------------------------- |
51 | 58 |
|
52 | 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 | 72 | stdout = Bool( |
56 | 73 | False, config=True, |
@@ -118,10 +135,15 @@ def start(self, argv=None): |
118 | 135 | ipynb_file = (self.extra_args)[2] |
119 | 136 |
|
120 | 137 | #Export |
121 | | - return_value = export_by_name(export_type, ipynb_file) |
122 | | - if return_value is None: |
123 | | - print("Error: '%s' template not found." % export_type) |
124 | | - return |
| 138 | + try: |
| 139 | + return_value = export_by_name(export_type, ipynb_file) |
| 140 | + except NameError as e: |
| 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 | 147 | else: |
126 | 148 | (output, resources, exporter) = return_value |
127 | 149 |
|
|
0 commit comments