Skip to content

Commit

Permalink
Merge pull request #237 from takluyver/forwport-8524
Browse files Browse the repository at this point in the history
Fix abstract checkpoint methods to match interface used
  • Loading branch information
minrk committed Jul 28, 2015
2 parents e47a7e4 + 3bd961b commit 8912455
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
25 changes: 20 additions & 5 deletions notebook/services/contents/checkpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class GenericCheckpointsMixin(object):
- get_notebook_checkpoint(self, checkpoint_id, path)
To create a generic CheckpointManager, add this mixin to a class that
implement the above three methods plus the remaining Checkpoints API
implement the above four methods plus the remaining Checkpoints API
methods:
- delete_checkpoint(self, checkpoint_id, path)
Expand Down Expand Up @@ -118,10 +118,25 @@ def create_notebook_checkpoint(self, nb, path):
"""
raise NotImplementedError("must be implemented in a subclass")

def get_checkpoint(self, checkpoint_id, path, type):
"""Get the content of a checkpoint.
def get_file_checkpoint(self, checkpoint_id, path):
"""Get the content of a checkpoint for a non-notebook file.
Returns an unvalidated model with the same structure as
the return value of ContentsManager.get
Returns a dict of the form:
{
'type': 'file',
'content': <str>,
'format': {'text','base64'},
}
"""
raise NotImplementedError("must be implemented in a subclass")

def get_notebook_checkpoint(self, checkpoint_id, path):
"""Get the content of a checkpoint for a notebook.
Returns a dict of the form:
{
'type': 'notebook',
'content': <output of nbformat.read>,
}
"""
raise NotImplementedError("must be implemented in a subclass")
5 changes: 3 additions & 2 deletions notebook/services/contents/filecheckpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class GenericFileCheckpoints(GenericCheckpointsMixin, FileCheckpoints):
ContentsManager.
"""
def create_file_checkpoint(self, content, format, path):
"""Create a checkpoint from the current content of a notebook."""
"""Create a checkpoint from the current content of a file."""
path = path.strip('/')
# only the one checkpoint ID:
checkpoint_id = u"checkpoint"
Expand All @@ -168,7 +168,7 @@ def create_notebook_checkpoint(self, nb, path):
return self.checkpoint_model(checkpoint_id, os_checkpoint_path)

def get_notebook_checkpoint(self, checkpoint_id, path):

"""Get a checkpoint for a notebook."""
path = path.strip('/')
self.log.info("restoring %s from checkpoint %s", path, checkpoint_id)
os_checkpoint_path = self.checkpoint_path(checkpoint_id, path)
Expand All @@ -185,6 +185,7 @@ def get_notebook_checkpoint(self, checkpoint_id, path):
}

def get_file_checkpoint(self, checkpoint_id, path):
"""Get a checkpoint for a file."""
path = path.strip('/')
self.log.info("restoring %s from checkpoint %s", path, checkpoint_id)
os_checkpoint_path = self.checkpoint_path(checkpoint_id, path)
Expand Down

0 comments on commit 8912455

Please sign in to comment.