add ModifyCheckpoints handler

separates requests that change specified checkpoint IDs from those that do not.
pull/37/head
MinRK 13 years ago
parent 62d61cbbc0
commit dd234bbc93

@ -679,41 +679,44 @@ class NotebookHandler(IPythonHandler):
self.set_status(204)
self.finish()
class NotebookCheckpointHandler(AuthenticatedHandler):
SUPPORTED_METHODS = ('GET', 'POST', 'PUT', 'DELETE')
class NotebookCheckpointsHandler(AuthenticatedHandler):
SUPPORTED_METHODS = ('GET', 'POST')
@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)
data = jsonapi.dumps(checkpoints, default=date_default)
self.finish(data)
@web.authenticated
def post(self, notebook_id):
"""post creates a new checkpoint"""
nbm = self.application.notebook_manager
checkpoint = nbm.create_checkpoint(notebook_id)
data = jsonapi.dumps(checkpoint, default=date_default)
self.finish(data)
class ModifyNotebookCheckpointsHandler(AuthenticatedHandler):
SUPPORTED_METHODS = ('POST', 'DELETE')
@web.authenticated
def post(self, notebook_id, checkpoint_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):
def delete(self, notebook_id, checkpoint_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()

@ -68,9 +68,9 @@ from .handlers import (LoginHandler, LogoutHandler,
ProjectDashboardHandler, NewHandler, NamedNotebookHandler,
MainKernelHandler, KernelHandler, KernelActionHandler, IOPubHandler, StdinHandler,
ShellHandler, NotebookRootHandler, NotebookHandler, NotebookCopyHandler,
AuthenticatedFileHandler, MainClusterHandler, ClusterProfileHandler,
ClusterActionHandler, FileFindHandler,
NotebookRedirectHandler, NotebookCheckpointHandler,
NotebookRedirectHandler, NotebookCheckpointsHandler, ModifyNotebookCheckpointsHandler,
AuthenticatedFileHandler, FileFindHandler,
MainClusterHandler, ClusterProfileHandler, ClusterActionHandler,
)
from .nbmanager import NotebookManager
from .filenbmanager import FileNotebookManager
@ -105,6 +105,7 @@ _kernel_id_regex = r"(?P<kernel_id>\w+-\w+-\w+-\w+-\w+)"
_kernel_action_regex = r"(?P<action>restart|interrupt)"
_notebook_id_regex = r"(?P<notebook_id>\w+-\w+-\w+-\w+-\w+)"
_notebook_name_regex = r"(?P<notebook_name>.+\.ipynb)"
_checkpoint_id_regex = r"(?P<checkpoint_id>[\w-]+)"
_profile_regex = r"(?P<profile>[^\/]+)" # there is almost no text that is invalid
_cluster_action_regex = r"(?P<action>start|stop)"
@ -162,7 +163,10 @@ 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"/notebooks/%s/checkpoints" % _notebook_id_regex, NotebookCheckpointsHandler),
(r"/notebooks/%s/checkpoints/%s" % (_notebook_id_regex, _checkpoint_id_regex),
ModifyNotebookCheckpointsHandler
),
(r"/files/(.*)", AuthenticatedFileHandler, {'path' : notebook_manager.notebook_dir}),
(r"/clusters", MainClusterHandler),
(r"/clusters/%s/%s" % (_profile_regex, _cluster_action_regex), ClusterActionHandler),

Loading…
Cancel
Save