runme.py
65 lines
| 1.8 KiB
| text/x-python
|
PythonLexer
Matthias BUSSONNIER
|
r9586 | #!/usr/bin/env python | ||
Matthias BUSSONNIER
|
r9612 | #----------------------------------------------------------------------------- | ||
# Imports | ||||
#----------------------------------------------------------------------------- | ||||
Matthias BUSSONNIER
|
r9589 | from __future__ import print_function | ||
Matthias BUSSONNIER
|
r9580 | import sys | ||
Matthias BUSSONNIER
|
r9581 | import io | ||
Matthias BUSSONNIER
|
r9612 | |||
Matthias BUSSONNIER
|
r9578 | from converters.template import * | ||
Matthias BUSSONNIER
|
r9612 | from converters.template import ConverterTemplate | ||
from converters.html import ConverterHTML | ||||
# From IPython | ||||
# All the stuff needed for the configurable things | ||||
from IPython.config.application import Application | ||||
from IPython.utils.traitlets import List, Unicode, Type, Bool, Dict, CaselessStrEnum | ||||
class NbconvertApp(Application): | ||||
def __init__(self, **kwargs): | ||||
super(NbconvertApp, self).__init__(**kwargs) | ||||
self.classes.insert(0,ConverterTemplate) | ||||
# ensure those are registerd | ||||
def initialize(self, argv=None): | ||||
self.parse_command_line(argv) | ||||
cl_config = self.config | ||||
self.update_config(cl_config) | ||||
def run(self): | ||||
"""Convert a notebook to html in one step""" | ||||
template_file = (self.extra_args or [None])[0] | ||||
ipynb_file = (self.extra_args or [None])[1] | ||||
template_file = sys.argv[1] | ||||
Matthias BUSSONNIER
|
r9609 | |||
Matthias BUSSONNIER
|
r9612 | if template_file.startswith('latex'): | ||
tex_environement=True | ||||
else: | ||||
tex_environement=False | ||||
Matthias BUSSONNIER
|
r9611 | |||
Matthias BUSSONNIER
|
r9612 | C = ConverterTemplate(tplfile=sys.argv[1], tex_environement=tex_environement, config=self.config) | ||
C.read(ipynb_file) | ||||
Matthias BUSSONNIER
|
r9609 | |||
Matthias BUSSONNIER
|
r9612 | output,rest = C.convert() | ||
Matthias BUSSONNIER
|
r9609 | |||
Matthias BUSSONNIER
|
r9612 | print(output.encode('utf-8')) | ||
Matthias BUSSONNIER
|
r9580 | |||
Matthias BUSSONNIER
|
r9612 | def main(): | ||
"""Convert a notebook to html in one step""" | ||||
app = NbconvertApp.instance() | ||||
app.initialize() | ||||
app.start() | ||||
app.run() | ||||
#----------------------------------------------------------------------------- | ||||
# Script main | ||||
#----------------------------------------------------------------------------- | ||||
Matthias BUSSONNIER
|
r9601 | |||
Matthias BUSSONNIER
|
r9612 | if __name__ == '__main__': | ||
main() | ||||