diff --git a/jupyter-openbis-extension/server.py b/jupyter-openbis-extension/server.py index 4959b643935b8f1085f64ab27bc7c9ad22a9343b..beccb3252d0e7b672813a35b9742c51e5d28fa6d 100644 --- a/jupyter-openbis-extension/server.py +++ b/jupyter-openbis-extension/server.py @@ -69,6 +69,15 @@ def load_jupyter_server_extension(nb_server_app): host_pattern = '.*$' base_url = web_app.settings['base_url'] + # get the file list + web_app.add_handlers( + host_pattern, + [(url_path_join( base_url, '/general/filelist'), + FileListHandler + )] + ) + + # DataSet download web_app.add_handlers( host_pattern, @@ -81,10 +90,7 @@ def load_jupyter_server_extension(nb_server_app): # DataSet upload web_app.add_handlers( host_pattern, [( - url_path_join( - base_url, - '/openbis/dataset/(?P<connection_name>.*)' - ), + url_path_join( base_url, '/openbis/dataset/(?P<connection_name>.*)' ), DataSetUploadHandler )] ) @@ -93,9 +99,7 @@ def load_jupyter_server_extension(nb_server_app): web_app.add_handlers( host_pattern, [( - url_path_join( - base_url, - '/openbis/datasetTypes/(?P<connection_name>.*)' + url_path_join( base_url, '/openbis/datasetTypes/(?P<connection_name>.*)' ), DataSetTypesHandler )] @@ -352,6 +356,37 @@ class SampleHandler(IPythonHandler): }) +class FileListHandler(IPythonHandler): + + def get(self, **params): + """ + Returns the file list of the current working directory + + :param params: + :return: dictionary of files, key is the fully qualified name, + value is the relative name (for display) + """ + + cwd = os.getcwd() + files = {} + for (dirpath, dirnames, filenames) in os.walk(cwd): + if filenames: + for filename in filenames: + # ignore hidden files + if filename.startswith('.'): + continue + # ignore hidden folders + if os.path.relpath(dirpath) != '.' \ + and os.path.relpath(dirpath).startswith('.'): + continue + fqn = os.path.join(dirpath, filename) + files[fqn] = os.path.relpath(fqn, cwd) + + self.set_status(200) + self.write({ + "files": files + }) + class DataSetDownloadHandler(IPythonHandler): """Handle the requests for /openbis/dataset/connection/permId""" diff --git a/todos/Jupyter-OpenBIS-extension todos.md b/todos/Jupyter-OpenBIS-extension todos.md index 7b51fc65b31337372178efbd013399a1251b6b70..3e3ad02ec84f6e35837f415fb8de3c001fc43385 100644 --- a/todos/Jupyter-OpenBIS-extension todos.md +++ b/todos/Jupyter-OpenBIS-extension todos.md @@ -17,9 +17,10 @@ ## 3) Uploading datasets + - let the upload dialog box stay in place until the upload was successful - - if metadata is faulty, tell the user to correct them (e.g. invalid vocabulary) - - show which metadata is mandatory and which are optional + - if metadata is faulty, tell the user to correct them (e.g. invalid vocabulary). This involves the backend to check as much as possible. + - show which metadata is mandatory and which are optional. Mandatory metadata is marked as such in the propertyAssignments that are fetched from the backend (e.g. `"mandatory:true`) - if dataset type is changed back and forth, keep the values that already have been entered - keep choice of current dataset type