add notebook checkpoint handler

pull/37/head
MinRK 13 years ago
parent c4ac8eee36
commit 62d61cbbc0

@ -679,6 +679,46 @@ class NotebookHandler(IPythonHandler):
self.set_status(204)
self.finish()
class NotebookCheckpointHandler(AuthenticatedHandler):
SUPPORTED_METHODS = ('GET', 'POST', 'PUT', 'DELETE')
@web.authenticated
def get(self, notebook_id):
"""get lists checkpoints for a notebook"""
nbm = self.application.notebook_manager
checkpoints = nbm.list_checkpoints(notebook_id)
self.finish(checkpoints)
@web.authenticated
def post(self, notebook_id):
"""post restores a notebook from a checkpoint"""
nbm = self.application.notebook_manager
checkpoint_id = self.get_argument('checkpoint', None)
nbm.restore_checkpoint(notebook_id, checkpoint_id)
self.set_status(204)
self.finish()
@web.authenticated
def put(self, notebook_id):
"""put saves the notebook, and creates a new checkpoint"""
nbm = self.application.notebook_manager
format = self.get_argument('format', default='json')
name = self.get_argument('name', default=None)
nbm.save_notebook(notebook_id, self.request.body, name=name, format=format)
checkpoint = nbm.create_checkpoint(notebook_id)
self.finish(checkpoint)
@web.authenticated
def delete(self, notebook_id):
"""delete clears a checkpoint for a given notebook"""
nbm = self.application.notebook_manager
checkpoint_id = self.get_argument('checkpoint', None)
nbm.delte_checkpoint(notebook_id, checkpoint_id)
self.set_status(204)
self.finish()
class NotebookCopyHandler(IPythonHandler):

@ -69,7 +69,8 @@ from .handlers import (LoginHandler, LogoutHandler,
MainKernelHandler, KernelHandler, KernelActionHandler, IOPubHandler, StdinHandler,
ShellHandler, NotebookRootHandler, NotebookHandler, NotebookCopyHandler,
AuthenticatedFileHandler, MainClusterHandler, ClusterProfileHandler,
ClusterActionHandler, FileFindHandler, NotebookRedirectHandler,
ClusterActionHandler, FileFindHandler,
NotebookRedirectHandler, NotebookCheckpointHandler,
)
from .nbmanager import NotebookManager
from .filenbmanager import FileNotebookManager
@ -161,6 +162,7 @@ class NotebookWebApplication(web.Application):
(r"/kernels/%s/stdin" % _kernel_id_regex, StdinHandler),
(r"/notebooks", NotebookRootHandler),
(r"/notebooks/%s" % _notebook_id_regex, NotebookHandler),
(r"/notebooks/%s/checkpoint" % _notebook_id_regex, NotebookCheckpointHandler),
(r"/files/(.*)", AuthenticatedFileHandler, {'path' : notebook_manager.notebook_dir}),
(r"/clusters", MainClusterHandler),
(r"/clusters/%s/%s" % (_profile_regex, _cluster_action_regex), ClusterActionHandler),

Loading…
Cancel
Save