Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/smc_pyutil/smc_pyutil/jupyter_notebook.py
Views: 285
1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
4
import os, sys
5
6
def prepare_file_for_open():
7
# Before opening a file, we run this to make sure there is a blank JSON template in place.
8
# This is for compatibility with "new jupyter".
9
# See https://github.com/sagemathinc/cocalc/issues/1978
10
# This may need to be updated periodically, and not doing so can cause
11
# difficult-to-debug problems. It would be much better if
12
# Jupyter could handle a blank file... see
13
# https://github.com/sagemathinc/cocalc/issues/4645
14
for path in sys.argv[1:]:
15
if not os.path.exists(path) or len(open(path).read().strip()) == 0:
16
open(path, 'w').write(
17
'{"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}'
18
)
19
20