ini

In [6]:
# config.ini
[MARKET1]
	NAME = market1
	[[DIMENSION1]]
		TABLE = dim1
		FIELDS = PRODUCT_ID,PRODUCT_DESC,PRODUCT_L1,PRODUCT_L2
		HIERARCHY_FLAG = True
		LINEAR_HIERARCHY_FLAG = True
		HIERARCHY = PRODUCT_ID,PRODUCT_L1,PRODUCT_L2
		DEPENDENT_FIELD_FLAG = True
		[[[KEYS]]]
			#PRIMARY_KEY,SECONDARY_KEY,ORDER
			PK0 = PRODUCT_ID
			SK0 = PRODUCT_ID, PRODUCT_DESC
			ORDER0 = 0
			PK1 = PRODUCT_L1
			SK1 = PRODUCT_L1_DESC
			ORDER1 = 1
			PK2 = PRODUCT_L2
			SK2 = PRODUCT_L2_DESC
			ORDER2 = 2
	[[DIMENSION2]]
		TABLE = dim2
		FIELDS = STORE_ID,STORE_NAME
		HIERARCHY_FLAG = True
		LINEAR_HIERARCHY_FLAG = False
		DEPENDENT_FIELD_FLAG = True
		[[[KEYS]]]
			PK0 = STORE_ID
			SK0 = STORE_NAME
			ORDER0 = 0
In [1]:
from configobj import ConfigObj
cnfg = ConfigObj('config.ini')
In [5]:
CLIENT = 'market1'
def get_config_key(l_search_key):
    from configobj import ConfigObj
    cnfg = ConfigObj('config.ini')
    for key,value in cnfg.items():
        if value['NAME'] == CLIENT:
            for k,v in value.items(): #subject(dimension1,dimension2,measures,dialect)
                if k[0:3]=='DIM' and l_search_key in v['FIELDS']:
                    if v['DEPENDENT_FIELD_FLAG']=='True':
                        for k1, v1 in v.items():  #table,fields
                            if k1=='KEYS':
                                for k2, v2 in v1.items():  #PK0,SK0
                                    if l_search_key in v2 and k2[0:2]=='SK':
                                        l_pk = cnfg[key][k][k1]['PK' + k2[2]]
                                        l_sk = cnfg[key][k][k1]['SK' + k2[2]]
                                        l_order = cnfg[key][k][k1]['ORDER' + k2[2]]
                                        l_table = cnfg[key][k]['TABLE']
                                        l_subject = k
                                        return ([l_subject, l_table, l_pk, l_sk, l_order])

l_search_key = 'PRODUCT_ID'
print(get_config_key(l_search_key))
www.000webhost.com