Show More
@@ -54,17 +54,36 b' class NbConvertApp(Application):' | |||||
54 | """Application used to convert to and from notebook file type (*.ipynb)""" |
|
54 | """Application used to convert to and from notebook file type (*.ipynb)""" | |
55 |
|
55 | |||
56 | stdout = Bool( |
|
56 | stdout = Bool( | |
57 |
|
|
57 | False, config=True, | |
58 | help="""Whether to print the converted IPYNB file to stdout |
|
58 | help="""Whether to print the converted IPYNB file to stdout | |
59 | use full do diff files without actually writing a new file""" |
|
59 | use full do diff files without actually writing a new file""" | |
60 | ) |
|
60 | ) | |
61 |
|
61 | |||
62 | write = Bool( |
|
62 | write = Bool( | |
63 |
|
|
63 | True, config=True, | |
64 | help="""Should the converted notebook file be written to disk |
|
64 | help="""Should the converted notebook file be written to disk | |
65 | along with potential extracted resources.""" |
|
65 | along with potential extracted resources.""" | |
66 | ) |
|
66 | ) | |
67 |
|
67 | |||
|
68 | aliases = { | |||
|
69 | 'stdout':'NbConvertApp.stdout', | |||
|
70 | 'write':'NbConvertApp.write', | |||
|
71 | } | |||
|
72 | ||||
|
73 | flags = {} | |||
|
74 | ||||
|
75 | flags['stdout'] = ( | |||
|
76 | {'NbConvertApp' : {'stdout' : True}}, | |||
|
77 | """Print converted file to stdout, equivalent to --stdout=True | |||
|
78 | """ | |||
|
79 | ) | |||
|
80 | ||||
|
81 | flags['no-write'] = ( | |||
|
82 | {'NbConvertApp' : {'write' : True}}, | |||
|
83 | """Do not write to disk, eauivalent to --write=False | |||
|
84 | """ | |||
|
85 | ) | |||
|
86 | ||||
68 |
|
87 | |||
69 | def __init__(self, **kwargs): |
|
88 | def __init__(self, **kwargs): | |
70 | """Public constructor""" |
|
89 | """Public constructor""" | |
@@ -121,10 +140,10 b' class NbConvertApp(Application):' | |||||
121 |
|
140 | |||
122 | #Write the results |
|
141 | #Write the results | |
123 | if self.stdout or not (destination_filename is None and destination_directory is None): |
|
142 | if self.stdout or not (destination_filename is None and destination_directory is None): | |
124 |
self._write_results(output, resources, |
|
143 | self._write_results(output, resources, destination_filename, destination_directory) | |
125 |
|
144 | |||
126 |
|
145 | |||
127 |
def _write_results(self, output, resources, |
|
146 | def _write_results(self, output, resources, destination_filename=None, destination_directory=None): | |
128 | """Output the conversion results to the console and/or filesystem |
|
147 | """Output the conversion results to the console and/or filesystem | |
129 |
|
148 | |||
130 | Parameters |
|
149 | Parameters | |
@@ -137,8 +156,6 b' class NbConvertApp(Application):' | |||||
137 | figures it extracts into this dictionary. This method |
|
156 | figures it extracts into this dictionary. This method | |
138 | relies on the figures being in this dictionary when |
|
157 | relies on the figures being in this dictionary when | |
139 | attempting to write the figures to the file system. |
|
158 | attempting to write the figures to the file system. | |
140 | stdout : bool, Optional |
|
|||
141 | Whether or not to echo output to console |
|
|||
142 | destination_filename : str, Optional |
|
159 | destination_filename : str, Optional | |
143 | Filename to write output into. If None, output is not |
|
160 | Filename to write output into. If None, output is not | |
144 | written to a file. |
|
161 | written to a file. | |
@@ -147,7 +164,7 b' class NbConvertApp(Application):' | |||||
147 | None, figures are not written to the file system. |
|
164 | None, figures are not written to the file system. | |
148 | """ |
|
165 | """ | |
149 |
|
166 | |||
150 | if stdout: |
|
167 | if self.stdout: | |
151 | print(output.encode('utf-8')) |
|
168 | print(output.encode('utf-8')) | |
152 |
|
169 | |||
153 | #Write file output from conversion. |
|
170 | #Write file output from conversion. | |
@@ -174,10 +191,10 b' class NbConvertApp(Application):' | |||||
174 |
|
191 | |||
175 | #Figures that weren't exported which will need to be created by the |
|
192 | #Figures that weren't exported which will need to be created by the | |
176 | #user. Tell the user what figures these are. |
|
193 | #user. Tell the user what figures these are. | |
177 | if stdout: |
|
194 | if self.stdout: | |
178 | print(KEYS_PROMPT_HEAD) |
|
195 | print(KEYS_PROMPT_HEAD, file=sys.stderr) | |
179 | print(resources[figures_key].keys()) |
|
196 | print(resources[figures_key].keys(), file=sys.stderr) | |
180 | print(KEYS_PROMPT_BODY) |
|
197 | print(KEYS_PROMPT_BODY , file=sys.stderr) | |
181 |
|
198 | |||
182 | #----------------------------------------------------------------------------- |
|
199 | #----------------------------------------------------------------------------- | |
183 | #Script main |
|
200 | #Script main |
General Comments 0
You need to be logged in to leave comments.
Login now