From 68894dff0817c6058ddad2adcff1fdc479ace2f5 2013-10-17 21:09:14 From: MinRK Date: 2013-10-17 21:09:14 Subject: [PATCH] move os_path to FileNBMan doesn't belong in base NotebookManager --- diff --git a/IPython/html/services/notebooks/filenbmanager.py b/IPython/html/services/notebooks/filenbmanager.py index b01c3a7..7497dc4 100644 --- a/IPython/html/services/notebooks/filenbmanager.py +++ b/IPython/html/services/notebooks/filenbmanager.py @@ -92,11 +92,49 @@ class FileNotebookManager(NotebookManager): i = i+1 return name - def os_path_exists(self, path): - """Check that the given file system path is valid on this machine.""" - if os.path.exists(path) is False: - raise web.HTTPError(404, "No file or directory found.") + def path_exists(self, path): + """Does the API-style path (directory) actually exist? + Parameters + ---------- + path : string + The path to check. This is an API path (`/` separated, + relative to base notebook-dir). + + Returns + ------- + exists : bool + Whether the path is indeed a directory. + """ + os_path = self.get_os_path(path=path) + return os.path.isdir(os_path) + + def get_os_path(self, name=None, path=''): + """Given a notebook name and a URL path, return its file system + path. + + Parameters + ---------- + name : string + The name of a notebook file with the .ipynb extension + path : string + The relative URL path (with '/' as separator) to the named + notebook. + + Returns + ------- + path : string + A file system path that combines notebook_dir (location where + server started), the relative path, and the filename with the + current operating system's url. + """ + parts = path.strip('/').split('/') + parts = [p for p in parts if p != ''] # remove duplicate splits + if name is not None: + parts.append(name) + path = os.path.join(self.notebook_dir, *parts) + return path + def notebook_exists(self, name, path=''): """Returns a True if the notebook exists. Else, returns False. diff --git a/IPython/html/services/notebooks/nbmanager.py b/IPython/html/services/notebooks/nbmanager.py index 0b4e5b9..c8dd756 100644 --- a/IPython/html/services/notebooks/nbmanager.py +++ b/IPython/html/services/notebooks/nbmanager.py @@ -49,7 +49,7 @@ class NotebookManager(LoggingConfigurable): def path_exists(self, path): """Does the API-style path (directory) actually exist? - Override this method for non-filesystem-based notebooks. + Override this method in subclasses. Parameters ---------- @@ -61,36 +61,8 @@ class NotebookManager(LoggingConfigurable): exists : bool Whether the path does indeed exist. """ - os_path = self.get_os_path(name, path) - return os.path.exists(os_path) - + raise NotImplementedError - def get_os_path(self, name=None, path=''): - """Given a notebook name and a URL path, return its file system - path. - - Parameters - ---------- - name : string - The name of a notebook file with the .ipynb extension - path : string - The relative URL path (with '/' as separator) to the named - notebook. - - Returns - ------- - path : string - A file system path that combines notebook_dir (location where - server started), the relative path, and the filename with the - current operating system's url. - """ - parts = path.strip('/').split('/') - parts = [p for p in parts if p != ''] # remove duplicate splits - if name is not None: - parts.append(name) - path = os.path.join(self.notebook_dir, *parts) - return path - def _notebook_dir_changed(self, name, old, new): """Do a bit of validation of the notebook dir.""" if not os.path.isabs(new):