|
|
|
|
@ -38,8 +38,8 @@ class SessionManager(LoggingConfigurable):
|
|
|
|
|
"""Get an existing session or create a new one"""
|
|
|
|
|
model = None
|
|
|
|
|
for session in self.sessions:
|
|
|
|
|
if session['notebook_name'] == nb_name and session['notebook_path'] == nb_path:
|
|
|
|
|
session_id = session['session_id']
|
|
|
|
|
if session['name'] == nb_name and session['path'] == nb_path:
|
|
|
|
|
session_id = session['id']
|
|
|
|
|
model = session
|
|
|
|
|
if model != None:
|
|
|
|
|
return session_id, model
|
|
|
|
|
@ -49,12 +49,12 @@ class SessionManager(LoggingConfigurable):
|
|
|
|
|
|
|
|
|
|
def session_model(self, session_id, notebook_name=None, notebook_path=None, kernel=None):
|
|
|
|
|
""" Create a session that links notebooks with kernels """
|
|
|
|
|
model = dict(session_id=session_id,
|
|
|
|
|
notebook_name=notebook_name,
|
|
|
|
|
notebook_path=notebook_path,
|
|
|
|
|
model = dict(id=session_id,
|
|
|
|
|
name=notebook_name,
|
|
|
|
|
path=notebook_path,
|
|
|
|
|
kernel=kernel)
|
|
|
|
|
if notebook_path == None:
|
|
|
|
|
model['notebook_path']=""
|
|
|
|
|
model['path']=""
|
|
|
|
|
self.sessions.append(model)
|
|
|
|
|
return model
|
|
|
|
|
|
|
|
|
|
@ -65,33 +65,33 @@ class SessionManager(LoggingConfigurable):
|
|
|
|
|
def set_kernel_for_sessions(self, session_id, kernel_id):
|
|
|
|
|
"""Maps the kernel_ids to the session_id in session_mapping"""
|
|
|
|
|
for session in self.sessions:
|
|
|
|
|
if session['session_id'] == session_id:
|
|
|
|
|
session['kernel_id'] = kernel_id
|
|
|
|
|
if session['id'] == session_id:
|
|
|
|
|
session['kernel']['id'] = kernel_id
|
|
|
|
|
return self.sessions
|
|
|
|
|
|
|
|
|
|
def delete_mapping_for_session(self, session_id):
|
|
|
|
|
"""Delete the session from session_mapping with the given session_id"""
|
|
|
|
|
i = 0
|
|
|
|
|
for session in self.sessions:
|
|
|
|
|
if session['session_id'] == session_id:
|
|
|
|
|
if session['id'] == session_id:
|
|
|
|
|
del self.sessions[i]
|
|
|
|
|
i = i + 1
|
|
|
|
|
return self.sessions
|
|
|
|
|
|
|
|
|
|
def get_session_from_id(self, session_id):
|
|
|
|
|
for session in self.sessions:
|
|
|
|
|
if session['session_id'] == session_id:
|
|
|
|
|
if session['id'] == session_id:
|
|
|
|
|
return session
|
|
|
|
|
|
|
|
|
|
def get_notebook_from_session(self, session_id):
|
|
|
|
|
"""Returns the notebook_path for the given session_id"""
|
|
|
|
|
for session in self.sessions:
|
|
|
|
|
if session['session_id'] == session_id:
|
|
|
|
|
return session['notebook_name']
|
|
|
|
|
if session['id'] == session_id:
|
|
|
|
|
return session['name']
|
|
|
|
|
|
|
|
|
|
def get_kernel_from_session(self, session_id):
|
|
|
|
|
"""Returns the kernel_id for the given session_id"""
|
|
|
|
|
for session in self.sessions:
|
|
|
|
|
if session['session_id'] == session_id:
|
|
|
|
|
return session['kernel']['kernel_id']
|
|
|
|
|
if session['id'] == session_id:
|
|
|
|
|
return session['kernel']['id']
|
|
|
|
|
|
|
|
|
|
|