Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zentaoatf
提交
0937d2b7
Z
zentaoatf
项目概览
易企天创
/
zentaoatf
大约 1 年 前同步成功
通知
11
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
3
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Z
zentaoatf
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
3
Issue
3
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0937d2b7
编写于
12月 22, 2020
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
upgrade
上级
c705af98
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
113 addition
and
25 deletion
+113
-25
src/action/unitTest.go
src/action/unitTest.go
+1
-1
src/action/ztfTest.go
src/action/ztfTest.go
+1
-1
src/server/service/upgrade.go
src/server/service/upgrade.go
+65
-4
src/server/utils/const/const.go
src/server/utils/const/const.go
+4
-2
src/utils/assert/assert.go
src/utils/assert/assert.go
+2
-2
src/utils/common/utils.go
src/utils/common/utils.go
+1
-1
src/utils/config/config.go
src/utils/config/config.go
+1
-1
src/utils/const/const.go
src/utils/const/const.go
+7
-3
src/utils/display/screen.go
src/utils/display/screen.go
+1
-1
src/utils/file/file.go
src/utils/file/file.go
+4
-4
src/utils/log/print.go
src/utils/log/print.go
+4
-3
src/utils/shell/shell.go
src/utils/shell/shell.go
+21
-2
src/utils/vari/var.go
src/utils/vari/var.go
+1
-0
未找到文件。
src/action/unitTest.go
浏览文件 @
0937d2b7
...
...
@@ -9,7 +9,7 @@ import (
func
RunUnitTest
(
cmdStr
string
)
string
{
startTime
:=
time2
.
Now
()
.
Unix
()
shellUtils
.
Exe
Shell
WithOutput
(
cmdStr
)
shellUtils
.
Exe
App
WithOutput
(
cmdStr
)
endTime
:=
time2
.
Now
()
.
Unix
()
testSuites
,
resultDir
:=
testingService
.
RetrieveUnitResult
()
...
...
src/action/ztfTest.go
浏览文件 @
0937d2b7
...
...
@@ -158,7 +158,7 @@ func runCases(cases []string) {
var
report
=
model
.
TestReport
{
Env
:
commonUtils
.
GetOs
(),
Pass
:
0
,
Fail
:
0
,
Total
:
0
,
FuncResult
:
make
([]
model
.
FuncResult
,
0
)}
report
.
TestType
=
"func"
report
.
TestFrame
=
"ztf"
report
.
TestFrame
=
constant
.
AppName
pathMaxWidth
:=
0
numbMaxWidth
:=
0
...
...
src/server/service/upgrade.go
浏览文件 @
0937d2b7
...
...
@@ -5,9 +5,16 @@ import (
serverUtils
"github.com/easysoft/zentaoatf/src/server/utils/common"
serverConst
"github.com/easysoft/zentaoatf/src/server/utils/const"
commonUtils
"github.com/easysoft/zentaoatf/src/utils/common"
configUtils
"github.com/easysoft/zentaoatf/src/utils/config"
constant
"github.com/easysoft/zentaoatf/src/utils/const"
fileUtils
"github.com/easysoft/zentaoatf/src/utils/file"
logUtils
"github.com/easysoft/zentaoatf/src/utils/log"
"github.com/easysoft/zentaoatf/src/utils/vari"
"github.com/fatih/color"
"github.com/mholt/archiver/v3"
"github.com/sirupsen/logrus"
"os"
"os/exec"
"strconv"
"strings"
)
...
...
@@ -28,12 +35,16 @@ func (s *UpgradeService) CheckUpgrade() {
content
:=
strings
.
TrimSpace
(
fileUtils
.
ReadFile
(
pth
))
version
,
_
:=
strconv
.
ParseFloat
(
content
,
64
)
if
vari
.
Config
.
Version
<
version
{
s
.
Upgrade
(
version
)
versionStr
:=
fmt
.
Sprintf
(
"%.1f"
,
version
)
err
:=
s
.
DownloadVersion
(
versionStr
)
if
err
==
nil
{
s
.
RestartVersion
(
versionStr
)
}
}
}
func
(
s
*
UpgradeService
)
Upgrade
(
ver
float64
)
(
err
error
)
{
version
:=
fmt
.
Sprintf
(
"%.1f"
,
ver
)
func
(
s
*
UpgradeService
)
DownloadVersion
(
version
string
)
(
err
error
)
{
os
:=
commonUtils
.
GetOs
()
if
commonUtils
.
IsWin
()
{
...
...
@@ -46,9 +57,59 @@ func (s *UpgradeService) Upgrade(ver float64) (err error) {
err
=
serverUtils
.
Download
(
url
,
pth
)
if
err
==
nil
{
fileUtils
.
RmDir
(
dir
)
fileUtils
.
MkDirIfNeeded
(
dir
)
archiver
.
Unarchive
(
pth
,
dir
)
err
=
archiver
.
Unarchive
(
pth
,
dir
)
}
return
}
func
(
s
*
UpgradeService
)
RestartVersion
(
version
string
)
(
err
error
)
{
currExePath
:=
vari
.
ZTFDir
+
constant
.
AppName
bakExePath
:=
currExePath
+
"_bak"
newExePath
:=
vari
.
AgentLogDir
+
version
+
constant
.
PthSep
+
constant
.
AppName
+
constant
.
PthSep
+
constant
.
AppName
if
commonUtils
.
IsWin
()
{
currExePath
+=
".exe"
bakExePath
+=
".exe"
newExePath
+=
".exe"
}
logrus
.
Println
(
currExePath
)
if
!
vari
.
IsDebug
{
err
=
os
.
Rename
(
currExePath
,
bakExePath
)
}
_
,
err
=
fileUtils
.
CopyFile
(
newExePath
,
currExePath
)
cmdStr
:=
constant
.
AppName
var
cmd
*
exec
.
Cmd
if
commonUtils
.
IsWin
()
{
cmdStr
+=
".exe"
cmd
=
exec
.
Command
(
"cmd"
,
"/C"
,
cmdStr
)
}
else
{
cmd
=
exec
.
Command
(
"/bin/bash"
,
"-c"
,
cmdStr
)
}
cmd
.
Dir
=
vari
.
ZTFDir
err
=
cmd
.
Start
()
if
err
!=
nil
{
logUtils
.
PrintToWithColor
(
"fail to start new app, err: "
+
err
.
Error
(),
color
.
FgRed
)
return
}
err
=
cmd
.
Wait
()
if
err
!=
nil
{
logUtils
.
PrintToWithColor
(
"fail to start new app, err: "
+
err
.
Error
(),
color
.
FgRed
)
return
}
else
{
logUtils
.
PrintToWithColor
(
"success to start update to new version "
+
version
,
color
.
FgCyan
)
vari
.
Config
.
Version
,
_
=
strconv
.
ParseFloat
(
version
,
64
)
configUtils
.
SaveConfig
(
vari
.
Config
)
}
os
.
Exit
(
0
)
return
}
src/server/utils/const/const.go
浏览文件 @
0937d2b7
package
serverConst
import
constant
"github.com/easysoft/zentaoatf/src/utils/const"
const
(
HeartBeatInterval
=
5
CheckUpgradeInterval
=
5
...
...
@@ -7,7 +9,7 @@ const (
AgentRunTime
=
30
*
60
AgentLogDir
=
"log-agent"
QiNiuURL
=
"https://dl.cnezsoft.com/
ztf
/"
QiNiuURL
=
"https://dl.cnezsoft.com/
"
+
constant
.
AppName
+
"
/"
AgentUpgradeURL
=
QiNiuURL
+
"version.txt"
AgentDownloadURL
=
QiNiuURL
+
"%s/%s/
ztf
.zip"
AgentDownloadURL
=
QiNiuURL
+
"%s/%s/
"
+
constant
.
AppName
+
"
.zip"
)
src/utils/assert/assert.go
浏览文件 @
0937d2b7
...
...
@@ -57,7 +57,7 @@ func GetAllScriptsInDir(path string, files *[]string) error {
for
_
,
fi
:=
range
dir
{
name
:=
fi
.
Name
()
if
commonUtils
.
I
ng
oreFile
(
name
)
{
if
commonUtils
.
I
gn
oreFile
(
name
)
{
continue
}
...
...
@@ -85,7 +85,7 @@ func GetScriptByIdsInDir(dirPth string, idMap map[int]string, files *[]string) e
sep
:=
string
(
os
.
PathSeparator
)
if
commonUtils
.
I
ng
oreFile
(
dirPth
)
{
if
commonUtils
.
I
gn
oreFile
(
dirPth
)
{
return
nil
}
...
...
src/utils/common/utils.go
浏览文件 @
0937d2b7
...
...
@@ -73,7 +73,7 @@ func AddSlashForUrl(url string) string {
return
url
}
func
I
ng
oreFile
(
path
string
)
bool
{
func
I
gn
oreFile
(
path
string
)
bool
{
path
=
filepath
.
Base
(
path
)
if
strings
.
Index
(
path
,
"."
)
==
0
||
...
...
src/utils/config/config.go
浏览文件 @
0937d2b7
...
...
@@ -21,7 +21,7 @@ import (
)
func
InitConfig
()
{
vari
.
ZTFDir
=
fileUtils
.
GetZTFDir
()
vari
.
ZTFDir
,
vari
.
IsDebug
=
fileUtils
.
GetZTFDir
()
CheckConfigPermission
()
vari
.
ConfigPath
=
vari
.
ZTFDir
+
constant
.
ConfigFile
...
...
src/utils/const/const.go
浏览文件 @
0937d2b7
...
...
@@ -5,13 +5,17 @@ import (
"os"
)
const
(
AppName
=
"ztf"
ConfigVer
=
1.0
)
var
(
PthSep
=
string
(
os
.
PathSeparator
)
ConfigVer
=
1.0
ConfigFile
=
fmt
.
Sprintf
(
"conf%sztf.conf"
,
string
(
os
.
PathSeparator
))
ConfigFile
=
fmt
.
Sprintf
(
"conf%s%s.conf"
,
string
(
os
.
PathSeparator
),
AppName
)
UrlZen
t
aoSettings
=
"zentaoSettings"
UrlZen
T
aoSettings
=
"zentaoSettings"
UrlImportProject
=
"importProject"
UrlSubmitResult
=
"submitResults"
UrlReportBug
=
"reportBug"
...
...
src/utils/display/screen.go
浏览文件 @
0937d2b7
...
...
@@ -17,7 +17,7 @@ func GetScreenSize() (int, int) {
if
commonUtils
.
IsWin
()
{
cmd
=
"mode"
// tested for win7
out
,
_
:=
shellUtils
.
ExeS
hell
(
cmd
)
out
,
_
:=
shellUtils
.
ExeS
ysCmd
(
cmd
)
//out := `设备状态 CON:
// ---------
...
...
src/utils/file/file.go
浏览文件 @
0937d2b7
...
...
@@ -150,25 +150,25 @@ func ReadResData(path string) string {
return
jsonStr
}
func
GetZTFDir
()
string
{
// where ztf command in
var
dir
string
func
GetZTFDir
()
(
dir
string
,
isDebug
bool
)
{
// where ztf command in
arg1
:=
strings
.
ToLower
(
os
.
Args
[
0
])
name
:=
filepath
.
Base
(
arg1
)
if
strings
.
Index
(
name
,
"ztf"
)
==
0
&&
strings
.
Index
(
arg1
,
"go-build"
)
<
0
{
if
strings
.
Index
(
name
,
constant
.
AppName
)
==
0
&&
strings
.
Index
(
arg1
,
"go-build"
)
<
0
{
p
,
_
:=
exec
.
LookPath
(
os
.
Args
[
0
])
if
strings
.
Index
(
p
,
string
(
os
.
PathSeparator
))
>
-
1
{
dir
=
p
[
:
strings
.
LastIndex
(
p
,
string
(
os
.
PathSeparator
))]
}
}
else
{
// debug
dir
,
_
=
os
.
Getwd
()
isDebug
=
true
}
dir
,
_
=
filepath
.
Abs
(
dir
)
dir
=
AddPathSepIfNeeded
(
dir
)
//fmt.Printf("Debug: Launch %s in %s \n", arg1, dir)
return
dir
return
}
func
GetLogDir
()
string
{
...
...
src/utils/log/print.go
浏览文件 @
0937d2b7
...
...
@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
commonUtils
"github.com/easysoft/zentaoatf/src/utils/common"
constant
"github.com/easysoft/zentaoatf/src/utils/const"
fileUtils
"github.com/easysoft/zentaoatf/src/utils/file"
"github.com/fatih/color"
"os"
...
...
@@ -20,7 +21,7 @@ func PrintUsage() {
PrintToWithColor
(
"Usage: "
,
color
.
FgCyan
)
usage
:=
fileUtils
.
ReadResData
(
usageFile
)
exeFile
:=
"ztf"
exeFile
:=
constant
.
AppName
if
commonUtils
.
IsWin
()
{
exeFile
+=
".exe"
}
...
...
@@ -33,8 +34,8 @@ func PrintUsage() {
regx
,
_
:=
regexp
.
Compile
(
`\\`
)
sample
=
regx
.
ReplaceAllString
(
sample
,
"/"
)
regx
,
_
=
regexp
.
Compile
(
`ztf
.exe`
)
sample
=
regx
.
ReplaceAllString
(
sample
,
"ztf"
)
regx
,
_
=
regexp
.
Compile
(
constant
.
AppName
+
`
.exe`
)
sample
=
regx
.
ReplaceAllString
(
sample
,
constant
.
AppName
)
regx
,
_
=
regexp
.
Compile
(
`/bat/`
)
sample
=
regx
.
ReplaceAllString
(
sample
,
"/shell/"
)
...
...
src/utils/shell/shell.go
浏览文件 @
0937d2b7
...
...
@@ -16,7 +16,7 @@ import (
"strings"
)
func
ExeS
hell
(
cmdStr
string
)
(
string
,
error
)
{
func
ExeS
ysCmd
(
cmdStr
string
)
(
string
,
error
)
{
var
cmd
*
exec
.
Cmd
if
commonUtils
.
IsWin
()
{
cmd
=
exec
.
Command
(
cmdStr
)
...
...
@@ -31,8 +31,27 @@ func ExeShell(cmdStr string) (string, error) {
return
out
.
String
(),
err
}
func
ExeAppInDir
(
cmdStr
string
,
dir
string
)
(
string
,
error
)
{
var
cmd
*
exec
.
Cmd
if
commonUtils
.
IsWin
()
{
cmd
=
exec
.
Command
(
"cmd"
,
"/C"
,
cmdStr
)
}
else
{
cmd
=
exec
.
Command
(
"/bin/bash"
,
"-c"
,
cmdStr
)
}
if
dir
!=
""
{
cmd
.
Dir
=
dir
}
var
out
bytes
.
Buffer
cmd
.
Stdout
=
&
out
err
:=
cmd
.
Run
()
return
out
.
String
(),
err
}
func
Exe
Shell
WithOutput
(
cmdStr
string
)
[]
string
{
func
Exe
App
WithOutput
(
cmdStr
string
)
[]
string
{
var
cmd
*
exec
.
Cmd
if
commonUtils
.
IsWin
()
{
cmd
=
exec
.
Command
(
"cmd"
,
"/C"
,
cmdStr
)
...
...
src/utils/vari/var.go
浏览文件 @
0937d2b7
...
...
@@ -6,6 +6,7 @@ import (
)
var
(
IsDebug
bool
Config
=
model
.
Config
{}
Cui
*
gocui
.
Gui
MainViewHeight
int
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录