'''
@Author: hua
@Date: 2019-04-12 09:39:33
@LastEditors: hua
@LastEditTime: 2019-05-23 10:34:07
'''

import sys, os, pathlib, yaml, time
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from cacheout import Cache
#初始化配置信息
global config
conf = yaml.safe_load(open(os.getcwd()+'/app/Config/app.yaml'))
config = conf
#获取项目根目录
config['app_path'] = os.getcwd()+'/app'
config['app_path'] = config['app_path'].replace('\\','/')
#创建数据库及连接
db_url = "mysql+pymysql://{username}:{password}@{host}:{port}/{db}?charset=utf8".\
format(username=config['app']['database']['username'],password=config['app']['database']['password'],host=config['app']['database']['host'],port=config['app']['database']['port'],db=config['app']['database']['db'])
engine = create_engine(db_url)
# 创建DBSession类型:
DBSession = sessionmaker(bind=engine)
dBSession = DBSession()
#初始化缓存
cache = Cache(maxsize=2560, ttl=86400, timer=time.time, default=None)  # defaults