1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-06-18 06:16:05 +01:00

ipynb_exporter: learn to convert the notebook to HTML

This commit is contained in:
Javi Merino
2015-07-09 11:44:40 +01:00
parent 539c3de7b8
commit 30d7ee52f4
2 changed files with 38 additions and 11 deletions
wlauto
result_processors
ipynb_exporter
utils

@ -46,6 +46,7 @@ if IPython:
NotebookNode = IPython.nbformat.NotebookNode # pylint: disable=E1101
IPYTHON_NBCONVERT_HTML = ['ipython', 'nbconvert', '--to=html']
IPYTHON_NBCONVERT_PDF = ['ipython', 'nbconvert', '--to=pdf']
elif StrictVersion(IPython.__version__) >= StrictVersion('2.0.0'):
import IPython.kernel
@ -59,6 +60,7 @@ if IPython:
NotebookNode = IPython.nbformat.v3.NotebookNode # pylint: disable=E1101
IPYTHON_NBCONVERT_HTML = ['ipython', 'nbconvert', '--to=html']
IPYTHON_NBCONVERT_PDF = ['ipython', 'nbconvert', '--to=latex',
'--post=PDF']
else:
@ -143,19 +145,28 @@ def run_notebook(notebook):
kernel_manager.shutdown_kernel()
def generate_pdf(nbbasename, output_directory):
"""Generate a PDF from the ipython notebook
def export_notebook(nbbasename, output_directory, output_format):
"""Generate a PDF or HTML from the ipython notebook
output_format has to be either 'pdf' or 'html'. These are the
only formats currently supported.
ipython nbconvert claims that the CLI is not stable, so keep this
function here to be able to cope with inconsistencies
"""
if output_format == "html":
ipython_command = IPYTHON_NBCONVERT_HTML
elif output_format == "pdf":
ipython_command = IPYTHON_NBCONVERT_PDF
else:
raise ValueError("Unknown output format: {}".format(output_format))
prev_dir = os.getcwd()
os.chdir(output_directory)
with open(os.devnull, 'w') as devnull:
subprocess.check_call(IPYTHON_NBCONVERT_PDF + [nbbasename], stderr=devnull)
subprocess.check_call(ipython_command + [nbbasename], stderr=devnull)
os.chdir(prev_dir)