From 62d61cbbc0f81f2979fd440da04e29d2d8155bad Mon Sep 17 00:00:00 2001 From: MinRK Date: Tue, 9 Apr 2013 15:43:59 -0700 Subject: [PATCH] add notebook checkpoint handler --- IPython/frontend/html/notebook/handlers.py | 40 +++++++++++++++++++ IPython/frontend/html/notebook/notebookapp.py | 4 +- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/IPython/frontend/html/notebook/handlers.py b/IPython/frontend/html/notebook/handlers.py index d6dcd0f12..5d76b7459 100644 --- a/IPython/frontend/html/notebook/handlers.py +++ b/IPython/frontend/html/notebook/handlers.py @@ -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): diff --git a/IPython/frontend/html/notebook/notebookapp.py b/IPython/frontend/html/notebook/notebookapp.py index 01206cf77..536e480ab 100644 --- a/IPython/frontend/html/notebook/notebookapp.py +++ b/IPython/frontend/html/notebook/notebookapp.py @@ -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),