提交 a4575bf6 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

close task#8649

上级 f0655f95
...@@ -23,7 +23,7 @@ func CommitBug(files []string) { ...@@ -23,7 +23,7 @@ func CommitBug(files []string) {
} else { } else {
stdinUtils.InputForDir(&resultDir, "", "result") stdinUtils.InputForDir(&resultDir, "", "result")
} }
resultDir = fileUtils.UpdateDir(resultDir) resultDir = fileUtils.AddPathSepIfNeeded(resultDir)
report := testingService.GetZTFTestReportForSubmit(resultDir) report := testingService.GetZTFTestReportForSubmit(resultDir)
......
...@@ -14,6 +14,6 @@ func CommitZTFTestResult(files []string, productId string, taskId string, noNeed ...@@ -14,6 +14,6 @@ func CommitZTFTestResult(files []string, productId string, taskId string, noNeed
stdinUtils.InputForDir(&resultDir, "", "result") stdinUtils.InputForDir(&resultDir, "", "result")
} }
resultDir = fileUtils.UpdateDir(resultDir) resultDir = fileUtils.AddPathSepIfNeeded(resultDir)
zentaoService.CommitZTFTestResult(resultDir, productId, taskId, noNeedConfirm) zentaoService.CommitZTFTestResult(resultDir, productId, taskId, noNeedConfirm)
} }
package serverModel package serverModel
type SysInfo struct { type SysInfo struct {
AgentDir string `json:"agentDir"`
SysArch string `json:"sysArch"` SysArch string `json:"sysArch"`
SysCores int `json:"sysCores"` SysCores int `json:"sysCores"`
......
...@@ -5,7 +5,10 @@ import ( ...@@ -5,7 +5,10 @@ import (
"fmt" "fmt"
serverModel "github.com/easysoft/zentaoatf/src/server/model" serverModel "github.com/easysoft/zentaoatf/src/server/model"
"github.com/easysoft/zentaoatf/src/server/service" "github.com/easysoft/zentaoatf/src/server/service"
serverUtils "github.com/easysoft/zentaoatf/src/server/utils" serverUtils "github.com/easysoft/zentaoatf/src/server/utils/common"
serverConst "github.com/easysoft/zentaoatf/src/server/utils/const"
constant "github.com/easysoft/zentaoatf/src/utils/const"
fileUtils "github.com/easysoft/zentaoatf/src/utils/file"
"github.com/easysoft/zentaoatf/src/utils/vari" "github.com/easysoft/zentaoatf/src/utils/vari"
"io" "io"
"io/ioutil" "io/ioutil"
...@@ -27,6 +30,15 @@ func NewServer() *Server { ...@@ -27,6 +30,15 @@ func NewServer() *Server {
return &Server{commonService: commonService, agentService: agentService, cronService: cronService} return &Server{commonService: commonService, agentService: agentService, cronService: cronService}
} }
func (s *Server) Init() {
if vari.AgentDir != "" {
return
}
home, _ := serverUtils.GetUserHome()
vari.AgentDir = fileUtils.AddPathSepIfNeeded(home + constant.PthSep + serverConst.AgentDir)
}
func (s *Server) Run() { func (s *Server) Run() {
httpServer := &http.Server{ httpServer := &http.Server{
Addr: fmt.Sprintf(":%d", vari.Port), Addr: fmt.Sprintf(":%d", vari.Port),
......
package commonUtils package serverUtils
import ( import (
"bytes"
"errors"
serverModel "github.com/easysoft/zentaoatf/src/server/model" serverModel "github.com/easysoft/zentaoatf/src/server/model"
"github.com/easysoft/zentaoatf/src/utils/vari"
"os" "os"
"os/exec"
"os/user"
"runtime" "runtime"
"strings" "strings"
) )
func GetSysInfo() (info serverModel.SysInfo) { func GetSysInfo() (info serverModel.SysInfo) {
info.AgentDir = vari.AgentDir
info.SysArch = runtime.GOARCH info.SysArch = runtime.GOARCH
info.SysCores = runtime.GOMAXPROCS(0) info.SysCores = runtime.GOMAXPROCS(0)
...@@ -23,3 +30,55 @@ func GetSysInfo() (info serverModel.SysInfo) { ...@@ -23,3 +30,55 @@ func GetSysInfo() (info serverModel.SysInfo) {
return return
} }
func GetUserHome() (string, error) {
user, err := user.Current()
if nil == err {
return user.HomeDir, nil
}
// cross compile support
if "windows" == runtime.GOOS {
return homeWindows()
}
// Unix-like system, so just assume Unix
return homeUnix()
}
func homeUnix() (string, error) {
// First prefer the HOME environmental variable
if home := os.Getenv("HOME"); home != "" {
return home, nil
}
// If that fails, try the shell
var stdout bytes.Buffer
cmd := exec.Command("sh", "-c", "eval echo ~$USER")
cmd.Stdout = &stdout
if err := cmd.Run(); err != nil {
return "", err
}
result := strings.TrimSpace(stdout.String())
if result == "" {
return "", errors.New("blank output when reading home directory")
}
return result, nil
}
func homeWindows() (string, error) {
drive := os.Getenv("HOMEDRIVE")
path := os.Getenv("HOMEPATH")
home := drive + path
if drive == "" || path == "" {
home = os.Getenv("USERPROFILE")
}
if home == "" {
return "", errors.New("HOMEDRIVE, HOMEPATH, and USERPROFILE are blank")
}
return home, nil
}
...@@ -2,4 +2,6 @@ package serverConst ...@@ -2,4 +2,6 @@ package serverConst
const ( const (
HeartBeatInterval = 5 HeartBeatInterval = 5
AgentDir = "ztf_agent"
) )
...@@ -6,6 +6,8 @@ import ( ...@@ -6,6 +6,8 @@ import (
) )
var ( var (
PthSep = string(os.PathSeparator)
ConfigVer = 1 ConfigVer = 1
ConfigFile = fmt.Sprintf("conf%sztf.conf", string(os.PathSeparator)) ConfigFile = fmt.Sprintf("conf%sztf.conf", string(os.PathSeparator))
......
...@@ -78,7 +78,7 @@ func AbosutePath(pth string) string { ...@@ -78,7 +78,7 @@ func AbosutePath(pth string) string {
pth, _ = filepath.Abs(pth) pth, _ = filepath.Abs(pth)
} }
pth = UpdateDir(pth) pth = AddPathSepIfNeeded(pth)
return pth return pth
} }
...@@ -88,7 +88,7 @@ func IsAbosutePath(pth string) bool { ...@@ -88,7 +88,7 @@ func IsAbosutePath(pth string) bool {
strings.Index(pth, ":") == 1 // windows strings.Index(pth, ":") == 1 // windows
} }
func UpdateDir(pth string) string { func AddPathSepIfNeeded(pth string) string {
sepa := string(os.PathSeparator) sepa := string(os.PathSeparator)
if strings.LastIndex(pth, sepa) < len(pth)-1 { if strings.LastIndex(pth, sepa) < len(pth)-1 {
...@@ -148,7 +148,7 @@ func GetZTFDir() string { // where ztf command in ...@@ -148,7 +148,7 @@ func GetZTFDir() string { // where ztf command in
} }
dir, _ = filepath.Abs(dir) dir, _ = filepath.Abs(dir)
dir = UpdateDir(dir) dir = AddPathSepIfNeeded(dir)
//fmt.Printf("Debug: Launch %s in %s \n", arg1, dir) //fmt.Printf("Debug: Launch %s in %s \n", arg1, dir)
return dir return dir
...@@ -195,7 +195,7 @@ func GetLogDir() string { ...@@ -195,7 +195,7 @@ func GetLogDir() string {
ret := getLogNumb(numb + 1) ret := getLogNumb(numb + 1)
return UpdateDir(path + ret) return AddPathSepIfNeeded(path + ret)
} }
func getLogNumb(numb int) string { func getLogNumb(numb int) string {
......
...@@ -40,7 +40,8 @@ var ( ...@@ -40,7 +40,8 @@ var (
Interpreter string Interpreter string
// server // server
RunMode string RunMode string
IP string IP string
Port int Port int
AgentDir string
) )
...@@ -290,7 +290,7 @@ func ReadCaseId(content string) string { ...@@ -290,7 +290,7 @@ func ReadCaseId(content string) string {
} }
func GetDependentExpect(file string) (bool, string) { func GetDependentExpect(file string) (bool, string) {
dir := fileUtils.UpdateDir(filepath.Dir(file)) dir := fileUtils.AddPathSepIfNeeded(filepath.Dir(file))
name := strings.Replace(filepath.Base(file), path.Ext(file), ".exp", -1) name := strings.Replace(filepath.Base(file), path.Ext(file), ".exp", -1)
expectIndependentFile := dir + name expectIndependentFile := dir + name
......
...@@ -75,6 +75,7 @@ func main() { ...@@ -75,6 +75,7 @@ func main() {
flagSet.IntVar(&vari.Port, "P", 8848, "") flagSet.IntVar(&vari.Port, "P", 8848, "")
flagSet.IntVar(&vari.Port, "port", 8848, "") flagSet.IntVar(&vari.Port, "port", 8848, "")
flagSet.StringVar(&vari.AgentDir, "w", "", "")
var placeholder string var placeholder string
flagSet.StringVar(&placeholder, "h", "", "") flagSet.StringVar(&placeholder, "h", "", "")
...@@ -227,6 +228,7 @@ func startServer() { ...@@ -227,6 +228,7 @@ func startServer() {
logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("start_server", vari.IP, strconv.Itoa(vari.Port)), color.FgCyan) logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("start_server", vari.IP, strconv.Itoa(vari.Port)), color.FgCyan)
server := server.NewServer() server := server.NewServer()
server.Init()
server.Run() server.Run()
return return
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册