release-request-e04bb055-13fc-41a1-8a9f-7fb10894ec3d-for-git_oc-mr1-release-4189380 snap-temp-L90600000083186678
Change-Id: Ibca6130baed5bec5dfb345bc0e1793f27237586b
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)
+
+