From 552c9ff93c6e6016b3706bb95e5bdef44c348ac3 Mon Sep 17 00:00:00 2001 From: vermeul <swen@ethz.ch> Date: Wed, 6 Feb 2019 16:18:56 +0100 Subject: [PATCH] server now sends information about dataset types --- jupyter-openbis-extension/server.py | 31 ++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/jupyter-openbis-extension/server.py b/jupyter-openbis-extension/server.py index c1d72c5..086bffa 100644 --- a/jupyter-openbis-extension/server.py +++ b/jupyter-openbis-extension/server.py @@ -37,6 +37,8 @@ def load_jupyter_server_extension(nb_server_app): """ # load the configuration file + #print(dir(nb_server_app)) + print(nb_server_app.config_file_paths) config = _load_configuration() if config is not None: for conn in config['connections']: @@ -51,6 +53,7 @@ def load_jupyter_server_extension(nb_server_app): base_url = web_app.settings['base_url'] + # DataSet download web_app.add_handlers( host_pattern, [(url_path_join( @@ -106,19 +109,33 @@ def register_connection(connection_info): verify_certificates = conn.verify_certificates ) conn.openbis = openbis + conn.ds_types = {} openbis.login( username = conn.username, password = conn.password ) conn.status = 'connected' + print('connected to {}'.format(conn.name)) except Exception as exc: conn.status = 'FAILED: {}'.format(exc) print('ERROR: could not connected to {}. Reason: {}'.format(conn.name, exc)) - raise exc + try: + # add dataset types to the connection + dataset_types = conn.openbis.get_dataset_types() + dts = dataset_types.df.to_dict(orient='records') + for dt in dts: + dataset_type = conn.openbis.get_dataset_type(dt['code']) + pa = dataset_type.get_propertyAssignments() + pa_dict = pa.to_dict(orient='records') + dt['propertyAssignments'] = pa_dict + conn.ds_types = dts + except Exception as e: + print('ERROR: {}'.format(e)) + def check_connection(connection_name): """Checks whether connection is valid and session is still active @@ -157,10 +174,12 @@ class OpenBISHandler(IPythonHandler): """ connections= [] for conn in openbis_connections.values(): + connections.append({ - 'name' : conn.name, - 'url' : conn.url, - 'status' : conn.status, + 'name' : conn.name, + 'url' : conn.url, + 'status' : conn.status, + 'ds_types': conn.ds_types, }) self.write({ @@ -188,7 +207,9 @@ class SampleHandler(IPythonHandler): sample = conn.openbis.get_sample(permId) except Exception as exc: print(exc) - self.send_error( reason = 'No such sample found: {}'.format(permId) ) + self.send_error( reason = 'No such sample: {}'.format(permId) ) + if sample is None: + return datasets = sample.get_datasets().df datasets.replace({np.nan:None}, inplace=True) # replace NaN with None, otherwise we cannot convert it correctly -- GitLab