2017-05-03 10:03:17 +00:00
|
|
|
|
# encoding: UTF-8
|
2017-04-28 13:32:17 +00:00
|
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
动态载入所有的Gateway
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
import importlib
|
|
|
|
|
import traceback
|
|
|
|
|
|
|
|
|
|
# 用来保存Gateway类的字典
|
|
|
|
|
GATEWAY_DICT = {}
|
|
|
|
|
|
2017-05-11 10:58:35 +00:00
|
|
|
|
# modified by Incense Lee
|
|
|
|
|
# 只加载指定的gateway清单
|
|
|
|
|
|
2017-04-28 13:32:17 +00:00
|
|
|
|
# 需要加载的gateway清单
|
|
|
|
|
load_gateways = ['ctpGateway']
|
|
|
|
|
|
2017-05-11 10:58:35 +00:00
|
|
|
|
# 逐一加载
|
|
|
|
|
for load_gateway in load_gateways:
|
|
|
|
|
# 模块名称需要上前缀
|
|
|
|
|
moduleName = 'gateway.' + load_gateway
|
|
|
|
|
print u'load Module:{0}'.format(moduleName)
|
|
|
|
|
try:
|
|
|
|
|
# 使用importlib动态载入模块,并保存到字典中
|
|
|
|
|
module = importlib.import_module(moduleName)
|
|
|
|
|
GATEWAY_DICT[module.gatewayName] = module
|
|
|
|
|
except Exception as ex:
|
|
|
|
|
print u'Load {0} exception:{1}'.format(moduleName, ex)
|
|
|
|
|
traceback.print_exc()
|
|
|
|
|
|
|
|
|
|
"""
|
2017-04-28 13:32:17 +00:00
|
|
|
|
# 获取目录路径
|
|
|
|
|
path = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
|
|
|
|
|
|
# 遍历strategy目录下的文件
|
|
|
|
|
for root, subdirs, files in os.walk(path):
|
|
|
|
|
if path != root:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
for foldername in subdirs:
|
|
|
|
|
# 接口目录名中必须含有Gateway
|
|
|
|
|
if 'Gateway' in foldername:
|
|
|
|
|
|
|
|
|
|
# 排除不要加载的gateway模块
|
|
|
|
|
if foldername not in load_gateways:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
# 模块名称需要上前缀
|
|
|
|
|
moduleName = 'gateway.' + foldername
|
2017-05-03 10:03:17 +00:00
|
|
|
|
print u'load Module:{0}'.format(moduleName)
|
2017-04-28 13:32:17 +00:00
|
|
|
|
try:
|
|
|
|
|
# 使用importlib动态载入模块,并保存到字典中
|
|
|
|
|
module = importlib.import_module(moduleName)
|
|
|
|
|
GATEWAY_DICT[module.gatewayName] = module
|
2017-05-03 10:03:17 +00:00
|
|
|
|
except Exception as ex:
|
|
|
|
|
print u'Load {0} exception:{1}'.format(moduleName, ex)
|
|
|
|
|
traceback.print_exc()
|
|
|
|
|
|
2017-05-11 10:58:35 +00:00
|
|
|
|
"""
|