Setting up QDataLib

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. The settings for QDataLib is stored in a config.ini file.

The config.ini file contains the following information: - mongo_client: The mongo clioent used - mongo_db: The mogo database used - mongo_collection: The collection used to keep track of your data files - db_local: The SQLite database to export from - db_shared: The SQLite database to export to - shared_dir: The Directory where other dataformats should be stored

If we instantiate an instance of Qdatalib without thise information in the config file, Qdatalib vill ask us to setup the config file.

[1]:
import tempfile
import os
from qdatalib.tolib import Qdatalib
qdatalib = Qdatalib()
Please setup QDataLib config file

Setting up the config file

The configfile can be setup by instantiate an instance of Qdatalib passing the necessary information:

[2]:
client = "mongodb://localhost:27017/"
db = "testbase"
col = "testcol"
lib_dir = tempfile.gettempdir()
db_local = os.path.join(lib_dir, 'qdatalib_tutorial.db')
db_shared = os.path.join(lib_dir, 'shared_tutorial.db')

qdatalib = Qdatalib(
                    mongo_client = client,
                    mongo_db = db,
                    mongo_collection = col,
                    db_local = db_local,
                    db_shared = db_shared,
                    lib_dir = lib_dir)

Inspecting the config file

We can print the content of the config file

[3]:
qdatalib.config.print_config_file()
[MONGODB]
client = mongodb://localhost:27017/
db = testbase
collection = testcol

[SQLITE]
db_local = C:\Users\rbcma\AppData\Local\Temp\qdatalib_tutorial.db
db_shared = C:\Users\rbcma\AppData\Local\Temp\shared_tutorial.db

[LIBDIR]
lib_dir = C:\Users\rbcma\AppData\Local\Temp


Changing the config file

We can change the content of the config file by using the funcions: - set_mongo_client - set_mongo_db - set_mongo_collection - set_db_local - set_db_shared - set_lib_dir

[4]:
db_local = os.path.join(lib_dir, 'qdatalib_local.db')
qdatalib.set_db_local(db_local)
[5]:
qdatalib.config.print_config_file()
[MONGODB]
client = mongodb://localhost:27017/
db = testbase
collection = testcol

[SQLITE]
db_local = C:\Users\rbcma\AppData\Local\Temp\qdatalib_local.db
db_shared = C:\Users\rbcma\AppData\Local\Temp\shared_tutorial.db

[LIBDIR]
lib_dir = C:\Users\rbcma\AppData\Local\Temp