Path: blob/master/src/smc_pyutil/smc_pyutil/jupyter_notebook.py
Views: 285
#!/usr/bin/python1# -*- coding: utf-8 -*-23import os, sys45def prepare_file_for_open():6# Before opening a file, we run this to make sure there is a blank JSON template in place.7# This is for compatibility with "new jupyter".8# See https://github.com/sagemathinc/cocalc/issues/19789# This may need to be updated periodically, and not doing so can cause10# difficult-to-debug problems. It would be much better if11# Jupyter could handle a blank file... see12# https://github.com/sagemathinc/cocalc/issues/464513for path in sys.argv[1:]:14if not os.path.exists(path) or len(open(path).read().strip()) == 0:15open(path, 'w').write(16'{"cells":[{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":[]}],"metadata":{"kernelspec":{"display_name":"Python 3 (system-wide)","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.6.9"}},"nbformat":4,"nbformat_minor":4}'17)181920