From e9806d2b047c0b60c5263ec5e4e6c2fc9d252972 2012-06-18 22:37:44 From: MinRK Date: 2012-06-18 22:37:44 Subject: [PATCH] create notebook-dir if it doesn't exist closes #1980 --- diff --git a/IPython/frontend/html/notebook/notebookmanager.py b/IPython/frontend/html/notebook/notebookmanager.py index bc8ec4a..ea6da86 100644 --- a/IPython/frontend/html/notebook/notebookmanager.py +++ b/IPython/frontend/html/notebook/notebookmanager.py @@ -26,7 +26,7 @@ from tornado import web from IPython.config.configurable import LoggingConfigurable from IPython.nbformat import current -from IPython.utils.traitlets import Unicode, List, Dict, Bool +from IPython.utils.traitlets import Unicode, List, Dict, Bool, TraitError #----------------------------------------------------------------------------- # Classes @@ -37,6 +37,16 @@ class NotebookManager(LoggingConfigurable): notebook_dir = Unicode(os.getcwdu(), config=True, help=""" The directory to use for notebooks. """) + def _notebook_dir_changed(self, name, old, new): + """do a bit of validation of the notebook dir""" + if os.path.exists(new) and not os.path.isdir(new): + raise TraitError("notebook dir %r is not a directory" % new) + if not os.path.exists(new): + self.log.info("Creating notebook dir %s", new) + try: + os.mkdir(new) + except: + raise TraitError("Couldn't create notebook dir %r" % new) save_script = Bool(False, config=True, help="""Automatically create a Python script when saving the notebook.