Browse Source

fix:python可执行文件地址配置

Roc 3 years ago
parent
commit
1ad9b79a81
3 changed files with 6 additions and 13 deletions
  1. 0 9
      models/base_from_python.go
  2. 4 4
      services/base_from_python.go
  3. 2 0
      utils/config.go

+ 0 - 9
models/base_from_python.go

@@ -264,12 +264,3 @@ type AddPythonEdbReq struct {
 	ClassifyId int    `description:"分类id"`
 	PythonCode string `description:"python代码"`
 }
-
-// EdbPythonEdbReq 编辑python代码运算指标的请求参数
-type EdbPythonEdbReq struct {
-	EdbName    string `description:"指标名称"`
-	Frequency  string `description:"频度"`
-	Unit       string `description:"单位"`
-	ClassifyId int    `description:"分类id"`
-	PythonCode string `description:"python代码"`
-}

+ 4 - 4
services/base_from_python.go

@@ -75,16 +75,16 @@ func ExecPythonCode(edbCode, reqCode string) (dataMap EdbDataFromPython, err err
 	if err != nil {
 		return
 	}
-	//defer func() {
-	//	os.Remove(pythonFile)
-	//}()
+	defer func() {
+		os.Remove(pythonFile)
+	}()
 	_, err = fileHandle.Write([]byte(pthonCodeStr))
 	if err != nil {
 		return
 	}
 	fileHandle.Close()
 
-	cmd := exec.Command("python3", pythonFile)
+	cmd := exec.Command(utils.PYTHON_PATH, pythonFile)
 	outputByte, err := cmd.Output()
 	//fmt.Println(err)
 	if err != nil {

+ 2 - 0
utils/config.go

@@ -17,6 +17,7 @@ var (
 	PYTHON_MYSQL_USER   string //python数据库链接账号
 	PYTHON_MYSQL_PASSWD string //python数据库链接密码
 	PYTHON_MYSQL_DB     string //python数据库链接数据库名
+	PYTHON_PATH         string //python可执行文件地址
 
 	REDIS_CACHE string       //缓存地址
 	Rc          *cache.Cache //redis缓存
@@ -61,6 +62,7 @@ func init() {
 	PYTHON_MYSQL_USER = config["python_mysql_user"]
 	PYTHON_MYSQL_PASSWD = config["python_mysql_passwd"]
 	PYTHON_MYSQL_DB = config["python_mysql_db"]
+	PYTHON_PATH = config["python_path"]
 
 	REDIS_CACHE = config["beego_cache"]
 	if len(REDIS_CACHE) <= 0 {