Show More
@@ -273,27 +273,46 b' class FileNotebookManager(NotebookManager):' | |||||
273 | name = self.get_name(notebook_id) |
|
273 | name = self.get_name(notebook_id) | |
274 | return self.get_checkpoint_path_by_name(name, checkpoint_id) |
|
274 | return self.get_checkpoint_path_by_name(name, checkpoint_id) | |
275 |
|
275 | |||
|
276 | def get_checkpoint_info(self, notebook_id, checkpoint_id): | |||
|
277 | """construct the info dict for a given checkpoint""" | |||
|
278 | path = self.get_checkpoint_path(notebook_id, checkpoint_id) | |||
|
279 | stats = os.stat(path) | |||
|
280 | last_modified = datetime.datetime.utcfromtimestamp(stats.st_mtime) | |||
|
281 | info = dict( | |||
|
282 | checkpoint_id = checkpoint_id, | |||
|
283 | last_modified = last_modified, | |||
|
284 | ) | |||
|
285 | ||||
|
286 | return info | |||
|
287 | ||||
276 | # public checkpoint API |
|
288 | # public checkpoint API | |
277 |
|
289 | |||
278 | def create_checkpoint(self, notebook_id): |
|
290 | def create_checkpoint(self, notebook_id): | |
279 | """Create a checkpoint from the current state of a notebook""" |
|
291 | """Create a checkpoint from the current state of a notebook""" | |
280 | nb_path = self.get_path(notebook_id) |
|
292 | nb_path = self.get_path(notebook_id) | |
281 | cp_path = self.get_checkpoint_path(notebook_id, "checkpoint") |
|
293 | # only the one checkpoint ID: | |
|
294 | checkpoint_id = "checkpoint" | |||
|
295 | cp_path = self.get_checkpoint_path(notebook_id, checkpoint_id) | |||
282 | self.log.debug("creating checkpoint for notebook %s", notebook_id) |
|
296 | self.log.debug("creating checkpoint for notebook %s", notebook_id) | |
283 | if not os.path.exists(self.checkpoint_dir): |
|
297 | if not os.path.exists(self.checkpoint_dir): | |
284 | os.mkdir(self.checkpoint_dir) |
|
298 | os.mkdir(self.checkpoint_dir) | |
285 | shutil.copy2(nb_path, cp_path) |
|
299 | shutil.copy2(nb_path, cp_path) | |
|
300 | ||||
|
301 | # return the checkpoint info | |||
|
302 | return self.get_checkpoint_info(notebook_id, checkpoint_id) | |||
286 |
|
303 | |||
287 | def list_checkpoints(self, notebook_id): |
|
304 | def list_checkpoints(self, notebook_id): | |
288 | """list the checkpoints for a given notebook |
|
305 | """list the checkpoints for a given notebook | |
289 |
|
306 | |||
290 | This notebook manager currently only supports one checkpoint per notebook. |
|
307 | This notebook manager currently only supports one checkpoint per notebook. | |
291 | """ |
|
308 | """ | |
292 |
|
|
309 | checkpoint_id = "checkpoint" | |
293 | if os.path.exists(path): |
|
310 | path = self.get_checkpoint_path(notebook_id, checkpoint_id) | |
294 | return ["checkpoint"] |
|
311 | if not os.path.exists(path): | |
295 | else: |
|
|||
296 | return [] |
|
312 | return [] | |
|
313 | else: | |||
|
314 | return [self.get_checkpoint_info(notebook_id, checkpoint_id)] | |||
|
315 | ||||
297 |
|
316 | |||
298 | def restore_checkpoint(self, notebook_id, checkpoint_id): |
|
317 | def restore_checkpoint(self, notebook_id, checkpoint_id): | |
299 | """restore a notebook to a checkpointed state""" |
|
318 | """restore a notebook to a checkpointed state""" | |
@@ -301,6 +320,7 b' class FileNotebookManager(NotebookManager):' | |||||
301 | nb_path = self.get_path(notebook_id) |
|
320 | nb_path = self.get_path(notebook_id) | |
302 | cp_path = self.get_checkpoint_path(notebook_id, checkpoint_id) |
|
321 | cp_path = self.get_checkpoint_path(notebook_id, checkpoint_id) | |
303 | if not os.path.isfile(cp_path): |
|
322 | if not os.path.isfile(cp_path): | |
|
323 | self.log.debug("checkpoint file does not exist: %s", cp_path) | |||
304 | raise web.HTTPError(404, |
|
324 | raise web.HTTPError(404, | |
305 | u'Notebook checkpoint does not exist: %s-%s' % (notebook_id, checkpoint_id) |
|
325 | u'Notebook checkpoint does not exist: %s-%s' % (notebook_id, checkpoint_id) | |
306 | ) |
|
326 | ) |
General Comments 0
You need to be logged in to leave comments.
Login now