Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c8b6955

Browse files
committed
add ModifyCheckpoints handler
separates requests that change specified checkpoint IDs from those that do not.
1 parent b68ea6d commit c8b6955

2 files changed

Lines changed: 27 additions & 20 deletions

File tree

IPython/frontend/html/notebook/handlers.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -679,41 +679,44 @@ def delete(self, notebook_id):
679679
self.set_status(204)
680680
self.finish()
681681

682-
class NotebookCheckpointHandler(AuthenticatedHandler):
683682

684-
SUPPORTED_METHODS = ('GET', 'POST', 'PUT', 'DELETE')
683+
class NotebookCheckpointsHandler(AuthenticatedHandler):
684+
685+
SUPPORTED_METHODS = ('GET', 'POST')
685686

686687
@web.authenticated
687688
def get(self, notebook_id):
688689
"""get lists checkpoints for a notebook"""
689690
nbm = self.application.notebook_manager
690691
checkpoints = nbm.list_checkpoints(notebook_id)
691-
self.finish(checkpoints)
692+
data = jsonapi.dumps(checkpoints, default=date_default)
693+
self.finish(data)
692694

693695
@web.authenticated
694696
def post(self, notebook_id):
697+
"""post creates a new checkpoint"""
698+
nbm = self.application.notebook_manager
699+
checkpoint = nbm.create_checkpoint(notebook_id)
700+
data = jsonapi.dumps(checkpoint, default=date_default)
701+
self.finish(data)
702+
703+
704+
class ModifyNotebookCheckpointsHandler(AuthenticatedHandler):
705+
706+
SUPPORTED_METHODS = ('POST', 'DELETE')
707+
708+
@web.authenticated
709+
def post(self, notebook_id, checkpoint_id):
695710
"""post restores a notebook from a checkpoint"""
696711
nbm = self.application.notebook_manager
697-
checkpoint_id = self.get_argument('checkpoint', None)
698712
nbm.restore_checkpoint(notebook_id, checkpoint_id)
699713
self.set_status(204)
700714
self.finish()
701715

702716
@web.authenticated
703-
def put(self, notebook_id):
704-
"""put saves the notebook, and creates a new checkpoint"""
705-
nbm = self.application.notebook_manager
706-
format = self.get_argument('format', default='json')
707-
name = self.get_argument('name', default=None)
708-
nbm.save_notebook(notebook_id, self.request.body, name=name, format=format)
709-
checkpoint = nbm.create_checkpoint(notebook_id)
710-
self.finish(checkpoint)
711-
712-
@web.authenticated
713-
def delete(self, notebook_id):
717+
def delete(self, notebook_id, checkpoint_id):
714718
"""delete clears a checkpoint for a given notebook"""
715719
nbm = self.application.notebook_manager
716-
checkpoint_id = self.get_argument('checkpoint', None)
717720
nbm.delte_checkpoint(notebook_id, checkpoint_id)
718721
self.set_status(204)
719722
self.finish()

IPython/frontend/html/notebook/notebookapp.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@
6868
ProjectDashboardHandler, NewHandler, NamedNotebookHandler,
6969
MainKernelHandler, KernelHandler, KernelActionHandler, IOPubHandler, StdinHandler,
7070
ShellHandler, NotebookRootHandler, NotebookHandler, NotebookCopyHandler,
71-
AuthenticatedFileHandler, MainClusterHandler, ClusterProfileHandler,
72-
ClusterActionHandler, FileFindHandler,
73-
NotebookRedirectHandler, NotebookCheckpointHandler,
71+
NotebookRedirectHandler, NotebookCheckpointsHandler, ModifyNotebookCheckpointsHandler,
72+
AuthenticatedFileHandler, FileFindHandler,
73+
MainClusterHandler, ClusterProfileHandler, ClusterActionHandler,
7474
)
7575
from .nbmanager import NotebookManager
7676
from .filenbmanager import FileNotebookManager
@@ -105,6 +105,7 @@
105105
_kernel_action_regex = r"(?P<action>restart|interrupt)"
106106
_notebook_id_regex = r"(?P<notebook_id>\w+-\w+-\w+-\w+-\w+)"
107107
_notebook_name_regex = r"(?P<notebook_name>.+\.ipynb)"
108+
_checkpoint_id_regex = r"(?P<checkpoint_id>[\w-]+)"
108109
_profile_regex = r"(?P<profile>[^\/]+)" # there is almost no text that is invalid
109110
_cluster_action_regex = r"(?P<action>start|stop)"
110111

@@ -162,7 +163,10 @@ def __init__(self, ipython_app, kernel_manager, notebook_manager,
162163
(r"/kernels/%s/stdin" % _kernel_id_regex, StdinHandler),
163164
(r"/notebooks", NotebookRootHandler),
164165
(r"/notebooks/%s" % _notebook_id_regex, NotebookHandler),
165-
(r"/notebooks/%s/checkpoint" % _notebook_id_regex, NotebookCheckpointHandler),
166+
(r"/notebooks/%s/checkpoints" % _notebook_id_regex, NotebookCheckpointsHandler),
167+
(r"/notebooks/%s/checkpoints/%s" % (_notebook_id_regex, _checkpoint_id_regex),
168+
ModifyNotebookCheckpointsHandler
169+
),
166170
(r"/files/(.*)", AuthenticatedFileHandler, {'path' : notebook_manager.notebook_dir}),
167171
(r"/clusters", MainClusterHandler),
168172
(r"/clusters/%s/%s" % (_profile_regex, _cluster_action_regex), ClusterActionHandler),

0 commit comments

Comments
 (0)