{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### Requirements\n", "\n", "- Installed git. More on how to use and install git can be found [here][git]. \n", "- A zip of the certificate. Particularly, you'll need the crt and key files.\n", "- A labkey access configuration file. A sample for [linux][linuxConfig] or [Windows][windowsConfig]. The file paths point to locations of extracted files from certificate zip on your disk.\n", "\n", "[git]: https://git-scm.com/\n", "[linuxConfig]: https://git0.fmf.uni-lj.si/studen/labkeyInterface/src/master/network-config-sample.json\n", "[windowsConfig]: https://git0.fmf.uni-lj.si/studen/labkeyInterface/src/master/network-config-sample.json" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "remoteSourcesURL https://git0.fmf.uni-lj.si/studen/nixSuite/raw/master/remoteResources/resources.json\n", "{'labkeyInterface': {'url': 'https://git0.fmf.uni-lj.si/studen/labkeyInterface/archive/master.zip', 'branch': 'master', 'modules': []}, 'irAEMM': {'url': 'https://git0.fmf.uni-lj.si/studen/iraemm/archive/master.zip', 'branch': 'master', 'modules': ['iraemmBrowser']}, 'SlicerLabkeyExtension': {'url': 'https://git0.fmf.uni-lj.si/studen/SlicerLabkeyExtension/archive/SlicerExtensionIndex.zip', 'branch': 'SlicerExtensionIndex', 'modules': ['labkeyBrowser']}, 'parseConfig': {'url': 'https://git0.fmf.uni-lj.si/studen/parseConfig/archive/master.zip', 'branch': 'master', 'modules': []}, 'orthancInterface': {'url': 'https://git0.fmf.uni-lj.si/studen/orthancInterface/archive/master.zip', 'branch': 'master', 'modules': []}}\n" ] } ], "source": [ "#load required libraries\n", "import sys\n", "import os\n", "import SimpleITK\n", "import numpy\n", "import matplotlib.pyplot\n", "import chardet\n", "import json\n", "\n", "#you should get nixSuite via git clone https://git0.fmf.uni-lj.si/studen/nixSuite.git\n", "#if you don't put it to $HOME/software/src/, you should update the path\n", "nixSuite=os.path.join(os.path.expanduser('~'),'software','src','nixSuite')\n", "sys.path.append(os.path.join(nixSuite,'wrapper'))\n", "import nixWrapper\n", "nixWrapper.loadLibrary('labkeyInterface')\n", "import labkeyInterface\n", "import labkeyDatabaseBrowser\n", "import labkeyFileBrowser\n", "\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Using: /home/studen/.labkey/astuden/astuden.crt\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/usr/lib/python3/dist-packages/urllib3/connection.py:391: SubjectAltNameWarning: Certificate for merlin.fmf.uni-lj.si has no `subjectAltName`, falling back to check for a `commonName` for now. This feature is being removed by major browsers and deprecated by RFC 2818. (See https://github.com/urllib3/urllib3/issues/497 for details.)\n", " warnings.warn(\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "User: andrej studen CSRF: fef6cf98248ecf46dcbb51d171424039\n" ] }, { "data": { "text/plain": [ "'fef6cf98248ecf46dcbb51d171424039'" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#check connectivity. This checks the configuration in $HOME/.labkey/network.json, \n", "#where paths to certificates are stored\n", "net=labkeyInterface.labkeyInterface()\n", "fconfig=os.path.join(os.path.expanduser('~'),'.labkey','network.json')\n", "net.init(fconfig)\n", "#this reports the certificate used\n", "print('Using: {}'.format(net.connectionConfig['SSL']['user']))\n", "#This gets a deafult CSRF code; It should report user name plus a long string of random hex numbers\n", "net.getCSRF()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "db=labkeyDatabaseBrowser.labkeyDB(net)\n", "fb=labkeyFileBrowser.labkeyFileBrowser(net)\n", "#select a project\n", "project='EUtopia/Study'\n", "dataset='Imaging'\n", "idFilter={'variable':'ParticipantId','value':'VUB_PA3','oper':'eq'}\n", "#empty filter\n", "#qFilter=[]\n", "#qFilter can be a list of filters used in conjugation (logical AND)\n", "qFilter=[idFilter]\n", "ds=db.selectRows(project,'study',dataset,qFilter)\n", "rows=ds['rows']\n", "for row in rows:\n", " #row as a dictionary\n", " print(row)\n", " #update row\n", " #depending on field type adjust newValue\n", " row['field']='newValue'\n", " #print the new row\n", " print(row)\n", " #change the value of the field in database \n", " #if field is not in database, it will NOT be added and no changes will occur\n", " #db.modifyRows('update',project,'study',dataset,[row]) \n", " " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.10" } }, "nbformat": 4, "nbformat_minor": 4 }