##// END OF EJS Templates
add stdout flag and description in help
Matthias BUSSONNIER -
Show More
@@ -1,7 +1,8 b''
1 c = get_config()
1 c = get_config()
2
2
3 c.ConverterTemplate.extract_figures=True
3 c.ConverterTemplate.extract_figures=True
4 c.ConverterTemplate.template_file='latex_base'
4 c.ConverterTemplate.template_file='latex_base'
5 c.ConverterTemplate.tex_environement=True
5 c.ConverterTemplate.tex_environement=True
6
6
7 c.ExtractFigureTransformer.extra_ext_map={'svg':'pdf'}
7 c.ExtractFigureTransformer.extra_ext_map={'svg':'pdf'}
8 c.ExtractFigureTransformer.enabled=True
@@ -1,94 +1,133 b''
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 """
3 ================================================================================
4
5 |,---. | | , .| |
6 ||---', .|--- |---.,---.,---. |\ ||---.,---.,---.,---.. ,,---.,---.|---
7 || | || | || || | | \ || || | || | \ / |---'| |
8 `` `---|`---'` '`---'` ' ` `'`---'`---'`---'` ' `' `---'` `---'
9 `---'
10 ================================================================================
11
12 Highly experimental for now
13
14 """
2 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
3 # Imports
16 # Imports
4 #-----------------------------------------------------------------------------
17 #-----------------------------------------------------------------------------
5 from __future__ import print_function
18 from __future__ import print_function
6 import sys
19 import sys
7 import io
20 import io
8 import os
21 import os
9
22
10 from converters.template import *
23 from converters.template import *
11 from converters.template import ConverterTemplate
24 from converters.template import ConverterTemplate
12 from converters.html import ConverterHTML
25 from converters.html import ConverterHTML
13 # From IPython
26 # From IPython
14
27
15 # All the stuff needed for the configurable things
28 # All the stuff needed for the configurable things
16 from IPython.config.application import Application
29 from IPython.config.application import Application
17 from IPython.config.loader import ConfigFileNotFound
30 from IPython.config.loader import ConfigFileNotFound
18 from IPython.utils.traitlets import List, Unicode, Type, Bool, Dict, CaselessStrEnum
31 from IPython.utils.traitlets import List, Unicode, Type, Bool, Dict, CaselessStrEnum
19
32
20 from converters.transformers import (ConfigurableTransformers,Foobar,ExtractFigureTransformer)
33 from converters.transformers import (ConfigurableTransformers,Foobar,ExtractFigureTransformer)
21
34
22
35
23 class NbconvertApp(Application):
36 class NbconvertApp(Application):
24
37
38 stdout = Bool(True, config=True)
39 write = Bool(False, config=True)
40
41 aliases = {
42 'stdout':'NbconvertApp.stdout',
43 'write':'NbconvertApp.write',
44 }
45
46 flags= {}
47 flags['no-stdout'] = (
48 {'NbconvertApp' : {'stdout' : False}},
49 """the doc for this flag
50
51 """
52 )
25
53
26 def __init__(self, **kwargs):
54 def __init__(self, **kwargs):
27 super(NbconvertApp, self).__init__(**kwargs)
55 super(NbconvertApp, self).__init__(**kwargs)
28 self.classes.insert(0,ConverterTemplate)
56 self.classes.insert(0,ConverterTemplate)
29 # register class here to have help with help all
57 # register class here to have help with help all
30 self.classes.insert(0,ExtractFigureTransformer)
58 self.classes.insert(0,ExtractFigureTransformer)
31 self.classes.insert(0,Foobar)
59 self.classes.insert(0,Foobar)
32 # ensure those are registerd
60 # ensure those are registerd
33
61
34 def load_config_file(self, profile_name):
62 def load_config_file(self, profile_name):
35 try:
63 try:
36 Application.load_config_file(
64 Application.load_config_file(
37 self,
65 self,
38 profile_name+'.nbcv',
66 profile_name+'.nbcv',
39 path=[os.path.join(os.getcwdu(),'profile')]
67 path=[os.path.join(os.getcwdu(),'profile')]
40 )
68 )
41 except ConfigFileNotFound:
69 except ConfigFileNotFound:
42 self.log.warn("Config file for profile '%s' not found, giving up ",profile_name)
70 self.log.warn("Config file for profile '%s' not found, giving up ",profile_name)
43 exit(1)
71 exit(1)
44
72
45
73
46 def initialize(self, argv=None):
74 def initialize(self, argv=None):
47 self.parse_command_line(argv)
75 self.parse_command_line(argv)
48 cl_config = self.config
76 cl_config = self.config
49 profile_file = sys.argv[1]
77 profile_file = sys.argv[1]
50 self.load_config_file(profile_file)
78 self.load_config_file(profile_file)
51 self.update_config(cl_config)
79 self.update_config(cl_config)
52
80
53
81
54
82
55 def run(self):
83 def run(self):
56 """Convert a notebook to html in one step"""
84 """Convert a notebook to html in one step"""
57 template_file = (self.extra_args or [None])[0]
85 template_file = (self.extra_args or [None])[0]
58 ipynb_file = (self.extra_args or [None])[1]
86 ipynb_file = (self.extra_args or [None])[1]
59
87
60 template_file = sys.argv[1]
88 template_file = sys.argv[1]
61
89
62 C = ConverterTemplate(tplfile=sys.argv[1],
90 C = ConverterTemplate(tplfile=sys.argv[1],
63 config=self.config)
91 config=self.config)
64 C.read(ipynb_file)
92 C.read(ipynb_file)
65
93
66 output,resources = C.convert()
94 output,resources = C.convert()
67
95 if self.stdout :
68 print(output.encode('utf-8'))
96 print(output.encode('utf-8'))
69
97
98 out_root = ipynb_file[:-6].replace('.','_')
99
70 keys = resources.keys()
100 keys = resources.keys()
71 if keys :
101 if keys :
102 if self.write :
103 os.mkdir(out_root)
104 for key in keys:
105 if self.write:
106 with io.open(os.path.join(out_root+key),'w') as f:
107 print(' writing to ',os.path.join(out_root+key))
108 f.write(resources[key])
109 if self.stdout:
72 print('''
110 print('''
73 ====================== Keys in Resources ==================================
111 ====================== Keys in Resources ==================================
74 ''')
112 ''')
75 print(resources.keys())
113 print(resources.keys())
76 print("""
114 print("""
77 ===========================================================================
115 ===========================================================================
78 you are responsible from writing those data do a file in the right place if
116 you are responsible from writing those data do a file in the right place if
79 they need to be.
117 they need to be.
80 ===========================================================================
118 ===========================================================================
81 """)
119 """)
82
120
83 def main():
121 def main():
84 """Convert a notebook to html in one step"""
122 """Convert a notebook to html in one step"""
85 app = NbconvertApp.instance()
123 app = NbconvertApp.instance()
124 app.description = __doc__
86 app.initialize()
125 app.initialize()
87 app.start()
126 app.start()
88 app.run()
127 app.run()
89 #-----------------------------------------------------------------------------
128 #-----------------------------------------------------------------------------
90 # Script main
129 # Script main
91 #-----------------------------------------------------------------------------
130 #-----------------------------------------------------------------------------
92
131
93 if __name__ == '__main__':
132 if __name__ == '__main__':
94 main()
133 main()
General Comments 0
You need to be logged in to leave comments. Login now