Commit 060e3281 authored by mouadh's avatar mouadh

fix config path (with olapy-web flask instance_path)

parent 93df06cd
...@@ -33,6 +33,9 @@ class MdxEngine: ...@@ -33,6 +33,9 @@ class MdxEngine:
:param sep: separator in the csv files :param sep: separator in the csv files
""" """
# DATA_FOLDER useful for olapy web (falsk instance_path)
# get olapy-data path with instance_path instead of 'expanduser'
DATA_FOLDER = None
CUBE_FOLDER = "cubes" CUBE_FOLDER = "cubes"
# (before instantiate MdxEngine I need to access cubes information) # (before instantiate MdxEngine I need to access cubes information)
csv_files_cubes = [] csv_files_cubes = []
...@@ -75,7 +78,12 @@ class MdxEngine: ...@@ -75,7 +78,12 @@ class MdxEngine:
""":return: list cubes name that exists in cubes folder (under ~/olapy-data/cubes) and postgres database (if connected).""" """:return: list cubes name that exists in cubes folder (under ~/olapy-data/cubes) and postgres database (if connected)."""
# get csv files folders (cubes) # get csv files folders (cubes)
# toxworkdir does not expanduser properly under tox # toxworkdir does not expanduser properly under tox
if RUNNING_TOX:
# surrended with try, except and PASS so we continue getting cubes from different
# sources (db, csv...) without interruption
if cls.DATA_FOLDER is not None:
home_directory = cls.DATA_FOLDER
elif RUNNING_TOX:
home_directory = os.environ.get('HOME_DIR') home_directory = os.environ.get('HOME_DIR')
else: else:
home_directory = expanduser("~") home_directory = expanduser("~")
...@@ -94,7 +102,7 @@ class MdxEngine: ...@@ -94,7 +102,7 @@ class MdxEngine:
# get postgres databases # get postgres databases
try: try:
db = MyDB() db = MyDB(db_config_file_path=cls.DATA_FOLDER)
connection = db.engine connection = db.engine
# TODO this work only with postgres # TODO this work only with postgres
result = connection.execute('SELECT datname FROM pg_database WHERE datistemplate = false;') result = connection.execute('SELECT datname FROM pg_database WHERE datistemplate = false;')
...@@ -174,7 +182,6 @@ class MdxEngine: ...@@ -174,7 +182,6 @@ class MdxEngine:
:return: star schema DataFrame :return: star schema DataFrame
""" """
fusion = None fusion = None
config_file_parser = ConfigParser(self.cube_path) config_file_parser = ConfigParser(self.cube_path)
if config_file_parser.config_file_exist( if config_file_parser.config_file_exist(
self.client self.client
......
...@@ -2,6 +2,7 @@ from __future__ import absolute_import, division, print_function ...@@ -2,6 +2,7 @@ from __future__ import absolute_import, division, print_function
from ..tools.connection import MyDB from ..tools.connection import MyDB
import pandas.io.sql as psql import pandas.io.sql as psql
import os
def _load_table_config_file(executer_instance, cube_obj): def _load_table_config_file(executer_instance, cube_obj):
...@@ -83,7 +84,7 @@ def _construct_web_star_schema_config_file(executer_instance, cubes_obj): ...@@ -83,7 +84,7 @@ def _construct_web_star_schema_config_file(executer_instance, cubes_obj):
all_columns = [] all_columns = []
executer_instance.facts = cubes_obj.facts[0].table_name executer_instance.facts = cubes_obj.facts[0].table_name
db = MyDB(db=executer_instance.cube) db = MyDB(db=executer_instance.cube,db_config_file_path=os.path.join(executer_instance.cube_path,".."))
# load facts table # load facts table
if cubes_obj.facts[0].columns: if cubes_obj.facts[0].columns:
......
...@@ -13,7 +13,7 @@ def _load_tables_db(executer_instance): ...@@ -13,7 +13,7 @@ def _load_tables_db(executer_instance):
:return: tables dict with table name as key and dataframe as value :return: tables dict with table name as key and dataframe as value
""" """
tables = {} tables = {}
db = MyDB(db=executer_instance.cube) db = MyDB(db_config_file_path=executer_instance.DATA_FOLDER,db=executer_instance.cube)
inspector = inspect(db.engine) inspector = inspect(db.engine)
for table_name in inspector.get_table_names(): for table_name in inspector.get_table_names():
......
...@@ -17,10 +17,10 @@ class MyDB(object): ...@@ -17,10 +17,10 @@ class MyDB(object):
# raise Exception('Missing database config file') # raise Exception('Missing database config file')
def __init__(self,db=None): def __init__(self,db_config_file_path=None,db=None):
# TODO temporary # TODO temporary
db_config = DbConfigParser() db_config = DbConfigParser(config_path=db_config_file_path)
db_credentials = db_config.get_db_credentials()[0] db_credentials = db_config.get_db_credentials()[0]
username = db_credentials['user_name'] username = db_credentials['user_name']
password = db_credentials['password'] password = db_credentials['password']
......
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