diff --git a/IPython/html/services/notebooks/filenbmanager.py b/IPython/html/services/notebooks/filenbmanager.py index 10a6c70..e6fd5f1 100644 --- a/IPython/html/services/notebooks/filenbmanager.py +++ b/IPython/html/services/notebooks/filenbmanager.py @@ -82,16 +82,6 @@ class FileNotebookManager(NotebookManager): for name in names] return names - def increment_filename(self, basename, path='', ext='.ipynb'): - """Return a non-used filename of the form basename.""" - path = path.strip('/') - for i in itertools.count(): - name = u'{basename}{i}{ext}'.format(basename=basename, i=i, ext=ext) - os_path = self.get_os_path(name, path) - if not os.path.isfile(os_path): - break - return name - def path_exists(self, path): """Does the API-style path (directory) actually exist? diff --git a/IPython/html/services/notebooks/nbmanager.py b/IPython/html/services/notebooks/nbmanager.py index b2b8716..630e634 100644 --- a/IPython/html/services/notebooks/nbmanager.py +++ b/IPython/html/services/notebooks/nbmanager.py @@ -17,6 +17,7 @@ Authors: # Imports #----------------------------------------------------------------------------- +import itertools import os from IPython.config.configurable import LoggingConfigurable @@ -126,8 +127,20 @@ class NotebookManager(LoggingConfigurable): The name of a notebook without the ``.ipynb`` file extension. path : unicode The URL path of the notebooks directory + + Returns + ------- + name : unicode + A notebook name (with the .ipynb extension) that starts + with basename and does not refer to any existing notebook. """ - return basename + path = path.strip('/') + for i in itertools.count(): + name = u'{basename}{i}{ext}'.format(basename=basename, i=i, + ext=self.filename_ext) + if not self.notebook_exists(name, path): + break + return name def notebook_exists(self, name, path=''): """Returns a True if the notebook exists. Else, returns False.