mirror of
https://github.com/jupyter/notebook.git
synced 2024-12-27 04:20:22 +08:00
MAINT: Return dicts from CheckpointManager.get_checkpoint.
The output is going to get converted to a dict anyway, and this makes it easier to pipe output from a CheckpointManager directly to a ContentsManager.
This commit is contained in:
parent
7030a8717a
commit
1e2e86dcca
@ -252,7 +252,7 @@ class FileCheckpointManager(FileManagerMixin, CheckpointManager):
|
||||
def get_checkpoint(self, checkpoint_id, path, type):
|
||||
"""Get the content of a checkpoint.
|
||||
|
||||
Returns a pair of (content, type).
|
||||
Returns a model suitable for passing to ContentsManager.save.
|
||||
"""
|
||||
path = path.strip('/')
|
||||
self.log.info("restoring %s from checkpoint %s", path, checkpoint_id)
|
||||
@ -260,9 +260,20 @@ class FileCheckpointManager(FileManagerMixin, CheckpointManager):
|
||||
if not os.path.isfile(os_checkpoint_path):
|
||||
self.no_such_checkpoint(path, checkpoint_id)
|
||||
if type == 'notebook':
|
||||
return self._read_notebook(os_checkpoint_path, as_version=4), None
|
||||
return {
|
||||
'type': type,
|
||||
'content': self._read_notebook(
|
||||
os_checkpoint_path,
|
||||
as_version=4,
|
||||
),
|
||||
}
|
||||
else:
|
||||
return self._read_file(os_checkpoint_path, format=None)
|
||||
content, format = self._read_file(os_checkpoint_path, format=None)
|
||||
return {
|
||||
'type': type,
|
||||
'content': content,
|
||||
'format': format,
|
||||
}
|
||||
|
||||
def rename_checkpoint(self, checkpoint_id, old_path, new_path):
|
||||
"""Rename a checkpoint from old_path to new_path."""
|
||||
|
@ -523,19 +523,14 @@ class ContentsManager(LoggingConfigurable):
|
||||
"""
|
||||
Restore a checkpoint.
|
||||
"""
|
||||
type = self.get(path, content=False)['type']
|
||||
content, format = self.checkpoint_manager.get_checkpoint(
|
||||
checkpoint_id,
|
||||
path,
|
||||
type,
|
||||
return self.save(
|
||||
model=self.checkpoint_manager.get_checkpoint(
|
||||
checkpoint_id,
|
||||
path,
|
||||
self.get(path, content=False)['type']
|
||||
),
|
||||
path=path,
|
||||
)
|
||||
|
||||
model = {
|
||||
'type': type,
|
||||
'content': content,
|
||||
'format': format,
|
||||
}
|
||||
return self.save(model, path)
|
||||
|
||||
def delete_checkpoint(self, checkpoint_id, path):
|
||||
return self.checkpoint_manager.delete_checkpoint(checkpoint_id, path)
|
||||
|
Loading…
Reference in New Issue
Block a user