##// END OF EJS Templates
create checkpoints dir in notebook subdirectories
MinRK -
Show More
@@ -60,31 +60,15 b' class FileNotebookManager(NotebookManager):'
60 60 return
61 61 if not os.path.exists(new) or not os.path.isdir(new):
62 62 raise TraitError("notebook dir %r is not a directory" % new)
63
64 checkpoint_dir = Unicode(config=True,
65 help="""The location in which to keep notebook checkpoints
63
64 checkpoint_dir = Unicode('.ipynb_checkpoints', config=True,
65 help="""The directory name in which to keep notebook checkpoints
66
67 This is a path relative to the notebook's own directory.
66 68
67 By default, it is notebook-dir/.ipynb_checkpoints
69 By default, it is .ipynb_checkpoints
68 70 """
69 71 )
70 def _checkpoint_dir_default(self):
71 return os.path.join(self.notebook_dir, '.ipynb_checkpoints')
72
73 def _checkpoint_dir_changed(self, name, old, new):
74 """do a bit of validation of the checkpoint dir"""
75 if not os.path.isabs(new):
76 # If we receive a non-absolute path, make it absolute.
77 abs_new = os.path.abspath(new)
78 self.checkpoint_dir = abs_new
79 return
80 if os.path.exists(new) and not os.path.isdir(new):
81 raise TraitError("checkpoint dir %r is not a directory" % new)
82 if not os.path.exists(new):
83 self.log.info("Creating checkpoint dir %s", new)
84 try:
85 os.mkdir(new)
86 except:
87 raise TraitError("Couldn't create checkpoint dir %r" % new)
88 72
89 73 def _copy(self, src, dest):
90 74 """copy src to dest
@@ -416,7 +400,11 b' class FileNotebookManager(NotebookManager):'
416 400 checkpoint_id=checkpoint_id,
417 401 ext=self.filename_ext,
418 402 )
419 cp_path = os.path.join(path, self.checkpoint_dir, filename)
403 os_path = self._get_os_path(path=path)
404 cp_dir = os.path.join(os_path, self.checkpoint_dir)
405 if not os.path.exists(cp_dir):
406 os.mkdir(cp_dir)
407 cp_path = os.path.join(cp_dir, filename)
420 408 return cp_path
421 409
422 410 def get_checkpoint_model(self, checkpoint_id, name, path=''):
@@ -455,8 +443,8 b' class FileNotebookManager(NotebookManager):'
455 443 """
456 444 path = path.strip('/')
457 445 checkpoint_id = "checkpoint"
458 path = self.get_checkpoint_path(checkpoint_id, name, path)
459 if not os.path.exists(path):
446 os_path = self.get_checkpoint_path(checkpoint_id, name, path)
447 if not os.path.exists(os_path):
460 448 return []
461 449 else:
462 450 return [self.get_checkpoint_model(checkpoint_id, name, path)]
General Comments 0
You need to be logged in to leave comments. Login now