{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Setting up QDataLib\n", "\n", "The first time you use QDataLib on a given computer you need to tell QDataLib which Mongodb database it should talk to and the path to the \"local\" and \"shared\" SQLite database and finally the path where other types of data files should be stored. \n", "The settings for QDataLib is stored in a config.ini file.\n", "\n", "The config.ini file contains the following information:\n", "- mongo_client: The mongo clioent used \n", "- mongo_db: The mogo database used \n", "- mongo_collection: The collection used to keep track of your data files\n", "- db_local: The SQLite database to export from\n", "- db_shared: The SQLite database to export to\n", "- shared_dir: The Directory where other dataformats should be stored " ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "If we instantiate an instance of Qdatalib without thise information in the config file,\n", "Qdatalib vill ask us to setup the config file. " ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Please setup QDataLib config file\n" ] } ], "source": [ "import tempfile\n", "import os\n", "from qdatalib.tolib import Qdatalib\n", "qdatalib = Qdatalib()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Setting up the config file\n", "The configfile can be setup by instantiate an instance of Qdatalib passing the necessary information:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "client = \"mongodb://localhost:27017/\"\n", "db = \"testbase\"\n", "col = \"testcol\"\n", "lib_dir = tempfile.gettempdir()\n", "db_local = os.path.join(lib_dir, 'qdatalib_tutorial.db')\n", "db_shared = os.path.join(lib_dir, 'shared_tutorial.db')\n", "\n", "qdatalib = Qdatalib(\n", " mongo_client = client,\n", " mongo_db = db,\n", " mongo_collection = col,\n", " db_local = db_local,\n", " db_shared = db_shared,\n", " lib_dir = lib_dir)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Inspecting the config file \n", "We can print the content of the config file" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[MONGODB]\n", "client = mongodb://localhost:27017/\n", "db = testbase\n", "collection = testcol\n", "\n", "[SQLITE]\n", "db_local = C:\\Users\\rbcma\\AppData\\Local\\Temp\\qdatalib_tutorial.db\n", "db_shared = C:\\Users\\rbcma\\AppData\\Local\\Temp\\shared_tutorial.db\n", "\n", "[LIBDIR]\n", "lib_dir = C:\\Users\\rbcma\\AppData\\Local\\Temp\n", "\n", "\n" ] } ], "source": [ "qdatalib.config.print_config_file()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Changing the config file\n", "We can change the content of the config file by using the funcions:\n", "- set_mongo_client\n", "- set_mongo_db\n", "- set_mongo_collection\n", "- set_db_local\n", "- set_db_shared\n", "- set_lib_dir" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "db_local = os.path.join(lib_dir, 'qdatalib_local.db')\n", "qdatalib.set_db_local(db_local)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[MONGODB]\n", "client = mongodb://localhost:27017/\n", "db = testbase\n", "collection = testcol\n", "\n", "[SQLITE]\n", "db_local = C:\\Users\\rbcma\\AppData\\Local\\Temp\\qdatalib_local.db\n", "db_shared = C:\\Users\\rbcma\\AppData\\Local\\Temp\\shared_tutorial.db\n", "\n", "[LIBDIR]\n", "lib_dir = C:\\Users\\rbcma\\AppData\\Local\\Temp\n", "\n", "\n" ] } ], "source": [ "qdatalib.config.print_config_file()" ] } ], "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.7.7" } }, "nbformat": 4, "nbformat_minor": 4 }