From e3a59675c1d32fd78c4e84ec4c5917cfc1fb5b1a Mon Sep 17 00:00:00 2001 From: msincenselee Date: Tue, 17 Oct 2017 19:51:09 +0800 Subject: [PATCH] sync 1.7 --- vnpy/trader/vtFunction.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/vnpy/trader/vtFunction.py b/vnpy/trader/vtFunction.py index 561960df..e4070b39 100644 --- a/vnpy/trader/vtFunction.py +++ b/vnpy/trader/vtFunction.py @@ -75,3 +75,24 @@ def getTempPath(name): path = os.path.join(tempPath, name) return path + +# JSON配置文件路径 +jsonPathDict = {} + +# ---------------------------------------------------------------------- +def getJsonPath(name, moduleFile): + """ + 获取JSON配置文件的路径: + 1. 优先从当前工作目录查找JSON文件 + 2. 若无法找到则前往模块所在目录查找 + """ + currentFolder = os.getcwd() + currentJsonPath = os.path.join(currentFolder, name) + if os.path.isfile(currentJsonPath): + jsonPathDict[name] = currentJsonPath + return currentJsonPath + + moduleFolder = os.path.abspath(os.path.dirname(moduleFile)) + moduleJsonPath = os.path.join(moduleFolder, '.', name) + jsonPathDict[name] = moduleJsonPath + return moduleJsonPath