From a77ac78eed4a4709d48c78ef43becdeaad676fde Mon Sep 17 00:00:00 2001 From: vermeul <swen@ethz.ch> Date: Thu, 18 Jul 2019 00:05:29 +0200 Subject: [PATCH] fixed notebook_dir problem --- jupyter-openbis-extension/connection.py | 8 ++++++-- jupyter-openbis-extension/dataset.py | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/jupyter-openbis-extension/connection.py b/jupyter-openbis-extension/connection.py index 0e2039d..632334c 100644 --- a/jupyter-openbis-extension/connection.py +++ b/jupyter-openbis-extension/connection.py @@ -73,7 +73,9 @@ class OpenBISConnections(IPythonHandler): def _notebook_dir(self): notebook_dir = os.getcwd() - if 'notebook_dir' in self.config.NotebookApp: + if 'SingleUserNotebookApp' in self.config and 'notebook_dir' in self.config.SingleUserNotebookApp: + notebook_dir = self.config.SingleUserNotebookApp.notebook_dir + elif 'notebook_dir' in self.config.NotebookApp: notebook_dir = self.config.NotebookApp.notebook_dir return notebook_dir @@ -115,7 +117,9 @@ class OpenBISConnectionHandler(IPythonHandler): def _notebook_dir(self): notebook_dir = os.getcwd() - if 'notebook_dir' in self.config.NotebookApp: + if 'SingleUserNotebookApp' in self.config and 'notebook_dir' in self.config.SingleUserNotebookApp: + notebook_dir = self.config.SingleUserNotebookApp.notebook_dir + elif 'notebook_dir' in self.config.NotebookApp: notebook_dir = self.config.NotebookApp.notebook_dir return notebook_dir diff --git a/jupyter-openbis-extension/dataset.py b/jupyter-openbis-extension/dataset.py index 97bb085..4e81ddd 100644 --- a/jupyter-openbis-extension/dataset.py +++ b/jupyter-openbis-extension/dataset.py @@ -114,6 +114,14 @@ class DataSetTypesHandler(IPythonHandler): class DataSetUploadHandler(IPythonHandler): """Handle the POST requests for /openbis/dataset/connection_name""" + def _notebook_dir(self): + notebook_dir = os.getcwd() + if 'SingleUserNotebookApp' in self.config and 'notebook_dir' in self.config.SingleUserNotebookApp: + notebook_dir = self.config.SingleUserNotebookApp.notebook_dir + elif 'notebook_dir' in self.config.NotebookApp: + notebook_dir = self.config.NotebookApp.notebook_dir + return notebook_dir + def upload_data(self, conn, data): if not conn.is_session_active(): try: @@ -165,13 +173,15 @@ class DataSetUploadHandler(IPythonHandler): }) filenames = [] + notebook_dir = self._notebook_dir() for filename in data.get('files'): filename = unquote(filename) - if os.path.isfile(filename): - filenames.append(filename) + full_filename_path = os.path.join(notebook_dir, filename) + if os.path.isfile(full_filename_path): + filenames.append(full_filename_path) else: errors.append({ - "file": "File not found: {}".format(filename) + "file": "File not found: {}".format(full_filename_path) }) try: -- GitLab