def cwd_for_path(self, path): """Turn API path into absolute OS path.""" os_path = to_os_path(path, self.root_dir) # in the case of notebooks and kernels not being on the same filesystem, # walk up to root_dir if the paths don't exist while not os.path.isdir(os_path) and os_path != self.root_dir: os_path = os.path.dirname(os_path) return os_path
def cwd_for_path(self, path): """Turn API path into absolute OS path.""" # short circuit for NotebookManagers that pass in absolute paths if os.path.exists(path): return path os_path = to_os_path(path, self.root_dir) # in the case of notebooks and kernels not being on the same filesystem, # walk up to root_dir if the paths don't exist while not os.path.exists(os_path) and os_path != self.root_dir: os_path = os.path.dirname(os_path) return os_path
def _get_os_path(self, path): """Given an API path, return its file system path. Parameters ---------- path : string The relative API path to the named file. Returns ------- path : string Native, absolute OS path to for a file. """ return to_os_path(path, self.root_dir)
def _get_os_path(self, name=None, path=''): """Given a filename and API path, return its file system path. Parameters ---------- name : string A filename path : string The relative API path to the named file. Returns ------- path : string API path to be evaluated relative to root_dir. """ if name is not None: path = url_path_join(path, name) return to_os_path(path, self.root_dir)
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. """ if name is not None: path = path + '/' + name return to_os_path(path, self.notebook_dir)
def _get_os_path(self, path): """Given an API path, return its file system path. Parameters ---------- path : string The relative API path to the named file. Returns ------- path : string Native, absolute OS path to for a file. Raises ------ 404: if path is outside root """ root = os.path.abspath(self.root_dir) os_path = to_os_path(path, root) if not (os.path.abspath(os_path) + os.path.sep).startswith(root): raise HTTPError(404, "%s is outside root contents directory" % path) return os_path
def to_os_path(self, api_path): return to_os_path(api_path, root=self.notebook_dir.name)
def to_os_path(self, api_path): return to_os_path(api_path, root=self.td.name)