|
@@ -10,8 +10,6 @@ import (
|
|
|
"os"
|
|
|
"os/exec"
|
|
|
"reflect"
|
|
|
- "regexp"
|
|
|
- "strconv"
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
@@ -88,9 +86,6 @@ func ExecPythonCode(edbCode, reqCode string) (dataMap models.EdbDataFromPython,
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
- // 获取指定头部的换行符数量
|
|
|
- frontNumN := getPythonFrontNumN()
|
|
|
-
|
|
|
defer func() {
|
|
|
os.Remove(pythonFile)
|
|
|
}()
|
|
@@ -107,12 +102,6 @@ func ExecPythonCode(edbCode, reqCode string) (dataMap models.EdbDataFromPython,
|
|
|
err = cmd.Run()
|
|
|
if err != nil {
|
|
|
errMsg = errMsgOut.String()
|
|
|
- // 替换Python文件名
|
|
|
- errMsg = strings.Replace(errMsgOut.String(), pythonFile, "python file", -1)
|
|
|
- tmpErrMsg, tmpErr := replaceLineNumber(errMsg, frontNumN)
|
|
|
- if tmpErr == nil {
|
|
|
- errMsg = tmpErrMsg
|
|
|
- }
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -220,39 +209,3 @@ func getPythonFront3Str() string {
|
|
|
func getPythonLaterStr() string {
|
|
|
return "\n\nprint(\"result=\", result.to_json())\ndb.close()"
|
|
|
}
|
|
|
-
|
|
|
-// getPythonFrontNumN
|
|
|
-// @Description: 获取指定头部的换行符数量
|
|
|
-// @author: Roc
|
|
|
-// @datetime 2024-05-08 10:15:51
|
|
|
-// @return int
|
|
|
-func getPythonFrontNumN() int {
|
|
|
- re := regexp.MustCompile("\n")
|
|
|
- matches := re.FindAllStringIndex(getPythonFrontStr(), -1)
|
|
|
- return len(matches) // 每个匹配的结果对应一个换行符
|
|
|
-}
|
|
|
-
|
|
|
-func replaceLineNumber(errorText string, frontNumber int) (string, error) {
|
|
|
- // 编译正则表达式,匹配 "line" 后面跟一个或多个空格,再跟一个或多个数字的模式
|
|
|
- re := regexp.MustCompile(`line\s+\d+`)
|
|
|
- match := re.FindStringSubmatch(errorText)
|
|
|
- if match == nil {
|
|
|
- return "", fmt.Errorf("未找到行号信息")
|
|
|
- }
|
|
|
-
|
|
|
- // 从匹配到的字符串中提取行号数字
|
|
|
- oldLineNumberStr := match[0]
|
|
|
- oldLineNumber, err := strconv.Atoi(oldLineNumberStr[len("line "):])
|
|
|
- if err != nil {
|
|
|
- return "", fmt.Errorf("解析行号失败: %v", err)
|
|
|
- }
|
|
|
-
|
|
|
- newLineNumber := oldLineNumber - frontNumber
|
|
|
-
|
|
|
- // 构建新的行号字符串
|
|
|
- newLineNumberStr := fmt.Sprintf("line %d", newLineNumber)
|
|
|
-
|
|
|
- // 替换原来的行号为新的行号
|
|
|
- newErrorText := re.ReplaceAllString(errorText, newLineNumberStr)
|
|
|
- return newErrorText, nil
|
|
|
-}
|