##// END OF EJS Templates
use configuration file to do nice stuff
use configuration file to do nice stuff

File last commit:

r9234:77ba8646
r9234:77ba8646
Show More
runme.py
94 lines | 2.8 KiB | text/x-python | PythonLexer
Matthias BUSSONNIER
basic test for converter template
r9011 #!/usr/bin/env python
Matthias BUSSONNIER
rename runme2 to runme
r9215 #-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
Matthias BUSSONNIER
fix utf8
r9014 from __future__ import print_function
Matthias BUSSONNIER
null template
r8997 import sys
Matthias BUSSONNIER
handle unicode output
r9003 import io
Matthias BUSSONNIER
use configuration file to do nice stuff
r9234 import os
Matthias BUSSONNIER
rename runme2 to runme
r9215
Matthias BUSSONNIER
starting templates
r8994 from converters.template import *
Matthias BUSSONNIER
rename runme2 to runme
r9215 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
Matthias BUSSONNIER
use configuration file to do nice stuff
r9234 from IPython.config.loader import ConfigFileNotFound
Matthias BUSSONNIER
rename runme2 to runme
r9215 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
Matthias BUSSONNIER
use configuration file to do nice stuff
r9234 def load_config_file(self, profile_name):
try:
Application.load_config_file(
self,
profile_name+'.nbcv',
path=[os.path.join(os.getcwdu(),'profile')]
)
except ConfigFileNotFound:
self.log.warn("Config file for profile '%s' not found, giving up ",profile_name)
exit(1)
Matthias BUSSONNIER
rename runme2 to runme
r9215
def initialize(self, argv=None):
self.parse_command_line(argv)
cl_config = self.config
Matthias BUSSONNIER
use configuration file to do nice stuff
r9234 profile_file = sys.argv[1]
self.load_config_file(profile_file)
Matthias BUSSONNIER
rename runme2 to runme
r9215 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
multiple env
r9212
Matthias BUSSONNIER
rename runme2 to runme
r9215 if template_file.startswith('latex'):
tex_environement=True
else:
tex_environement=False
Matthias BUSSONNIER
lots of modification for latex
r9214
Matthias BUSSONNIER
flag for extracting figure
r9229 C = ConverterTemplate(tplfile=sys.argv[1],
config=self.config)
Matthias BUSSONNIER
rename runme2 to runme
r9215 C.read(ipynb_file)
Matthias BUSSONNIER
multiple env
r9212
Matthias BUSSONNIER
flag for extracting figure
r9229 output,resources = C.convert()
Matthias BUSSONNIER
multiple env
r9212
Matthias BUSSONNIER
rename runme2 to runme
r9215 print(output.encode('utf-8'))
Matthias BUSSONNIER
null template
r8997
Matthias BUSSONNIER
flag for extracting figure
r9229 keys = resources.keys()
if keys :
print('''
====================== Keys in Resources ==================================
''')
print(resources.keys())
print("""
===========================================================================
you are responsible from writing those data do a file in the right place if
they need to be.
===========================================================================
""")
Matthias BUSSONNIER
rename runme2 to runme
r9215 def main():
"""Convert a notebook to html in one step"""
app = NbconvertApp.instance()
app.initialize()
app.start()
app.run()
#-----------------------------------------------------------------------------
# Script main
#-----------------------------------------------------------------------------
Matthias BUSSONNIER
Start to think on api...
r9182
Matthias BUSSONNIER
rename runme2 to runme
r9215 if __name__ == '__main__':
main()