aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fernandes <joelaf@google.com>2017-07-17 13:00:23 -0700
committerJoel Fernandes <joelaf@google.com>2017-07-17 13:02:01 -0700
commit5bbafd33a4e06105ef4d736b5c14745ccd64182f (patch)
tree353565993ffd031d7fde6cc0f0f6aa9237d3ac57
parentbcfbcb536b1b05260a45064c5efd17532e5a2bf9 (diff)
downloadlisa-oreo-mr1-dev.tar.gz
scripts: add a script for generating notebooksoreo-mr1-dev
I put together a simple utility script some time back to generate an ipython notebook from a python file. Then one could run the following to generate an HTML file: ipython nbconvert --to html temp_notebook.ipynb The idea I had was to run analysis scripts that need graphical output as a 'notebook' and generate an HTML, but optionally not run it and generate output on the command line (standard output) if the analysis script chooses to (for example some (most) analysis scripts are simple enough for command line output). Change-Id: Ia057be958157d156409ffdc3d93e6364bd98b1ca Signed-off-by: Joel Fernandes <joelaf@google.com>
-rwxr-xr-xtools/scripts/py2ipynb.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tools/scripts/py2ipynb.py b/tools/scripts/py2ipynb.py
new file mode 100755
index 0000000..2496c29
--- /dev/null
+++ b/tools/scripts/py2ipynb.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+
+import argparse
+from IPython.nbformat import v3, v4
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser()
+ parser.add_argument("input", help="input python file")
+ parser.add_argument("output", help="output notebook file")
+ args = parser.parse_args()
+
+with open(args.input) as fpin:
+ text = fpin.read()
+
+nbook = v3.reads_py(text)
+nbook = v4.upgrade(nbook) # Upgrade v3 to v4
+
+jsonform = v4.writes(nbook) + "\n"
+with open(args.output, "w") as fpout:
+ fpout.write(jsonform)
+
+