Merge pull request #237 from takluyver/forwport-8524

Fix abstract checkpoint methods to match interface used
This commit is contained in:
Min RK 2015-07-28 10:14:51 -07:00
commit 89124554f4
2 changed files with 23 additions and 7 deletions

View File

@ -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)
@ -118,10 +118,25 @@ class GenericCheckpointsMixin(object):
"""
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")

View File

@ -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"
@ -168,7 +168,7 @@ class GenericFileCheckpoints(GenericCheckpointsMixin, FileCheckpoints):
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)
@ -185,6 +185,7 @@ class GenericFileCheckpoints(GenericCheckpointsMixin, FileCheckpoints):
}
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)