#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# Language Version: 3.4.x
# Last Modified: 2015-06-04 11:45:15


__all__ = []
__author__ = "刘飞 (email:13701242710@163.com)"
__version__ = "1.0.1"
import os
import json
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
try:
    print ('loading environ...')
    dbinfo = dict(dbname=os.environ['dbname'],user=os.environ['user'],password=os.environ['password'],host=os.environ['host'],port=os.environ['port'])
    print ('load success')
except Exception:
    print ('load environ faild. and running setinfo.json')
    with open(os.path.join(BASE_DIR,'dbinfo/setinfo.json'),'r') as f:
        data = json.loads(f.read(),'utf8')
        f.close()
    try:
        dbinfo = dict(dbname=data['dbname'],user=data['user'],password=data['password'],host=data['host'],port=data['port'])
    except Exception:
        import dbinfo.setinfo
        try:
            with open(os.path.join(BASE_DIR,'dbinfo/setinfo.json'),'r') as f:
                data = json.loads(f.read(),'utf8')
                f.close()
            dbinfo = dict(dbname=data['dbname'],user=data['user'],password=data['password'],host=data['host'],port=data['port'])
        except Exception:
            raise BaseException("Sorry, setinfo.json Error")
    print ('load success')