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

close task#8649

上级 f0655f95
......@@ -23,7 +23,7 @@ func CommitBug(files []string) {
} else {
stdinUtils.InputForDir(&resultDir, "", "result")
}
resultDir = fileUtils.UpdateDir(resultDir)
resultDir = fileUtils.AddPathSepIfNeeded(resultDir)
report := testingService.GetZTFTestReportForSubmit(resultDir)
......
......@@ -14,6 +14,6 @@ func CommitZTFTestResult(files []string, productId string, taskId string, noNeed
stdinUtils.InputForDir(&resultDir, "", "result")
}
resultDir = fileUtils.UpdateDir(resultDir)
resultDir = fileUtils.AddPathSepIfNeeded(resultDir)
zentaoService.CommitZTFTestResult(resultDir, productId, taskId, noNeedConfirm)
}
package serverModel
type SysInfo struct {
AgentDir string `json:"agentDir"`
SysArch string `json:"sysArch"`
SysCores int `json:"sysCores"`
......
......@@ -5,7 +5,10 @@ import (
"fmt"
serverModel "github.com/easysoft/zentaoatf/src/server/model"
"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"
"io"
"io/ioutil"
......@@ -27,6 +30,15 @@ func NewServer() *Server {
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() {
httpServer := &http.Server{
Addr: fmt.Sprintf(":%d", vari.Port),
......
package commonUtils
package serverUtils
import (
"bytes"
"errors"
serverModel "github.com/easysoft/zentaoatf/src/server/model"
"github.com/easysoft/zentaoatf/src/utils/vari"
"os"
"os/exec"
"os/user"
"runtime"
"strings"
)
func GetSysInfo() (info serverModel.SysInfo) {
info.AgentDir = vari.AgentDir
info.SysArch = runtime.GOARCH
info.SysCores = runtime.GOMAXPROCS(0)
......@@ -23,3 +30,55 @@ func GetSysInfo() (info serverModel.SysInfo) {
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
const (
HeartBeatInterval = 5
AgentDir = "ztf_agent"
)
......@@ -6,6 +6,8 @@ import (
)
var (
PthSep = string(os.PathSeparator)
ConfigVer = 1
ConfigFile = fmt.Sprintf("conf%sztf.conf", string(os.PathSeparator))
......
......@@ -78,7 +78,7 @@ func AbosutePath(pth string) string {
pth, _ = filepath.Abs(pth)
}
pth = UpdateDir(pth)
pth = AddPathSepIfNeeded(pth)
return pth
}
......@@ -88,7 +88,7 @@ func IsAbosutePath(pth string) bool {
strings.Index(pth, ":") == 1 // windows
}
func UpdateDir(pth string) string {
func AddPathSepIfNeeded(pth string) string {
sepa := string(os.PathSeparator)
if strings.LastIndex(pth, sepa) < len(pth)-1 {
......@@ -148,7 +148,7 @@ func GetZTFDir() string { // where ztf command in
}
dir, _ = filepath.Abs(dir)
dir = UpdateDir(dir)
dir = AddPathSepIfNeeded(dir)
//fmt.Printf("Debug: Launch %s in %s \n", arg1, dir)
return dir
......@@ -195,7 +195,7 @@ func GetLogDir() string {
ret := getLogNumb(numb + 1)
return UpdateDir(path + ret)
return AddPathSepIfNeeded(path + ret)
}
func getLogNumb(numb int) string {
......
......@@ -40,7 +40,8 @@ var (
Interpreter string
// server
RunMode string
IP string
Port int
RunMode string
IP string
Port int
AgentDir string
)
......@@ -290,7 +290,7 @@ func ReadCaseId(content string) 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)
expectIndependentFile := dir + name
......
......@@ -75,6 +75,7 @@ func main() {
flagSet.IntVar(&vari.Port, "P", 8848, "")
flagSet.IntVar(&vari.Port, "port", 8848, "")
flagSet.StringVar(&vari.AgentDir, "w", "", "")
var placeholder string
flagSet.StringVar(&placeholder, "h", "", "")
......@@ -227,6 +228,7 @@ func startServer() {
logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("start_server", vari.IP, strconv.Itoa(vari.Port)), color.FgCyan)
server := server.NewServer()
server.Init()
server.Run()
return
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册