Uncommentable section in Dockerfile to autosave .py and .html alongside .ipynb

This commit is contained in:
ziembla
2017-12-11 16:19:24 +01:00
parent 1d370f4001
commit 60bb0e4e50
3 changed files with 25 additions and 3 deletions

View File

@@ -0,0 +1,15 @@
import os
import subprocess
def export_script_and_view(model, os_path, contents_manager):
if model["type"] != "notebook":
return
dir_name, file_name = os.path.split(os_path)
file_base, file_ext = os.path.splitext(file_name)
if file_base.startswith("Untitled"):
return
export_name = file_base if file_ext == ".ipynb" else file_name
subprocess.check_call(["jupyter", "nbconvert", "--to", "script", file_name, "--output", export_name + "_script"], cwd=dir_name)
subprocess.check_call(["jupyter", "nbconvert", "--to", "html", file_name, "--output", export_name + "_view"], cwd=dir_name)
c.FileContentsManager.post_save_hook = export_script_and_view