mirror of
https://shylinux.com/x/icebergs
synced 2025-05-02 19:47:02 +08:00
opt git
This commit is contained in:
parent
1a787a9a14
commit
9e8563071a
@ -14,7 +14,7 @@ func _role_keys(key ...string) string {
|
||||
return strings.TrimPrefix(strings.TrimSuffix(strings.ReplaceAll(path.Join(strings.ReplaceAll(kit.Keys(key), ice.PT, ice.PS)), ice.PS, ice.PT), ice.PT), ice.PT)
|
||||
}
|
||||
func _role_set(m *ice.Message, role, zone, key string, status bool) {
|
||||
m.Logs(mdb.INSERT, ROLE, role, zone, key)
|
||||
m.Logs(mdb.INSERT, mdb.KEY, "aaa.role", ROLE, role, zone, key)
|
||||
mdb.HashSelectUpdate(m, role, func(value ice.Map) { value[zone].(ice.Map)[key] = status })
|
||||
}
|
||||
func _role_white(m *ice.Message, role, key string) { _role_set(m, role, WHITE, key, true) }
|
||||
|
@ -20,14 +20,14 @@ func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd {
|
||||
for i := 0; i < len(env)-1; i += 2 {
|
||||
if env[i] == PATH {
|
||||
if bin = _system_find(m, arg[0], strings.Split(env[i+1], ice.DF)...); bin != "" {
|
||||
m.Logs(mdb.SELECT, "env path cmd", bin)
|
||||
m.Logs(mdb.SELECT, "envpath cmd", bin)
|
||||
}
|
||||
}
|
||||
}
|
||||
if bin == "" {
|
||||
if text := kit.ReadFile(ice.ETC_PATH); len(text) > 0 {
|
||||
if bin = _system_find(m, arg[0], strings.Split(text, ice.NL)...); bin != "" {
|
||||
m.Logs(mdb.SELECT, "etc path cmd", bin)
|
||||
m.Logs(mdb.SELECT, "etcpath cmd", bin)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -54,7 +54,7 @@ func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd {
|
||||
}
|
||||
cmd := exec.Command(bin, arg[1:]...)
|
||||
if cmd.Dir = kit.TrimPath(m.Option(CMD_DIR)); len(cmd.Dir) > 0 {
|
||||
if m.Logs(mdb.EXPORT, CMD_DIR, cmd.Dir); !nfs.ExistsFile(m, cmd.Dir) {
|
||||
if m.Logs(mdb.PARAMS, CMD_DIR, cmd.Dir); !nfs.ExistsFile(m, cmd.Dir) {
|
||||
file.MkdirAll(cmd.Dir, ice.MOD_DIR)
|
||||
}
|
||||
}
|
||||
@ -62,7 +62,7 @@ func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd {
|
||||
cmd.Env = append(cmd.Env, kit.Format("%s=%s", env[i], env[i+1]))
|
||||
}
|
||||
if len(cmd.Env) > 0 {
|
||||
m.Logs(mdb.EXPORT, CMD_ENV, kit.Format(cmd.Env))
|
||||
m.Logs(mdb.PARAMS, CMD_ENV, kit.Format(cmd.Env))
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
@ -141,7 +141,7 @@ const SYSTEM = "system"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SYSTEM: {Name: "system cmd run", Help: "系统命令", Actions: ice.Actions{
|
||||
SYSTEM: {Name: "system cmd auto", Help: "系统命令", Actions: ice.MergeActions(ice.Actions{
|
||||
nfs.PUSH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
for _, p := range arg {
|
||||
if !strings.Contains(m.Cmdx(nfs.CAT, ice.ETC_PATH), p) {
|
||||
@ -160,10 +160,12 @@ func init() {
|
||||
m.Option(CMD_ENV, "COLUMNS", kit.Int(kit.Select("1920", m.Option(ice.WIDTH)))/12)
|
||||
m.Echo(SystemCmds(m, "man %s %s|col -b", kit.Select("", arg[1], arg[1] != "1"), arg[0]))
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
}, mdb.HashAction(mdb.SHORT, "cmd", mdb.FIELD, "time,cmd,arg")), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
mdb.HashSelect(m)
|
||||
return
|
||||
}
|
||||
mdb.HashCreate(m.Spawn(), ice.CMD, arg[0], ice.ARG, kit.Join(arg[1:], ice.SP))
|
||||
if _system_exec(m, _system_cmd(m, kit.Simple(kit.Split(arg[0]), arg[1:])...)); IsSuccess(m) && m.Append(CMD_ERR) == "" {
|
||||
m.SetAppend()
|
||||
}
|
||||
|
17
base/log/error.go
Normal file
17
base/log/error.go
Normal file
@ -0,0 +1,17 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"path"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
)
|
||||
const ERROR = "error"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
ERROR: {Name: "error auto", Help: "错误", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(nfs.CAT, path.Join(ice.VAR_LOG, "error.log"))
|
||||
}},
|
||||
})
|
||||
}
|
@ -81,8 +81,6 @@ const (
|
||||
)
|
||||
const (
|
||||
BENCH = "bench"
|
||||
WATCH = "watch"
|
||||
ERROR = "error"
|
||||
TRACE = "trace"
|
||||
)
|
||||
const (
|
||||
|
35
base/log/watch.go
Normal file
35
base/log/watch.go
Normal file
@ -0,0 +1,35 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const WATCH = "watch"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
WATCH: {Name: "watch auto", Help: "记录", Hand: func(m *ice.Message, arg ...string) {
|
||||
operate := map[string]int{}
|
||||
for _, line := range strings.Split(m.Cmdx(nfs.CAT, path.Join(ice.VAR_LOG, "watch.log")), ice.NL) {
|
||||
ls := kit.Split(line, "", " ", " ")
|
||||
if len(ls) < 5 {
|
||||
continue
|
||||
}
|
||||
m.Push(mdb.TIME, ls[0]+ice.SP+ls[1])
|
||||
m.Push("order", ls[2])
|
||||
m.Push("ship", ls[3])
|
||||
m.Push("source", kit.Slice(ls, -1)[0])
|
||||
m.Push("operate", ls[4])
|
||||
m.Push("content", kit.Join(kit.Slice(ls, 5, -1), ice.SP))
|
||||
operate[ls[4]]++
|
||||
}
|
||||
m.StatusTimeCount(operate)
|
||||
}},
|
||||
})
|
||||
}
|
@ -294,7 +294,7 @@ func HashPrunesValue(m *ice.Message, field, value string) {
|
||||
}
|
||||
func HashCreateDeferRemove(m *ice.Message, arg ...Any) func() {
|
||||
h := HashCreate(m, arg...)
|
||||
return func() { HashRemove(m, HASH, h) }
|
||||
return func() { HashRemove(m.SetResult(), HASH, h) }
|
||||
}
|
||||
func HashModifyDeferRemove(m *ice.Message, arg ...Any) func() {
|
||||
HashModify(m, arg...)
|
||||
|
@ -117,8 +117,12 @@ func ListAction(arg ...ice.Any) ice.Actions {
|
||||
func PageListAction(arg ...ice.Any) ice.Actions {
|
||||
return ice.MergeActions(ice.Actions{
|
||||
SELECT: {Name: "select id auto insert page", Hand: func(m *ice.Message, arg ...string) { PageListSelect(m, arg...) }},
|
||||
NEXT: {Hand: func(m *ice.Message, arg ...string) { NextPage(m, kit.Select(m.Config(COUNT), arg, 0), kit.Slice(arg, 1)...) }},
|
||||
PREV: {Hand: func(m *ice.Message, arg ...string) { PrevPageLimit(m, kit.Select(m.Config(COUNT), arg, 0), kit.Slice(arg, 1)...) }},
|
||||
NEXT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
NextPage(m, kit.Select(m.Config(COUNT), arg, 0), kit.Slice(arg, 1)...)
|
||||
}},
|
||||
PREV: {Hand: func(m *ice.Message, arg ...string) {
|
||||
PrevPageLimit(m, kit.Select(m.Config(COUNT), arg, 0), kit.Slice(arg, 1)...)
|
||||
}},
|
||||
}, ListAction(arg...))
|
||||
}
|
||||
func ListField(m *ice.Message) string { return kit.Select(LIST_FIELD, m.Config(FIELD)) }
|
||||
|
@ -113,6 +113,7 @@ const (
|
||||
RANDOM = "random"
|
||||
ACTION = "action"
|
||||
FIELDS = "fields"
|
||||
PARAMS = "params"
|
||||
|
||||
INPUTS = "inputs"
|
||||
CREATE = "create"
|
||||
|
@ -179,7 +179,6 @@ func init() {
|
||||
return
|
||||
}
|
||||
fields := kit.Split(kit.Select(kit.Select(DIR_DEF_FIELDS, m.OptionFields()), kit.Join(kit.Slice(arg, 1))))
|
||||
m.Logs(mdb.SELECT, DIR_ROOT, m.Option(DIR_ROOT), DIR_REG, m.Option(DIR_REG), mdb.FIELD, kit.Join(fields, ice.FS))
|
||||
_dir_list(m, root, dir, 0, m.Option(DIR_DEEP) == ice.TRUE, kit.Select(TYPE_BOTH, m.Option(DIR_TYPE)), kit.Regexp(m.Option(DIR_REG)), fields)
|
||||
m.Sort(PATH).StatusTimeCount()
|
||||
}},
|
||||
|
@ -179,3 +179,8 @@ func NewReadCloser(r io.Reader) io.ReadCloser {
|
||||
func NewCloser(c func() error) io.WriteCloser {
|
||||
return file.NewWriteCloser(func(buf []byte) (int, error) { return 0, nil }, c)
|
||||
}
|
||||
|
||||
func CatFile(m *ice.Message, p string) string {
|
||||
b, _ := ioutil.ReadFile(p)
|
||||
return strings.TrimSpace(string(b))
|
||||
}
|
||||
|
@ -44,7 +44,6 @@ func _tar_list(m *ice.Message, p string, cb func(*tar.Header, *tar.Reader, int))
|
||||
cb(h, r, i)
|
||||
}
|
||||
m.StatusTimeCount(mdb.TOTAL, i)
|
||||
m.Debug("what %v", i)
|
||||
return m
|
||||
default:
|
||||
return m
|
||||
@ -61,7 +60,7 @@ func init() {
|
||||
mdb.NEXT: {Hand: func(m *ice.Message, arg ...string) { mdb.PrevPage(m, arg[0], kit.Slice(arg, 1)...) }},
|
||||
mdb.PREV: {Hand: func(m *ice.Message, arg ...string) { mdb.NextPageLimit(m, arg[0], kit.Slice(arg, 1)...) }},
|
||||
mdb.EXPORT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
list := map[string]bool{}
|
||||
list, size := map[string]bool{}, int64(0)
|
||||
_tar_list(m, m.Option(PATH), func(h *tar.Header, r *tar.Reader, i int) {
|
||||
if h.Name == m.Option(FILE) || m.Option(FILE) == "" {
|
||||
p := path.Join(path.Dir(m.Option(PATH)), h.Name)
|
||||
@ -79,9 +78,11 @@ func init() {
|
||||
defer m.Cmdy(DIR, p, "time,path,size")
|
||||
defer m.Cmdy(CAT, p)
|
||||
}
|
||||
n, e := io.Copy(f, r)
|
||||
m.Logs(mdb.EXPORT, FILE, p, SIZE, n).Warn(e)
|
||||
os.Chmod(p, os.FileMode(h.Mode))
|
||||
if n, e := io.Copy(f, r); !m.Warn(e) {
|
||||
size += n
|
||||
m.Logs(mdb.EXPORT, LINE, i, SIZE, kit.FmtSize(size), FILE, p, SIZE, kit.FmtSize(n))
|
||||
os.Chmod(p, os.FileMode(h.Mode))
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -113,3 +114,6 @@ func ReadAll(m *ice.Message, r io.Reader) []byte {
|
||||
return buf
|
||||
}
|
||||
}
|
||||
func TarExport(m *ice.Message, path string, file ...string) {
|
||||
m.Cmd(TAR, mdb.EXPORT, ice.Maps{PATH: path, FILE: kit.Select("", file, 0)})
|
||||
}
|
||||
|
@ -79,10 +79,7 @@ func (f *Frame) change(m *ice.Message, ls []string) []string {
|
||||
if target == "~" {
|
||||
target = ""
|
||||
}
|
||||
m.Spawn(f.target).Search(target+ice.PT, func(p *ice.Context, s *ice.Context) {
|
||||
m.Logs(mdb.SELECT, ctx.CONTEXT, s.Name)
|
||||
f.target = s
|
||||
})
|
||||
m.Spawn(f.target).Search(target+ice.PT, func(p *ice.Context, s *ice.Context) { f.target = s })
|
||||
}
|
||||
return ls
|
||||
}
|
||||
|
@ -55,7 +55,8 @@ func init() {
|
||||
return
|
||||
}
|
||||
current := kit.Int(m.Config(BEGIN))
|
||||
m.Cmd(nfs.DIR, nfs.PWD, kit.Dict(nfs.DIR_ROOT, ice.USR_LOCAL_DAEMON), func(value ice.Maps) {
|
||||
m.Option(nfs.DIR_ROOT, ice.USR_LOCAL_DAEMON)
|
||||
m.Cmd(nfs.DIR, nfs.PWD, func(value ice.Maps) {
|
||||
bin := m.CmdAppend(nfs.DIR, path.Join(value[nfs.PATH], ice.BIN), nfs.PATH)
|
||||
if bin == "" {
|
||||
bin = m.CmdAppend(nfs.DIR, path.Join(value[nfs.PATH], "sbin"), nfs.PATH)
|
||||
|
@ -73,16 +73,20 @@ func _cache_upload(m *ice.Message, r *http.Request) (mime, name, file, size stri
|
||||
func _cache_download(m *ice.Message, r *http.Response, file string, cb ice.Any) string {
|
||||
if f, p, e := miss.CreateFile(file); !m.Warn(e, ice.ErrNotValid, DOWNLOAD) {
|
||||
defer f.Close()
|
||||
last, step, bufs := 0, 10, 10*ice.MOD_BUFS
|
||||
if cb == nil {
|
||||
cb = func(size, total, count int) {
|
||||
if count/step != last {
|
||||
m.Logs(mdb.EXPORT, nfs.FILE, p, nfs.SIZE, size, mdb.TOTAL, total, mdb.COUNT, count)
|
||||
last, base := 0, 10
|
||||
nfs.CopyFile(m, f, r.Body, base*ice.MOD_BUFS, kit.Int(kit.Select("100", r.Header.Get(ContentLength))), func(count, total, step int) {
|
||||
if step/base != last {
|
||||
m.Logs(mdb.EXPORT, nfs.FILE, p, mdb.COUNT, count, mdb.TOTAL, total, mdb.VALUE, step)
|
||||
switch cb := cb.(type) {
|
||||
case func(int, int, int):
|
||||
cb(count, total, step)
|
||||
case nil:
|
||||
default:
|
||||
m.ErrorNotImplement(cb)
|
||||
}
|
||||
last = count / step
|
||||
}
|
||||
}
|
||||
nfs.CopyFile(m, f, r.Body, bufs, kit.Int(kit.Select("100", r.Header.Get(ContentLength))), cb)
|
||||
last = step / base
|
||||
})
|
||||
return p
|
||||
}
|
||||
return ""
|
||||
|
@ -19,19 +19,20 @@ import (
|
||||
|
||||
func _space_dial(m *ice.Message, dev, name string, arg ...string) {
|
||||
msg := m.Cmd(SPIDE, tcp.CLIENT, dev, PP(SPACE))
|
||||
uri := kit.ParseURL(strings.Replace(kit.MergeURL(msg.Append(DOMAIN), mdb.TYPE, ice.Info.NodeType, mdb.NAME, name, SHARE, ice.Info.CtxShare, RIVER, ice.Info.CtxRiver, arg), ice.HTTP, "ws", 1))
|
||||
uri := kit.ParseURL(strings.Replace(kit.MergeURL(msg.Append(DOMAIN), mdb.TYPE, ice.Info.NodeType, mdb.NAME, name, SHARE, ice.Info.CtxShare, RIVER, ice.Info.CtxRiver), ice.HTTP, "ws", 1))
|
||||
args := kit.SimpleKV("type,name,host,port", msg.Append(tcp.PROTOCOL), dev, msg.Append(tcp.HOST), msg.Append(tcp.PORT))
|
||||
m.Go(func() {
|
||||
redial := kit.Dict(m.Configv(REDIAL))
|
||||
a, b, c := kit.Int(redial["a"]), kit.Int(redial["b"]), kit.Int(redial["c"])
|
||||
for i := 0; i < c; i++ {
|
||||
for i := 1; i < c; i++ {
|
||||
next := time.Duration(rand.Intn(a*(i+1))+b*i) * time.Millisecond
|
||||
m.Cmd(tcp.CLIENT, tcp.DIAL, args, func(c net.Conn) {
|
||||
if conn, _, e := websocket.NewClient(c, uri, nil, kit.Int(redial["r"]), kit.Int(redial["w"])); !m.Warn(e, tcp.DIAL, dev, SPACE, uri.String()) {
|
||||
defer mdb.HashCreateDeferRemove(m, kit.SimpleKV("", MASTER, dev, msg.Append(tcp.HOSTNAME)), kit.Dict(mdb.TARGET, conn))()
|
||||
_space_handle(m, true, dev, conn)
|
||||
_space_handle(m.Spawn(), true, dev, conn)
|
||||
i = 0
|
||||
}
|
||||
}).Cost("order", i, "sleep", next, "redial", dev).Sleep(next)
|
||||
}).Cost("order", i, "sleep", next, "redial", dev, "uri", uri.String()).Sleep(next)
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -48,7 +49,7 @@ func _space_fork(m *ice.Message) {
|
||||
case WORKER:
|
||||
defer gdb.EventDeferEvent(m, DREAM_OPEN, args)(DREAM_CLOSE, args)
|
||||
case CHROME:
|
||||
m.Go(func() { m.Sleep("10ms").Cmd(SPACE, name, cli.PWD, name) })
|
||||
m.Go(func() { m.Sleep30ms().Cmd(SPACE, name, cli.PWD, name) })
|
||||
}
|
||||
_space_handle(m, false, name, conn)
|
||||
})
|
||||
@ -58,7 +59,7 @@ func _space_handle(m *ice.Message, safe bool, name string, conn *websocket.Conn)
|
||||
for {
|
||||
_, b, e := conn.ReadMessage()
|
||||
if e != nil {
|
||||
m.Logs("sock", SPACE, name, "error", e)
|
||||
m.Cost(SPACE, name, e)
|
||||
break
|
||||
}
|
||||
msg := m.Spawn(b)
|
||||
|
@ -46,7 +46,7 @@ func init() {
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.Fetch([]string{"curl", "make", "gcc", "vim", "tmux"}, func(cmd string) { cli.IsSystem(m, cmd) })
|
||||
if cli.IsAlpine(m, "git"); !cli.IsAlpine(m, "go", "go git") {
|
||||
m.Cmd(mdb.INSERT, cli.CLI, "", mdb.ZONE, cli.CLI, "go", cli.CMD, kit.Format("install download https://golang.google.cn/dl/go1.15.5.%s-%s.tar.gz usr/local", runtime.GOOS, runtime.GOARCH))
|
||||
m.Cmd(mdb.INSERT, cli.MIRRORS, "", mdb.ZONE, cli.CLI, "go", cli.CMD, kit.Format("install download https://golang.google.cn/dl/go1.15.5.%s-%s.tar.gz usr/local", runtime.GOOS, runtime.GOARCH))
|
||||
}
|
||||
}},
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
|
@ -21,48 +21,39 @@ func _install_path(m *ice.Message, link string) string {
|
||||
link = kit.Select(m.Option(mdb.LINK), link)
|
||||
if p := path.Join(ice.USR_INSTALL, kit.TrimExt(link)); nfs.ExistsFile(m, p) {
|
||||
return p
|
||||
}
|
||||
if p := path.Join(ice.USR_INSTALL, path.Base(link)); nfs.ExistsFile(m, p) {
|
||||
} else if p := path.Join(ice.USR_INSTALL, path.Base(link)); nfs.ExistsFile(m, p) {
|
||||
return path.Join(ice.USR_INSTALL, strings.Split(m.Cmd(nfs.TAR, p, "", "1").Append(nfs.FILE), ice.PS)[0])
|
||||
} else {
|
||||
m.Assert(true)
|
||||
return ""
|
||||
}
|
||||
m.Warn(true, ice.ErrNotFound, link)
|
||||
return ""
|
||||
}
|
||||
func _install_download(m *ice.Message) {
|
||||
link := m.Option(mdb.LINK)
|
||||
name := path.Base(strings.Split(link, "?")[0])
|
||||
file := path.Join(kit.Select(ice.USR_INSTALL, m.Option(nfs.PATH)), name)
|
||||
defer web.ToastSuccess(m)
|
||||
defer m.Cmdy(nfs.DIR, file)
|
||||
if nfs.ExistsFile(m, file) {
|
||||
m.Cmdy(nfs.DIR, file)
|
||||
web.ToastSuccess(m)
|
||||
return
|
||||
}
|
||||
defer m.SetResult()
|
||||
m.Cmd(nfs.SAVE, file, "")
|
||||
begin := time.Now()
|
||||
mdb.HashCreate(m, mdb.NAME, name, nfs.PATH, file, mdb.LINK, link)
|
||||
web.GoToast(m, name, func(toast func(string, int, int)) {
|
||||
last, base := 0, 10
|
||||
web.SpideSave(m, file, link, func(count int, total int, step int) {
|
||||
if step/base == last {
|
||||
return
|
||||
}
|
||||
last = step / base
|
||||
defer nfs.TarExport(m, file)
|
||||
begin := time.Now()
|
||||
web.SpideSave(m, file, link, func(count, total, step int) {
|
||||
cost := time.Now().Sub(begin)
|
||||
mdb.HashSelectUpdate(m, name, func(value ice.Map) { value[mdb.COUNT], value[mdb.TOTAL], value[mdb.VALUE] = count, total, step })
|
||||
toast(kit.FormatShow("from", begin.Format("15:04:05"), "cost", kit.FmtDuration(cost),
|
||||
"rest", kit.FmtDuration(cost*time.Duration(101)/time.Duration(step+1)-cost),
|
||||
), count, total)
|
||||
toast(kit.FormatShow("from", begin.Format("15:04:05"), "cost", kit.FmtDuration(cost), "rest", kit.FmtDuration(cost*time.Duration(101)/time.Duration(step+1)-cost)), count, total)
|
||||
})
|
||||
m.Cmd(nfs.TAR, mdb.EXPORT, ice.Maps{nfs.PATH: file, nfs.FILE: ""})
|
||||
web.ToastSuccess(m)
|
||||
})
|
||||
m.Cmdy(nfs.DIR, file).SetResult()
|
||||
}
|
||||
func _install_build(m *ice.Message, arg ...string) string {
|
||||
p := m.Option(cli.CMD_DIR, _install_path(m, ""))
|
||||
pp := kit.Path(path.Join(p, _INSTALL))
|
||||
defer m.ProcessHold()
|
||||
switch web.PushStream(m); cb := m.Optionv(PREPARE).(type) {
|
||||
switch cb := m.Optionv(PREPARE).(type) {
|
||||
case func(string):
|
||||
cb(p)
|
||||
case nil:
|
||||
@ -70,16 +61,15 @@ func _install_build(m *ice.Message, arg ...string) string {
|
||||
return msg.Append(cli.CMD_ERR) + msg.Append(cli.CMD_OUT)
|
||||
}
|
||||
default:
|
||||
m.ErrorNotImplement(cb)
|
||||
return m.Result()
|
||||
return m.ErrorNotImplement(cb).Result()
|
||||
}
|
||||
if msg := m.Cmd(cli.SYSTEM, cli.MAKE, "-j"+m.Cmdx(cli.RUNTIME, cli.MAXPROCS)); !cli.IsSuccess(msg) {
|
||||
return msg.Append(cli.CMD_ERR) + msg.Append(cli.CMD_OUT)
|
||||
}
|
||||
if msg := m.Cmd(cli.SYSTEM, cli.MAKE, "PREFIX="+pp, INSTALL); !cli.IsSuccess(msg) {
|
||||
} else if msg := m.Cmd(cli.SYSTEM, cli.MAKE, "PREFIX="+pp, INSTALL); !cli.IsSuccess(msg) {
|
||||
return msg.Append(cli.CMD_ERR) + msg.Append(cli.CMD_OUT)
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
return ""
|
||||
}
|
||||
func _install_order(m *ice.Message, arg ...string) {
|
||||
p := _install_path(m, "")
|
||||
@ -91,7 +81,7 @@ func _install_order(m *ice.Message, arg ...string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
m.Cmdy(cli.SYSTEM, nfs.PUSH, path.Join(p, m.Option(nfs.PATH))+ice.NL)
|
||||
m.Cmdy(cli.SYSTEM, nfs.PUSH, path.Join(p, m.Option(nfs.PATH)))
|
||||
}
|
||||
func _install_spawn(m *ice.Message, arg ...string) {
|
||||
if kit.Int(m.Option(tcp.PORT)) >= 10000 {
|
||||
@ -102,20 +92,18 @@ func _install_spawn(m *ice.Message, arg ...string) {
|
||||
} else {
|
||||
m.Option(tcp.PORT, m.Cmdx(tcp.PORT, aaa.RIGHT))
|
||||
}
|
||||
target := path.Join(ice.USR_LOCAL_DAEMON, m.Option(tcp.PORT))
|
||||
source := _install_path(m, "")
|
||||
target, source := path.Join(ice.USR_LOCAL_DAEMON, m.Option(tcp.PORT)), _install_path(m, "")
|
||||
nfs.MkdirAll(m, target)
|
||||
defer m.Echo(target)
|
||||
if m.Option(INSTALL) == "" && nfs.ExistsFile(m, kit.Path(source, _INSTALL)) {
|
||||
m.Option(INSTALL, _INSTALL)
|
||||
}
|
||||
m.Cmd(nfs.DIR, path.Join(source, m.Option(INSTALL)), func(value ice.Maps) {
|
||||
m.Cmd(cli.SYSTEM, "cp", "-r", strings.TrimSuffix(value[nfs.PATH], ice.PS), target+ice.PS)
|
||||
nfs.DirDeepAll(m.Spawn(), path.Join(source, m.Option(INSTALL)), "", func(value ice.Maps) {
|
||||
m.Cmd(nfs.LINK, path.Join(target, value[nfs.PATH]), path.Join(source, m.Option(INSTALL), value[nfs.PATH]))
|
||||
})
|
||||
}
|
||||
func _install_start(m *ice.Message, arg ...string) {
|
||||
p := m.Option(cli.CMD_DIR, m.Cmdx(INSTALL, cli.SPAWN))
|
||||
args := []string{}
|
||||
args, p := []string{}, m.Option(cli.CMD_DIR, m.Cmdx(INSTALL, cli.SPAWN))
|
||||
switch cb := m.Optionv(PREPARE).(type) {
|
||||
case func(string) []string:
|
||||
args = append(args, cb(p)...)
|
||||
@ -128,8 +116,7 @@ func _install_start(m *ice.Message, arg ...string) {
|
||||
m.ErrorNotImplement(cb)
|
||||
return
|
||||
}
|
||||
bin := kit.Split(path.Base(arg[0]), "-.")[0]
|
||||
m.Cmdy(cli.DAEMON, kit.Select(path.Join(ice.BIN, bin), arg, 1), kit.Slice(arg, 2), args)
|
||||
m.Cmdy(cli.DAEMON, kit.Select(path.Join(ice.BIN, kit.Split(path.Base(arg[0]), "-.")[0]), arg, 1), kit.Slice(arg, 2), args)
|
||||
}
|
||||
func _install_stop(m *ice.Message, arg ...string) {
|
||||
m.Cmd(cli.DAEMON, func(value ice.Maps) {
|
||||
@ -139,6 +126,13 @@ func _install_stop(m *ice.Message, arg ...string) {
|
||||
})
|
||||
m.Cmd(gdb.SIGNAL, gdb.KILL, m.Option(cli.PID))
|
||||
}
|
||||
func _install_end(m *ice.Message, arg ...string) {
|
||||
m.Cmd(cli.DAEMON, func(value ice.Maps) {
|
||||
if value[cli.PID] == m.Option(cli.PID) {
|
||||
m.Cmd(cli.DAEMON, mdb.REMOVE, kit.Dict(mdb.HASH, value[mdb.HASH]))
|
||||
}
|
||||
})
|
||||
}
|
||||
func _install_trash(m *ice.Message, arg ...string) {
|
||||
m.Cmd(cli.DAEMON, func(value ice.Maps) {
|
||||
if value[cli.PID] == m.Option(cli.PID) {
|
||||
@ -153,18 +147,17 @@ func _install_service(m *ice.Message, arg ...string) {
|
||||
m.Cmd(mdb.SELECT, cli.DAEMON, "", mdb.HASH, func(value ice.Maps) {
|
||||
if strings.Contains(value[ice.CMD], path.Join(ice.BIN, arg[0])) {
|
||||
m.Push("", value, kit.Split(m.OptionFields()))
|
||||
}
|
||||
switch value[mdb.STATUS] {
|
||||
case cli.START:
|
||||
m.PushButton(gdb.DEBUG, cli.STOP)
|
||||
case cli.STOP:
|
||||
m.PushButton(cli.START)
|
||||
default:
|
||||
m.PushButton("")
|
||||
switch value[mdb.STATUS] {
|
||||
case cli.START:
|
||||
m.PushButton(gdb.DEBUG, cli.STOP)
|
||||
case cli.STOP:
|
||||
m.PushButton(cli.START, cli.END)
|
||||
default:
|
||||
m.PushButton("")
|
||||
}
|
||||
}
|
||||
})
|
||||
m.Set(tcp.PORT).Tables(func(value ice.Maps) { m.Push(tcp.PORT, path.Base(value[nfs.DIR])) })
|
||||
m.StatusTimeCount()
|
||||
m.Set(tcp.PORT).Tables(func(value ice.Maps) { m.Push(tcp.PORT, path.Base(value[nfs.DIR])) }).StatusTimeCount()
|
||||
}
|
||||
|
||||
const (
|
||||
@ -181,9 +174,10 @@ func init() {
|
||||
_install_download(m)
|
||||
}},
|
||||
cli.BUILD: {Name: "build link*", Help: "构建", Hand: func(m *ice.Message, arg ...string) {
|
||||
if err := _install_build(m, arg...); err != "" {
|
||||
web.ToastFailure(m, cli.BUILD)
|
||||
m.Echo(err)
|
||||
web.PushStream(m)
|
||||
defer m.ProcessHold()
|
||||
if err := _install_build(m, arg...); m.Warn(err != "", err) {
|
||||
web.ToastFailure(m, cli.BUILD, err)
|
||||
} else {
|
||||
web.ToastSuccess(m, cli.BUILD)
|
||||
}
|
||||
@ -197,34 +191,36 @@ func init() {
|
||||
cli.START: {Name: "start link* cmd", Help: "启动", Hand: func(m *ice.Message, arg ...string) {
|
||||
_install_start(m, arg...)
|
||||
}},
|
||||
cli.STOP: {Name: "stop", Help: "停止", Hand: func(m *ice.Message, arg ...string) {
|
||||
cli.STOP: {Help: "停止", Hand: func(m *ice.Message, arg ...string) {
|
||||
_install_stop(m, arg...)
|
||||
}},
|
||||
gdb.DEBUG: {Name: "debug", Help: "调试", Hand: func(m *ice.Message, arg ...string) {
|
||||
cli.END: {Help: "清理", Hand: func(m *ice.Message, arg ...string) {
|
||||
_install_end(m, arg...)
|
||||
}},
|
||||
gdb.DEBUG: {Help: "调试", Hand: func(m *ice.Message, arg ...string) {
|
||||
ctx.Process(m, XTERM, []string{mdb.TYPE, "gdb"}, arg...)
|
||||
}},
|
||||
nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
_install_trash(m, arg...)
|
||||
}},
|
||||
nfs.SOURCE: {Name: "source link path", Help: "源码", Hand: func(m *ice.Message, arg ...string) {
|
||||
nfs.SOURCE: {Name: "source link* path", Help: "源码", Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(nfs.DIR_ROOT, path.Join(_install_path(m, ""), _INSTALL)); !nfs.ExistsFile(m, m.Option(nfs.DIR_ROOT)) {
|
||||
m.Option(nfs.DIR_ROOT, path.Join(_install_path(m, "")))
|
||||
}
|
||||
if m.Option(nfs.DIR_ROOT) == "" {
|
||||
return
|
||||
}
|
||||
m.Cmdy(nfs.DIR, m.Option(nfs.PATH)).Sort(nfs.PATH).StatusTimeCount(nfs.PATH, m.Option(nfs.DIR_ROOT))
|
||||
m.Cmdy(nfs.DIR, m.Option(nfs.PATH)).StatusTimeCount(nfs.PATH, m.Option(nfs.DIR_ROOT))
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,path,link")), Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.REMOVE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
nfs.Trash(m, m.Option(nfs.PATH))
|
||||
mdb.HashRemove(m)
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,count,total,name,path,link")), Hand: func(m *ice.Message, arg ...string) {
|
||||
switch len(arg) {
|
||||
case 0:
|
||||
mdb.HashSelect(m, arg...)
|
||||
m.PushAction(cli.BUILD, cli.ORDER)
|
||||
mdb.HashSelect(m, arg...).PushAction(cli.BUILD, cli.ORDER, mdb.REMOVE)
|
||||
case 1:
|
||||
_install_service(m, arg...)
|
||||
default:
|
||||
m.Option(nfs.DIR_ROOT, path.Join(ice.USR_LOCAL_DAEMON, arg[1]))
|
||||
m.Cmdy(nfs.CAT, kit.Select(nfs.PWD, arg, 2))
|
||||
m.Cmdy(nfs.CAT, kit.Select(nfs.PWD, arg, 2), kit.Dict(nfs.DIR_ROOT, path.Join(ice.USR_LOCAL_DAEMON, arg[1])))
|
||||
}
|
||||
}},
|
||||
})
|
||||
|
5
logs.go
5
logs.go
@ -20,7 +20,7 @@ func (m *Message) join(arg ...Any) (string, []Any) {
|
||||
i--
|
||||
continue
|
||||
case []string:
|
||||
list = append(list, v...)
|
||||
list = append(list, kit.JoinKV(": ", " ", v...))
|
||||
i--
|
||||
continue
|
||||
}
|
||||
@ -131,8 +131,9 @@ func (m *Message) Warn(err Any, arg ...Any) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
func (m *Message) ErrorNotImplement(arg ...Any) {
|
||||
func (m *Message) ErrorNotImplement(arg ...Any) *Message {
|
||||
m.Error(true, append(kit.List(ErrNotImplement), arg...)...)
|
||||
return m
|
||||
}
|
||||
func (m *Message) Error(err bool, arg ...Any) bool {
|
||||
if err {
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"shylinux.com/x/gogit"
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
@ -22,11 +23,11 @@ func _repos_cmd(m *ice.Message, name string, arg ...string) *ice.Message {
|
||||
}
|
||||
func _repos_insert(m *ice.Message, name string, dir string) {
|
||||
if s, e := nfs.StatFile(m, m.Option(cli.CMD_DIR, path.Join(dir, ".git"))); e == nil && s.IsDir() {
|
||||
ls := strings.SplitN(strings.Trim(_git_cmds(m, "log", "-n1", `--pretty=format:"%ad %s"`, "--date=iso"), `"`), ice.SP, 4)
|
||||
ci, _ := gogit.OpenRepository(path.Join(dir, ".git")).GetCurrentCommit()
|
||||
mdb.HashCreate(m, mdb.NAME, name, nfs.PATH, dir,
|
||||
COMMIT, kit.Select("", ls, 3), mdb.TIME, strings.Join(ls[:2], ice.SP),
|
||||
REMOTE, strings.TrimSpace(_git_cmds(m, REMOTE, "-v")),
|
||||
BRANCH, strings.TrimSpace(_git_cmds(m, BRANCH)),
|
||||
COMMIT, strings.TrimSpace(ci.CommitMessage), mdb.TIME, ci.Author.When.Format(ice.MOD_TIME),
|
||||
REMOTE, strings.SplitN(nfs.CatFile(m, path.Join(dir, ".git", "FETCH_HEAD")), ice.SP, 2)[1],
|
||||
BRANCH, path.Base(nfs.CatFile(m, path.Join(dir, ".git", "HEAD"))),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -44,6 +44,8 @@ func Render(m *Message, cmd string, args ...Any) string {
|
||||
for k, v := range k {
|
||||
list = append(list, kit.Format(`<input type="button" name="%s" value="%s">`, k, kit.Select(k, v, m.Option(MSG_LANGUAGE) != "en")))
|
||||
}
|
||||
default:
|
||||
list = append(list, Render(m, RENDER_BUTTON, kit.Format(k)))
|
||||
}
|
||||
}
|
||||
return strings.Join(list, "")
|
||||
|
Loading…
x
Reference in New Issue
Block a user