Commit 5956f1ae authored by Justin Tyberg's avatar Justin Tyberg

Ensure PEM file directory exists before creating file.

Fixes issue #34
parent 78df4dc0
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
from jupyter_core.paths import jupyter_data_dir from jupyter_core.paths import jupyter_data_dir
import subprocess import subprocess
import os import os
import errno
PEM_FILE = os.path.join(jupyter_data_dir(), 'notebook.pem') PEM_FILE = os.path.join(jupyter_data_dir(), 'notebook.pem')
...@@ -13,6 +14,14 @@ c.NotebookApp.open_browser = False ...@@ -13,6 +14,14 @@ c.NotebookApp.open_browser = False
# Set a certificate if USE_HTTPS is set to any value # Set a certificate if USE_HTTPS is set to any value
if 'USE_HTTPS' in os.environ: if 'USE_HTTPS' in os.environ:
if not os.path.isfile(PEM_FILE): if not os.path.isfile(PEM_FILE):
# Ensure PEM_FILE directory exists
dir_name = os.path.dirname(PEM_FILE)
try:
os.makedirs(dir_name)
except OSError as exc: # Python >2.5
if exc.errno == errno.EEXIST and os.path.isdir(dir_name):
pass
else: raise
# Generate a certificate if one doesn't exist on disk # Generate a certificate if one doesn't exist on disk
subprocess.check_call(['openssl', 'req', '-new', subprocess.check_call(['openssl', 'req', '-new',
'-newkey', 'rsa:2048', '-days', '365', '-nodes', '-x509', '-newkey', 'rsa:2048', '-days', '365', '-nodes', '-x509',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment