##// END OF EJS Templates
deprecation message in old nbconvert.py
Matthias BUSSONNIER -
Show More
@@ -1,117 +1,123 b''
1 1 #!/usr/bin/env python
2 2 """Convert IPython notebooks to other formats, such as ReST, and HTML.
3 3
4 4 Example:
5 5 ./nbconvert.py --format rst file.ipynb
6 6
7 7 Produces 'file.rst', along with auto-generated figure files
8 8 called nb_figure_NN.png.
9 9 """
10 10 #-----------------------------------------------------------------------------
11 11 # Imports
12 12 #-----------------------------------------------------------------------------
13 13 from __future__ import print_function
14 14
15 15 # From IPython
16 16 from IPython.external import argparse
17 17
18 18 # All the stuff needed for the configurable things
19 19 from IPython.config.application import Application, catch_config_error
20 20 from IPython.config.configurable import Configurable, SingletonConfigurable
21 21 from IPython.config.loader import Config, ConfigFileNotFound
22 22 from IPython.utils.traitlets import List, Unicode, Type, Bool, Dict, CaselessStrEnum
23 23
24 24
25 25 # local
26 26 from converters.html import ConverterHTML
27 27 from converters.markdown import ConverterMarkdown
28 28 from converters.bloggerhtml import ConverterBloggerHTML
29 29 from converters.rst import ConverterRST
30 30 from converters.latex import ConverterLaTeX
31 31 from converters.python import ConverterPy
32 32 from converters.base import Converter
33 33
34 34
35 35 # When adding a new format, make sure to add it to the `converters`
36 36 # dictionary below. This is used to create the list of known formats,
37 37 # which gets printed in case an unknown format is encounteres, as well
38 38 # as in the help
39 39
40 40 converters = {
41 41 'rst': ConverterRST,
42 42 'markdown': ConverterMarkdown,
43 43 'html': ConverterHTML,
44 44 'blogger-html': ConverterBloggerHTML,
45 45 'latex': ConverterLaTeX,
46 46 'py': ConverterPy,
47 47 }
48 48
49 49 default_format = 'rst'
50 50
51 51 # Extract the list of known formats and mark the first format as the default.
52 52 known_formats = ', '.join([key + " (default)" if key == default_format else key
53 53 for key in converters])
54 54
55 55 class NbconvertApp(Application):
56 56
57 57
58 58 fmt = CaselessStrEnum(converters.keys(),
59 59 default_value='rst',
60 60 config=True,
61 61 help="Supported conversion format")
62 62
63 63 exclude = List( [],
64 64 config=True,
65 65 help = 'list of cells to exclude while converting')
66 66
67 67 aliases = {
68 68 'format':'NbconvertApp.fmt',
69 69 'exclude':'NbconvertApp.exclude',
70 70 'highlight':'Converter.highlight_source',
71 71 'preamble':'Converter.preamble',
72 72 }
73 73
74 74 def __init__(self, **kwargs):
75 75 super(NbconvertApp, self).__init__(**kwargs)
76 76 # ensure those are registerd
77 77 self.classes.insert(0,Converter)
78 78 self.classes.insert(0,ConverterRST)
79 79 self.classes.insert(0,ConverterMarkdown)
80 80 self.classes.insert(0,ConverterBloggerHTML)
81 81 self.classes.insert(0,ConverterLaTeX)
82 82 self.classes.insert(0,ConverterPy)
83 83
84 84 def initialize(self, argv=None):
85 85 self.parse_command_line(argv)
86 86 cl_config = self.config
87 87 self.update_config(cl_config)
88 88
89 89 def run(self):
90 90 """Convert a notebook to html in one step"""
91 91 ConverterClass = converters[self.fmt]
92 92 infile = (self.extra_args or [None])[0]
93 93 converter = ConverterClass(infile=infile, config=self.config)
94 94 converter.render()
95 95
96 96 def main():
97 97 """Convert a notebook to html in one step"""
98 98 app = NbconvertApp.instance()
99 99 app.description = __doc__
100 print("""
101 ======================================================
102 Warning, we are deprecating this version of nbconvert,
103 please consider using the new version.
104 ======================================================
105 """)
100 106 app.initialize()
101 107 app.start()
102 108 app.run()
103 109 #-----------------------------------------------------------------------------
104 110 # Script main
105 111 #-----------------------------------------------------------------------------
106 112
107 113 if __name__ == '__main__':
108 114 # TODO: consider passing file like object around, rather than filenames
109 115 # would allow us to process stdin, or even http streams
110 116 #parser.add_argument('infile', nargs='?', type=argparse.FileType('r'),
111 117 # default=sys.stdin)
112 118
113 119 #parser.add_argument('-e', '--exclude', default='',
114 120 # help='Comma-separated list of cells to exclude')
115 121 #exclude_cells = [s.strip() for s in args.exclude.split(',')]
116 122
117 123 main()
General Comments 0
You need to be logged in to leave comments. Login now