Commit 44a31ef6 authored by mouadh's avatar mouadh

db config file

parent 19c0f590
......@@ -6,7 +6,7 @@
<!--<sgbd>postgres</sgbd>-->
<user_name>postgres</user_name>
<passowrd>root</passowrd>
<password>root</password>
<host>localhost</host>
</database>
......
import psycopg2 as pg
# postgres connection
from olapy.core.mdx.tools.olapy_config_file_parser import DbConfigParser
from olapy_config_file_parser import DbConfigParser
class MyDB(object):
"""Connect to sql database (postgres only right now)."""
@staticmethod
def get_db_credentials():
db_config = DbConfigParser()
if db_config.config_file_exist():
# many databases in the future maybe
return db_config.get_db_credentials()[0]
else:
raise Exception('Missing database config file')
# @staticmethod
# def db_credentials():
# db_config = DbConfigParser()
# if db_config.config_file_exist():
# # many databases in the future maybe
# return db_config.get_db_credentials()[0]
# else:
# raise Exception('Missing database config file')
def __init__(self,
username=get_db_credentials()['user_name'],
password=get_db_credentials()['passowrd'],
username='postgres',
password='root',
db=None,
host=get_db_credentials()['host']):
host='localhost'
):
# TODO temporary
db_config = DbConfigParser()
db_credentials = db_config.get_db_credentials()[0]
username = db_credentials['user_name']
password = db_credentials['password']
host = db_credentials['host']
if db is None:
self.connection = pg.connect("user={0} password={1} host='{2}'".
format(username, password, host))
else:
......
......@@ -45,9 +45,10 @@ class DbConfigParser:
try:
return [
{'sgbd': db.find('sgbd').text,
{
# 'sgbd': db.find('sgbd').text,
'user_name': db.find('user_name').text,
'passowrd': db.find('passowrd').text,
'password': db.find('password').text,
'host': db.find('host').text,
}
for db in tree.xpath('/olapy/database')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment