mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-25 16:58:06 +08:00
add see
This commit is contained in:
parent
9d3eafbc70
commit
436c230b5f
@ -225,6 +225,10 @@ func main() {
|
|||||||
"template_tar_gz": "usr/template",
|
"template_tar_gz": "usr/template",
|
||||||
"librarys_tar_gz": "usr/librarys",
|
"librarys_tar_gz": "usr/librarys",
|
||||||
},
|
},
|
||||||
|
"script": map[string]interface{}{
|
||||||
|
"worker": "usr/publish/hello/local.shy",
|
||||||
|
"server": "usr/publish/docker/local.shy",
|
||||||
|
},
|
||||||
}, Help: "版本发布"},
|
}, Help: "版本发布"},
|
||||||
"upgrade": &ctx.Config{Name: "upgrade", Value: map[string]interface{}{
|
"upgrade": &ctx.Config{Name: "upgrade", Value: map[string]interface{}{
|
||||||
"system": []interface{}{"boot.sh", "node.sh", "init.shy", "common.shy", "exit.shy"},
|
"system": []interface{}{"boot.sh", "node.sh", "init.shy", "common.shy", "exit.shy"},
|
||||||
@ -601,51 +605,256 @@ func main() {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
"plugin": &ctx.Command{Name: "plugin [action] file", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"source": &ctx.Command{Name: "source [script|stdio|snippet]", Help: "解析脚本, script: 脚本文件, stdio: 命令终端, snippet: 代码片段", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
suffix, action, target := "go", "build", path.Join(m.Conf("runtime", "boot.ctx_home"), "src/examples/app/bench.go")
|
|
||||||
if len(arg) == 0 {
|
if len(arg) == 0 {
|
||||||
arg = append(arg, target)
|
m.Cmdy("dir", "", "dir_deep", "dir_reg", ".*\\.(sh|shy|py)$")
|
||||||
}
|
return
|
||||||
if cs := strings.Split(arg[0], "."); len(cs) > 1 {
|
|
||||||
suffix = cs[len(cs)-1]
|
|
||||||
} else if cs := strings.Split(arg[1], "."); len(cs) > 1 {
|
|
||||||
suffix, action, arg = cs[len(cs)-1], arg[0], arg[1:]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if target = m.Cmdx("nfs.path", arg[0]); target == "" {
|
// 解析脚本文件
|
||||||
target = m.Cmdx("nfs.path", path.Join("src/plugin/", arg[0]))
|
if p := m.Cmdx("nfs.path", arg[0]); p != "" && strings.Contains(p, ".") {
|
||||||
}
|
arg[0] = p
|
||||||
|
switch path.Ext(p) {
|
||||||
for suffix != "" && action != "" {
|
case "":
|
||||||
m.Log("info", "%v %v %v", suffix, action, target)
|
case ".shy":
|
||||||
cook := m.Confv("plugin", suffix)
|
m.Option("scan_end", "false")
|
||||||
next := strings.Replace(target, "."+suffix, "."+kit.Chains(cook, "next.0"), -1)
|
m.Start(fmt.Sprintf("shell%d", m.Capi("nshell", 1)), "shell", arg...)
|
||||||
|
m.Wait()
|
||||||
args := []string{}
|
default:
|
||||||
if suffix == "so" {
|
m.Cmdy("system", m.Conf("system", []string{"script", strings.TrimPrefix(path.Ext(p), ".")}), arg)
|
||||||
if p, e := plugin.Open(target); m.Assert(e) {
|
|
||||||
s, e := p.Lookup("Index")
|
|
||||||
m.Assert(e)
|
|
||||||
w := *(s.(**ctx.Context))
|
|
||||||
w.Name = kit.Select(w.Name, arg, 1)
|
|
||||||
c.Register(w, nil)
|
|
||||||
m.Spawn(w).Cmd("_init", arg[1:])
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if suffix == "go" {
|
|
||||||
args = append(args, "-o", next)
|
|
||||||
}
|
|
||||||
m.Assert(m.Cmd("cli.system", kit.Chain(cook, action), args, target))
|
|
||||||
}
|
}
|
||||||
|
m.Append("directory", "")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
suffix = kit.Chains(cook, "next.0")
|
// 解析终端命令
|
||||||
action = kit.Chains(cook, "next.1")
|
if arg[0] == "stdio" {
|
||||||
target = next
|
m.Option("scan_end", "false")
|
||||||
|
m.Start("shy", "shell", "stdio", "engine")
|
||||||
|
m.Wait()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
text := strings.Join(arg, " ")
|
||||||
|
if !strings.HasPrefix(text, "sess") && m.Options("remote") {
|
||||||
|
text = m.Current(text)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解析代码片段
|
||||||
|
m.Sess("yac").Call(func(msg *ctx.Message) *ctx.Message {
|
||||||
|
switch msg.Cmd().Detail(0) {
|
||||||
|
case "cmd":
|
||||||
|
m.Set("append").Copy(msg, "append")
|
||||||
|
m.Set("result").Copy(msg, "result")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}, "parse", "line", "void", text)
|
||||||
|
return
|
||||||
|
}},
|
||||||
|
"sleep": &ctx.Command{Name: "sleep time", Help: "睡眠, time(ns/us/ms/s/m/h): 时间值(纳秒/微秒/毫秒/秒/分钟/小时)", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
|
if d, e := time.ParseDuration(arg[0]); m.Assert(e) {
|
||||||
|
m.Log("info", "sleep %v", d)
|
||||||
|
time.Sleep(d)
|
||||||
|
m.Log("info", "sleep %v done", d)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
|
"timer": &ctx.Command{Name: "timer [begin time] [repeat] [order time] time cmd", Help: "定时任务", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
|
if cli, ok := c.Server.(*CLI); m.Assert(ok) {
|
||||||
|
// 定时列表
|
||||||
|
if len(arg) == 0 {
|
||||||
|
m.Confm("timer", func(key string, timer map[string]interface{}) {
|
||||||
|
m.Add("append", "key", key)
|
||||||
|
m.Add("append", "action_time", time.Unix(0, timer["action_time"].(int64)/int64(m.Confi("time_unit"))*1000000000).Format(m.Conf("time_format")))
|
||||||
|
m.Add("append", "order", timer["order"])
|
||||||
|
m.Add("append", "time", timer["time"])
|
||||||
|
m.Add("append", "cmd", timer["cmd"])
|
||||||
|
m.Add("append", "msg", timer["msg"])
|
||||||
|
m.Add("append", "results", kit.Format(timer["result"]))
|
||||||
|
})
|
||||||
|
m.Table()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch arg[0] {
|
||||||
|
case "stop":
|
||||||
|
if timer := m.Confm("timer", arg[1]); timer != nil {
|
||||||
|
timer["stop"] = true
|
||||||
|
}
|
||||||
|
cli.schedule(m)
|
||||||
|
return
|
||||||
|
case "start":
|
||||||
|
if timer := m.Confm("timer", arg[1]); timer != nil {
|
||||||
|
timer["stop"] = false
|
||||||
|
}
|
||||||
|
cli.schedule(m)
|
||||||
|
return
|
||||||
|
case "delete":
|
||||||
|
delete(m.Confm("timer"), arg[1])
|
||||||
|
cli.schedule(m)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
now := m.Sess("cli").Cmd("time").Appendi("timestamp")
|
||||||
|
begin := now
|
||||||
|
if len(arg) > 0 && arg[0] == "begin" {
|
||||||
|
begin, arg = int64(m.Sess("cli").Cmd("time", arg[1]).Appendi("timestamp")), arg[2:]
|
||||||
|
}
|
||||||
|
|
||||||
|
repeat := false
|
||||||
|
if len(arg) > 0 && arg[0] == "repeat" {
|
||||||
|
repeat, arg = true, arg[1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
order := ""
|
||||||
|
if len(arg) > 0 && arg[0] == "order" {
|
||||||
|
order, arg = arg[1], arg[2:]
|
||||||
|
}
|
||||||
|
|
||||||
|
action := int64(m.Sess("cli").Cmd("time", begin, order, arg[0]).Appendi("timestamp"))
|
||||||
|
|
||||||
|
// 创建任务
|
||||||
|
hash := m.Sess("aaa").Cmd("hash", "timer", arg, "time", "rand").Result(0)
|
||||||
|
m.Confv("timer", hash, map[string]interface{}{
|
||||||
|
"create_time": now,
|
||||||
|
"begin_time": begin,
|
||||||
|
"action_time": action,
|
||||||
|
"repeat": repeat,
|
||||||
|
"order": order,
|
||||||
|
"done": false,
|
||||||
|
"stop": false,
|
||||||
|
"time": arg[0],
|
||||||
|
"cmd": arg[1:],
|
||||||
|
"msg": 0,
|
||||||
|
"result": "",
|
||||||
|
})
|
||||||
|
|
||||||
|
if cli.Timer == nil { // 创建时间队列
|
||||||
|
cli.Timer = time.NewTimer((time.Duration)((action - now) / int64(m.Confi("time_unit")) * 1000000000))
|
||||||
|
m.GoLoop(m, func(m *ctx.Message) {
|
||||||
|
select {
|
||||||
|
case <-cli.Timer.C:
|
||||||
|
if m.Conf("timer_next") == "" {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if timer := m.Confm("timer", m.Conf("timer_next")); timer != nil && !kit.Right(timer["stop"]) {
|
||||||
|
m.Log("info", "timer %s %v", m.Conf("timer_next"), timer["cmd"])
|
||||||
|
|
||||||
|
msg := m.Sess("cli").Cmd("source", timer["cmd"])
|
||||||
|
timer["result"] = msg.Meta["result"]
|
||||||
|
timer["msg"] = msg.Code()
|
||||||
|
|
||||||
|
if timer["repeat"].(bool) {
|
||||||
|
timer["action_time"] = int64(m.Sess("cli").Cmd("time", msg.Time(), timer["order"], timer["time"]).Appendi("timestamp"))
|
||||||
|
} else {
|
||||||
|
timer["done"] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cli.schedule(m)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调度任务
|
||||||
|
cli.schedule(m)
|
||||||
|
m.Echo(hash)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}},
|
||||||
|
"time": &ctx.Command{Name: "time when [begin|end|yestoday|tommorow|monday|sunday|first|last|new|eve] [offset]",
|
||||||
|
Help: "查看时间, when: 输入的时间戳, 剩余参数是时间偏移",
|
||||||
|
Form: map[string]int{"time_format": 1, "time_close": 1},
|
||||||
|
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
|
t, stamp := time.Now(), true
|
||||||
|
if len(arg) > 0 {
|
||||||
|
if i, e := strconv.ParseInt(arg[0], 10, 64); e == nil {
|
||||||
|
t, stamp, arg = time.Unix(int64(i/int64(m.Confi("time_unit"))), 0), false, arg[1:]
|
||||||
|
} else if n, e := time.ParseInLocation(m.Confx("time_format"), arg[0], time.Local); e == nil {
|
||||||
|
t, arg = n, arg[1:]
|
||||||
|
} else {
|
||||||
|
for _, v := range []string{"01-02", "2006-01-02", "15:04:05", "15:04"} {
|
||||||
|
if n, e := time.ParseInLocation(v, arg[0], time.Local); e == nil {
|
||||||
|
t, arg = n, arg[1:]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(arg) > 0 {
|
||||||
|
switch arg[0] {
|
||||||
|
case "begin":
|
||||||
|
d, e := time.ParseDuration(fmt.Sprintf("%dh%dm%ds", t.Hour(), t.Minute(), t.Second()))
|
||||||
|
m.Assert(e)
|
||||||
|
t, arg = t.Add(-d), arg[1:]
|
||||||
|
case "end":
|
||||||
|
d, e := time.ParseDuration(fmt.Sprintf("%dh%dm%ds%dns", t.Hour(), t.Minute(), t.Second(), t.Nanosecond()))
|
||||||
|
m.Assert(e)
|
||||||
|
t, arg = t.Add(time.Duration(24*time.Hour)-d), arg[1:]
|
||||||
|
if m.Confx("time_close") == "close" {
|
||||||
|
t = t.Add(-time.Second)
|
||||||
|
}
|
||||||
|
case "yestoday":
|
||||||
|
t, arg = t.Add(-time.Duration(24*time.Hour)), arg[1:]
|
||||||
|
case "tomorrow":
|
||||||
|
t, arg = t.Add(time.Duration(24*time.Hour)), arg[1:]
|
||||||
|
case "monday":
|
||||||
|
d, e := time.ParseDuration(fmt.Sprintf("%dh%dm%ds", int((t.Weekday()-time.Monday+7)%7)*24+t.Hour(), t.Minute(), t.Second()))
|
||||||
|
m.Assert(e)
|
||||||
|
t, arg = t.Add(-d), arg[1:]
|
||||||
|
case "sunday":
|
||||||
|
d, e := time.ParseDuration(fmt.Sprintf("%dh%dm%ds", int((t.Weekday()-time.Monday+7)%7)*24+t.Hour(), t.Minute(), t.Second()))
|
||||||
|
m.Assert(e)
|
||||||
|
t, arg = t.Add(time.Duration(7*24*time.Hour)-d), arg[1:]
|
||||||
|
if m.Confx("time_close") == "close" {
|
||||||
|
t = t.Add(-time.Second)
|
||||||
|
}
|
||||||
|
case "first":
|
||||||
|
t, arg = time.Date(t.Year(), t.Month(), 1, 0, 0, 0, 0, time.Local), arg[1:]
|
||||||
|
case "last":
|
||||||
|
month, year := t.Month()+1, t.Year()
|
||||||
|
if month >= 13 {
|
||||||
|
month, year = 1, year+1
|
||||||
|
}
|
||||||
|
t, arg = time.Date(year, month, 1, 0, 0, 0, 0, time.Local), arg[1:]
|
||||||
|
if m.Confx("time_close") == "close" {
|
||||||
|
t = t.Add(-time.Second)
|
||||||
|
}
|
||||||
|
case "new":
|
||||||
|
t, arg = time.Date(t.Year(), 1, 1, 0, 0, 0, 0, time.Local), arg[1:]
|
||||||
|
case "eve":
|
||||||
|
t, arg = time.Date(t.Year()+1, 1, 1, 0, 0, 0, 0, time.Local), arg[1:]
|
||||||
|
if m.Confx("time_close") == "close" {
|
||||||
|
t = t.Add(-time.Second)
|
||||||
|
}
|
||||||
|
case "":
|
||||||
|
arg = arg[1:]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(arg) > 0 {
|
||||||
|
if d, e := time.ParseDuration(arg[0]); e == nil {
|
||||||
|
t, arg = t.Add(d), arg[1:]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Append("datetime", t.Format(m.Confx("time_format")))
|
||||||
|
m.Append("timestamp", t.Unix()*int64(m.Confi("time_unit")))
|
||||||
|
|
||||||
|
if stamp {
|
||||||
|
m.Echo("%d", t.Unix()*int64(m.Confi("time_unit")))
|
||||||
|
} else {
|
||||||
|
m.Echo(t.Format(m.Confx("time_format")))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}},
|
||||||
"proc": &ctx.Command{Name: "proc", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"proc": &ctx.Command{Name: "proc", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
m.Cmdy("cli.system", "cmd_parse", "cut", "ps", kit.Select("ax", arg, 0))
|
m.Cmdy("cli.system", "cmd_parse", "cut", "ps", kit.Select("ax", arg, 0))
|
||||||
|
if len(arg) > 0 {
|
||||||
|
m.Cmd("select", "reg", "COMMAND", arg[1])
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
"quit": &ctx.Command{Name: "quit code", Help: "停止服务", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"quit": &ctx.Command{Name: "quit code", Help: "停止服务", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
@ -790,7 +999,7 @@ func main() {
|
|||||||
|
|
||||||
if m.Cmdy("cli.system", env, "go", "build", o, "-o", q, p); m.Result(0) == "" {
|
if m.Cmdy("cli.system", env, "go", "build", o, "-o", q, p); m.Result(0) == "" {
|
||||||
m.Append("time", m.Time())
|
m.Append("time", m.Time())
|
||||||
m.Append("hash", kit.Hashs(q)[:8])
|
m.Append("hash", kit.Hashs(q)[:8])
|
||||||
m.Append("bin", q)
|
m.Append("bin", q)
|
||||||
m.Table()
|
m.Table()
|
||||||
}
|
}
|
||||||
@ -816,9 +1025,9 @@ func main() {
|
|||||||
m.Confm("project", "plugin.list", func(index int, value map[string]interface{}) {
|
m.Confm("project", "plugin.list", func(index int, value map[string]interface{}) {
|
||||||
m.Cmd("nfs.copy", path.Join(q, kit.Format(value["name"])), path.Join(p, kit.Format(value["name"])))
|
m.Cmd("nfs.copy", path.Join(q, kit.Format(value["name"])), path.Join(p, kit.Format(value["name"])))
|
||||||
})
|
})
|
||||||
for _, v := range arg[1:] {
|
for _, v := range arg[1:] {
|
||||||
m.Cmd("nfs.copy", path.Join(q, v), path.Join(p, v))
|
m.Cmd("nfs.copy", path.Join(q, v), path.Join(p, v))
|
||||||
}
|
}
|
||||||
m.Cmdy("nfs.dir", q, "time", "size", "hashs", "path")
|
m.Cmdy("nfs.dir", q, "time", "size", "hashs", "path")
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
@ -834,9 +1043,10 @@ func main() {
|
|||||||
} else {
|
} else {
|
||||||
m.Cmd("nfs.copy", q, p)
|
m.Cmd("nfs.copy", q, p)
|
||||||
}
|
}
|
||||||
m.Add("append", "time", m.Time())
|
m.Add("append", "time", s.ModTime())
|
||||||
|
m.Add("append", "size", s.Size())
|
||||||
|
m.Add("append", "hash", kit.Hashs(p)[:8])
|
||||||
m.Add("append", "file", q)
|
m.Add("append", "file", q)
|
||||||
m.Add("append", "hash", kit.Hashs(p))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.Table()
|
m.Table()
|
||||||
@ -858,7 +1068,7 @@ func main() {
|
|||||||
|
|
||||||
case "script":
|
case "script":
|
||||||
if len(arg) == 1 {
|
if len(arg) == 1 {
|
||||||
m.Cmdy("nfs.dir", m.Conf("project", "script.path"), "time", "size", "line", "hash", "path")
|
m.Cmdy("nfs.dir", m.Conf("project", "script.path"), "time", "line", "hashs", "path")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
miss := ""
|
miss := ""
|
||||||
@ -982,6 +1192,49 @@ func main() {
|
|||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
|
|
||||||
|
"plugin": &ctx.Command{Name: "plugin [action] file", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
|
suffix, action, target := "go", "build", path.Join(m.Conf("runtime", "boot.ctx_home"), "src/examples/app/bench.go")
|
||||||
|
if len(arg) == 0 {
|
||||||
|
arg = append(arg, target)
|
||||||
|
}
|
||||||
|
if cs := strings.Split(arg[0], "."); len(cs) > 1 {
|
||||||
|
suffix = cs[len(cs)-1]
|
||||||
|
} else if cs := strings.Split(arg[1], "."); len(cs) > 1 {
|
||||||
|
suffix, action, arg = cs[len(cs)-1], arg[0], arg[1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
if target = m.Cmdx("nfs.path", arg[0]); target == "" {
|
||||||
|
target = m.Cmdx("nfs.path", path.Join("src/plugin/", arg[0]))
|
||||||
|
}
|
||||||
|
|
||||||
|
for suffix != "" && action != "" {
|
||||||
|
m.Log("info", "%v %v %v", suffix, action, target)
|
||||||
|
cook := m.Confv("plugin", suffix)
|
||||||
|
next := strings.Replace(target, "."+suffix, "."+kit.Chains(cook, "next.0"), -1)
|
||||||
|
|
||||||
|
args := []string{}
|
||||||
|
if suffix == "so" {
|
||||||
|
if p, e := plugin.Open(target); m.Assert(e) {
|
||||||
|
s, e := p.Lookup("Index")
|
||||||
|
m.Assert(e)
|
||||||
|
w := *(s.(**ctx.Context))
|
||||||
|
w.Name = kit.Select(w.Name, arg, 1)
|
||||||
|
c.Register(w, nil)
|
||||||
|
m.Spawn(w).Cmd("_init", arg[1:])
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if suffix == "go" {
|
||||||
|
args = append(args, "-o", next)
|
||||||
|
}
|
||||||
|
m.Assert(m.Cmd("cli.system", kit.Chain(cook, action), args, target))
|
||||||
|
}
|
||||||
|
|
||||||
|
suffix = kit.Chains(cook, "next.0")
|
||||||
|
action = kit.Chains(cook, "next.1")
|
||||||
|
target = next
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}},
|
||||||
"version": &ctx.Command{Name: "version", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"version": &ctx.Command{Name: "version", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
if len(arg) == 0 {
|
if len(arg) == 0 {
|
||||||
types := reflect.TypeOf(version)
|
types := reflect.TypeOf(version)
|
||||||
@ -1010,251 +1263,6 @@ var version = struct {
|
|||||||
m.Append("directory", "")
|
m.Append("directory", "")
|
||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
"source": &ctx.Command{Name: "source [script|stdio|snippet]", Help: "解析脚本, script: 脚本文件, stdio: 命令终端, snippet: 代码片段", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
|
||||||
if len(arg) == 0 {
|
|
||||||
m.Cmdy("dir", "", "dir_deep", "dir_reg", ".*\\.(sh|shy|py)$")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 解析脚本文件
|
|
||||||
if p := m.Cmdx("nfs.path", arg[0]); p != "" && strings.Contains(p, ".") {
|
|
||||||
arg[0] = p
|
|
||||||
switch path.Ext(p) {
|
|
||||||
case "":
|
|
||||||
case ".shy":
|
|
||||||
m.Option("scan_end", "false")
|
|
||||||
m.Start(fmt.Sprintf("shell%d", m.Capi("nshell", 1)), "shell", arg...)
|
|
||||||
m.Wait()
|
|
||||||
default:
|
|
||||||
m.Cmdy("system", m.Conf("system", []string{"script", strings.TrimPrefix(path.Ext(p), ".")}), arg)
|
|
||||||
}
|
|
||||||
m.Append("directory", "")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 解析终端命令
|
|
||||||
if arg[0] == "stdio" {
|
|
||||||
m.Option("scan_end", "false")
|
|
||||||
m.Start("shy", "shell", "stdio", "engine")
|
|
||||||
m.Wait()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
text := strings.Join(arg, " ")
|
|
||||||
if !strings.HasPrefix(text, "sess") && m.Options("remote") {
|
|
||||||
text = m.Current(text)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 解析代码片段
|
|
||||||
m.Sess("yac").Call(func(msg *ctx.Message) *ctx.Message {
|
|
||||||
switch msg.Cmd().Detail(0) {
|
|
||||||
case "cmd":
|
|
||||||
m.Set("append").Copy(msg, "append")
|
|
||||||
m.Set("result").Copy(msg, "result")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}, "parse", "line", "void", text)
|
|
||||||
return
|
|
||||||
}},
|
|
||||||
"timer": &ctx.Command{Name: "timer [begin time] [repeat] [order time] time cmd", Help: "定时任务", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
|
||||||
if cli, ok := c.Server.(*CLI); m.Assert(ok) {
|
|
||||||
// 定时列表
|
|
||||||
if len(arg) == 0 {
|
|
||||||
m.Confm("timer", func(key string, timer map[string]interface{}) {
|
|
||||||
m.Add("append", "key", key)
|
|
||||||
m.Add("append", "action_time", time.Unix(0, timer["action_time"].(int64)/int64(m.Confi("time_unit"))*1000000000).Format(m.Conf("time_format")))
|
|
||||||
m.Add("append", "order", timer["order"])
|
|
||||||
m.Add("append", "time", timer["time"])
|
|
||||||
m.Add("append", "cmd", timer["cmd"])
|
|
||||||
m.Add("append", "msg", timer["msg"])
|
|
||||||
m.Add("append", "results", kit.Format(timer["result"]))
|
|
||||||
})
|
|
||||||
m.Table()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
switch arg[0] {
|
|
||||||
case "stop":
|
|
||||||
if timer := m.Confm("timer", arg[1]); timer != nil {
|
|
||||||
timer["stop"] = true
|
|
||||||
}
|
|
||||||
cli.schedule(m)
|
|
||||||
return
|
|
||||||
case "start":
|
|
||||||
if timer := m.Confm("timer", arg[1]); timer != nil {
|
|
||||||
timer["stop"] = false
|
|
||||||
}
|
|
||||||
cli.schedule(m)
|
|
||||||
return
|
|
||||||
case "delete":
|
|
||||||
delete(m.Confm("timer"), arg[1])
|
|
||||||
cli.schedule(m)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
now := m.Sess("cli").Cmd("time").Appendi("timestamp")
|
|
||||||
begin := now
|
|
||||||
if len(arg) > 0 && arg[0] == "begin" {
|
|
||||||
begin, arg = int64(m.Sess("cli").Cmd("time", arg[1]).Appendi("timestamp")), arg[2:]
|
|
||||||
}
|
|
||||||
|
|
||||||
repeat := false
|
|
||||||
if len(arg) > 0 && arg[0] == "repeat" {
|
|
||||||
repeat, arg = true, arg[1:]
|
|
||||||
}
|
|
||||||
|
|
||||||
order := ""
|
|
||||||
if len(arg) > 0 && arg[0] == "order" {
|
|
||||||
order, arg = arg[1], arg[2:]
|
|
||||||
}
|
|
||||||
|
|
||||||
action := int64(m.Sess("cli").Cmd("time", begin, order, arg[0]).Appendi("timestamp"))
|
|
||||||
|
|
||||||
// 创建任务
|
|
||||||
hash := m.Sess("aaa").Cmd("hash", "timer", arg, "time", "rand").Result(0)
|
|
||||||
m.Confv("timer", hash, map[string]interface{}{
|
|
||||||
"create_time": now,
|
|
||||||
"begin_time": begin,
|
|
||||||
"action_time": action,
|
|
||||||
"repeat": repeat,
|
|
||||||
"order": order,
|
|
||||||
"done": false,
|
|
||||||
"stop": false,
|
|
||||||
"time": arg[0],
|
|
||||||
"cmd": arg[1:],
|
|
||||||
"msg": 0,
|
|
||||||
"result": "",
|
|
||||||
})
|
|
||||||
|
|
||||||
if cli.Timer == nil { // 创建时间队列
|
|
||||||
cli.Timer = time.NewTimer((time.Duration)((action - now) / int64(m.Confi("time_unit")) * 1000000000))
|
|
||||||
m.GoLoop(m, func(m *ctx.Message) {
|
|
||||||
select {
|
|
||||||
case <-cli.Timer.C:
|
|
||||||
if m.Conf("timer_next") == "" {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
if timer := m.Confm("timer", m.Conf("timer_next")); timer != nil && !kit.Right(timer["stop"]) {
|
|
||||||
m.Log("info", "timer %s %v", m.Conf("timer_next"), timer["cmd"])
|
|
||||||
|
|
||||||
msg := m.Sess("cli").Cmd("source", timer["cmd"])
|
|
||||||
timer["result"] = msg.Meta["result"]
|
|
||||||
timer["msg"] = msg.Code()
|
|
||||||
|
|
||||||
if timer["repeat"].(bool) {
|
|
||||||
timer["action_time"] = int64(m.Sess("cli").Cmd("time", msg.Time(), timer["order"], timer["time"]).Appendi("timestamp"))
|
|
||||||
} else {
|
|
||||||
timer["done"] = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cli.schedule(m)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 调度任务
|
|
||||||
cli.schedule(m)
|
|
||||||
m.Echo(hash)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}},
|
|
||||||
"sleep": &ctx.Command{Name: "sleep time", Help: "睡眠, time(ns/us/ms/s/m/h): 时间值(纳秒/微秒/毫秒/秒/分钟/小时)", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
|
||||||
if d, e := time.ParseDuration(arg[0]); m.Assert(e) {
|
|
||||||
m.Log("info", "sleep %v", d)
|
|
||||||
time.Sleep(d)
|
|
||||||
m.Log("info", "sleep %v done", d)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}},
|
|
||||||
"time": &ctx.Command{Name: "time when [begin|end|yestoday|tommorow|monday|sunday|first|last|new|eve] [offset]",
|
|
||||||
Help: "查看时间, when: 输入的时间戳, 剩余参数是时间偏移",
|
|
||||||
Form: map[string]int{"time_format": 1, "time_close": 1},
|
|
||||||
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
|
||||||
t, stamp := time.Now(), true
|
|
||||||
if len(arg) > 0 {
|
|
||||||
if i, e := strconv.ParseInt(arg[0], 10, 64); e == nil {
|
|
||||||
t, stamp, arg = time.Unix(int64(i/int64(m.Confi("time_unit"))), 0), false, arg[1:]
|
|
||||||
} else if n, e := time.ParseInLocation(m.Confx("time_format"), arg[0], time.Local); e == nil {
|
|
||||||
t, arg = n, arg[1:]
|
|
||||||
} else {
|
|
||||||
for _, v := range []string{"01-02", "2006-01-02", "15:04:05", "15:04"} {
|
|
||||||
if n, e := time.ParseInLocation(v, arg[0], time.Local); e == nil {
|
|
||||||
t, arg = n, arg[1:]
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(arg) > 0 {
|
|
||||||
switch arg[0] {
|
|
||||||
case "begin":
|
|
||||||
d, e := time.ParseDuration(fmt.Sprintf("%dh%dm%ds", t.Hour(), t.Minute(), t.Second()))
|
|
||||||
m.Assert(e)
|
|
||||||
t, arg = t.Add(-d), arg[1:]
|
|
||||||
case "end":
|
|
||||||
d, e := time.ParseDuration(fmt.Sprintf("%dh%dm%ds%dns", t.Hour(), t.Minute(), t.Second(), t.Nanosecond()))
|
|
||||||
m.Assert(e)
|
|
||||||
t, arg = t.Add(time.Duration(24*time.Hour)-d), arg[1:]
|
|
||||||
if m.Confx("time_close") == "close" {
|
|
||||||
t = t.Add(-time.Second)
|
|
||||||
}
|
|
||||||
case "yestoday":
|
|
||||||
t, arg = t.Add(-time.Duration(24*time.Hour)), arg[1:]
|
|
||||||
case "tomorrow":
|
|
||||||
t, arg = t.Add(time.Duration(24*time.Hour)), arg[1:]
|
|
||||||
case "monday":
|
|
||||||
d, e := time.ParseDuration(fmt.Sprintf("%dh%dm%ds", int((t.Weekday()-time.Monday+7)%7)*24+t.Hour(), t.Minute(), t.Second()))
|
|
||||||
m.Assert(e)
|
|
||||||
t, arg = t.Add(-d), arg[1:]
|
|
||||||
case "sunday":
|
|
||||||
d, e := time.ParseDuration(fmt.Sprintf("%dh%dm%ds", int((t.Weekday()-time.Monday+7)%7)*24+t.Hour(), t.Minute(), t.Second()))
|
|
||||||
m.Assert(e)
|
|
||||||
t, arg = t.Add(time.Duration(7*24*time.Hour)-d), arg[1:]
|
|
||||||
if m.Confx("time_close") == "close" {
|
|
||||||
t = t.Add(-time.Second)
|
|
||||||
}
|
|
||||||
case "first":
|
|
||||||
t, arg = time.Date(t.Year(), t.Month(), 1, 0, 0, 0, 0, time.Local), arg[1:]
|
|
||||||
case "last":
|
|
||||||
month, year := t.Month()+1, t.Year()
|
|
||||||
if month >= 13 {
|
|
||||||
month, year = 1, year+1
|
|
||||||
}
|
|
||||||
t, arg = time.Date(year, month, 1, 0, 0, 0, 0, time.Local), arg[1:]
|
|
||||||
if m.Confx("time_close") == "close" {
|
|
||||||
t = t.Add(-time.Second)
|
|
||||||
}
|
|
||||||
case "new":
|
|
||||||
t, arg = time.Date(t.Year(), 1, 1, 0, 0, 0, 0, time.Local), arg[1:]
|
|
||||||
case "eve":
|
|
||||||
t, arg = time.Date(t.Year()+1, 1, 1, 0, 0, 0, 0, time.Local), arg[1:]
|
|
||||||
if m.Confx("time_close") == "close" {
|
|
||||||
t = t.Add(-time.Second)
|
|
||||||
}
|
|
||||||
case "":
|
|
||||||
arg = arg[1:]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(arg) > 0 {
|
|
||||||
if d, e := time.ParseDuration(arg[0]); e == nil {
|
|
||||||
t, arg = t.Add(d), arg[1:]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m.Append("datetime", t.Format(m.Confx("time_format")))
|
|
||||||
m.Append("timestamp", t.Unix()*int64(m.Confi("time_unit")))
|
|
||||||
|
|
||||||
if stamp {
|
|
||||||
m.Echo("%d", t.Unix()*int64(m.Confi("time_unit")))
|
|
||||||
} else {
|
|
||||||
m.Echo(t.Format(m.Confx("time_format")))
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}},
|
|
||||||
"notice": &ctx.Command{Name: "notice", Help: "睡眠, time(ns/us/ms/s/m/h): 时间值(纳秒/微秒/毫秒/秒/分钟/小时)", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"notice": &ctx.Command{Name: "notice", Help: "睡眠, time(ns/us/ms/s/m/h): 时间值(纳秒/微秒/毫秒/秒/分钟/小时)", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
m.Cmd("cli.system", "osascript", "-e", fmt.Sprintf("display notification \"%s\"", kit.Select("", arg, 0)))
|
m.Cmd("cli.system", "osascript", "-e", fmt.Sprintf("display notification \"%s\"", kit.Select("", arg, 0)))
|
||||||
return
|
return
|
||||||
|
@ -4,5 +4,5 @@ var version = struct {
|
|||||||
host string
|
host string
|
||||||
self int
|
self int
|
||||||
}{
|
}{
|
||||||
"2019-07-16 10:50:22", "ZYB-20190522USI.ubuntu", 177,
|
"2019-07-16 19:44:54", "ZYB-20190522USI", 171,
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package ctx
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -1185,8 +1186,8 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
"select": &Command{Name: "select key value field",
|
"select": &Command{Name: "select field...",
|
||||||
Form: map[string]int{"eq": 2, "expand": 2, "hide": -1, "fields": -1, "group": 1, "order": 2, "limit": 1, "offset": 1, "format": -1, "trans_map": -1, "vertical": 0},
|
Form: map[string]int{"reg": 2, "eq": 2, "expand": 2, "hide": -1, "fields": -1, "group": 1, "order": 2, "limit": 1, "offset": 1, "format": -1, "trans_map": -1, "vertical": 0},
|
||||||
Help: "选取数据", Hand: func(m *Message, c *Context, key string, arg ...string) (e error) {
|
Help: "选取数据", Hand: func(m *Message, c *Context, key string, arg ...string) (e error) {
|
||||||
msg := m.Set("result").Spawn()
|
msg := m.Set("result").Spawn()
|
||||||
|
|
||||||
@ -1263,6 +1264,11 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if m.Has("reg") {
|
||||||
|
if b, e := regexp.MatchString(m.Meta["reg"][1], m.Meta[m.Meta["reg"][0]][i]); e != nil || !b {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
for _, k := range arg {
|
for _, k := range arg {
|
||||||
if hides[k] {
|
if hides[k] {
|
||||||
continue
|
continue
|
||||||
|
@ -133,11 +133,11 @@ func dir(m *ctx.Message, name string, level int, deep bool, dir_type string, tri
|
|||||||
m.Assert(e)
|
m.Assert(e)
|
||||||
h := sha1.Sum(f)
|
h := sha1.Sum(f)
|
||||||
|
|
||||||
if field == "hash" {
|
if field == "hash" {
|
||||||
m.Add("append", "hash", hex.EncodeToString(h[:]))
|
m.Add("append", "hash", hex.EncodeToString(h[:]))
|
||||||
} else {
|
} else {
|
||||||
m.Add("append", "hash", hex.EncodeToString(h[:4]))
|
m.Add("append", "hash", hex.EncodeToString(h[:4]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1282,7 +1282,7 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
|||||||
strings.Split(m.Confx("dir_fields", strings.Join(arg[1:], " ")), " "),
|
strings.Split(m.Confx("dir_fields", strings.Join(arg[1:], " ")), " "),
|
||||||
m.Conf("time_format"))
|
m.Conf("time_format"))
|
||||||
} else {
|
} else {
|
||||||
if s.Size() < 100 {
|
if s.Size() < int64(m.Confi("buf_size")) {
|
||||||
p0 := p + ".tmp0"
|
p0 := p + ".tmp0"
|
||||||
f, e := os.Open(p0)
|
f, e := os.Open(p0)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
@ -1405,6 +1405,7 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
|||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
"grep": &ctx.Command{Name: "grep", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"grep": &ctx.Command{Name: "grep", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
|
hold := false
|
||||||
if len(arg) > 0 {
|
if len(arg) > 0 {
|
||||||
switch arg[0] {
|
switch arg[0] {
|
||||||
case "add":
|
case "add":
|
||||||
@ -1421,6 +1422,7 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
|
|
||||||
case "tail":
|
case "tail":
|
||||||
m.Confm("grep", "list", func(index int, value map[string]interface{}) {
|
m.Confm("grep", "list", func(index int, value map[string]interface{}) {
|
||||||
if len(arg) == 1 {
|
if len(arg) == 1 {
|
||||||
@ -1429,6 +1431,9 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
|
|
||||||
|
case "hold":
|
||||||
|
hold, arg = true, arg[1:]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1450,6 +1455,7 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
|||||||
m.Assert(e)
|
m.Assert(e)
|
||||||
|
|
||||||
n := 0
|
n := 0
|
||||||
|
offset := kit.Int(value["offset"])
|
||||||
bio := bufio.NewScanner(f)
|
bio := bufio.NewScanner(f)
|
||||||
for i := 0; i < m.Optioni("page.limit") && bio.Scan(); i++ {
|
for i := 0; i < m.Optioni("page.limit") && bio.Scan(); i++ {
|
||||||
text := bio.Text()
|
text := bio.Text()
|
||||||
@ -1459,16 +1465,19 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
|||||||
// m.Add("append", "pos",begin+int64(n))
|
// m.Add("append", "pos",begin+int64(n))
|
||||||
// m.Add("append", "len",len(text))
|
// m.Add("append", "len",len(text))
|
||||||
// m.Add("append", "end",s.Size())
|
// m.Add("append", "end",s.Size())
|
||||||
m.Add("append", "line", kit.Int(value["offset"]))
|
m.Add("append", "line", offset)
|
||||||
m.Add("append", "text", text)
|
m.Add("append", "text", text)
|
||||||
} else {
|
} else {
|
||||||
i--
|
i--
|
||||||
}
|
}
|
||||||
n += len(text) + 1
|
n += len(text) + 1
|
||||||
value["offset"] = kit.Int(value["offset"]) + 1
|
offset += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
value["pos"] = begin + int64(n)
|
if !hold {
|
||||||
|
value["offset"] = offset
|
||||||
|
value["pos"] = begin + int64(n)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
m.Table()
|
m.Table()
|
||||||
return
|
return
|
||||||
|
@ -70,11 +70,11 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
map[string]interface{}{"componet_name": "script", "componet_help": "脚本",
|
map[string]interface{}{"componet_name": "script", "componet_help": "脚本",
|
||||||
"componet_tmpl": "componet", "componet_view": "Compile", "componet_init": "",
|
"componet_tmpl": "componet", "componet_view": "Compile", "componet_init": "",
|
||||||
"componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route",
|
"componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route",
|
||||||
"componet_args": []interface{}{"$$", "context", "cli", "upgrade"}, "inputs": []interface{}{
|
"componet_args": []interface{}{"$$", "context", "cli", "upgrade", "script"}, "inputs": []interface{}{
|
||||||
map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"},
|
map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"},
|
||||||
map[string]interface{}{"type": "select", "name": "action", "values": []interface{}{"script", "portal", "system", "bench"}},
|
map[string]interface{}{"type": "text", "name": "you", "imports": "plugin_you", "view": "long"},
|
||||||
map[string]interface{}{"type": "text", "name": "action", "view": "long"},
|
map[string]interface{}{"type": "text", "name": "txt", "view": "long", "value": "test.php"},
|
||||||
map[string]interface{}{"type": "button", "value": "升级"},
|
map[string]interface{}{"type": "button", "value": "上传"},
|
||||||
},
|
},
|
||||||
"display": map[string]interface{}{"show_result": true},
|
"display": map[string]interface{}{"show_result": true},
|
||||||
},
|
},
|
||||||
@ -92,7 +92,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
"componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route",
|
"componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route",
|
||||||
"componet_args": []interface{}{"$$", "context", "nfs", "grep"}, "inputs": []interface{}{
|
"componet_args": []interface{}{"$$", "context", "nfs", "grep"}, "inputs": []interface{}{
|
||||||
map[string]interface{}{"type": "text", "name": "pod", "value": "", "imports": "plugin_pod"},
|
map[string]interface{}{"type": "text", "name": "pod", "value": "", "imports": "plugin_pod"},
|
||||||
map[string]interface{}{"type": "select", "name": "cmd", "values": []interface{}{"", "tail", "head"}},
|
map[string]interface{}{"type": "select", "name": "cmd", "values": []interface{}{"", "hold", "tail", "head"}},
|
||||||
map[string]interface{}{"type": "button", "value": "执行"},
|
map[string]interface{}{"type": "button", "value": "执行"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -134,13 +134,14 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
map[string]interface{}{"type": "text", "name": "who"},
|
map[string]interface{}{"type": "text", "name": "who"},
|
||||||
map[string]interface{}{"type": "button", "value": "执行"},
|
map[string]interface{}{"type": "button", "value": "执行"},
|
||||||
},
|
},
|
||||||
|
"exports": []interface{}{"see", "filename", "see"},
|
||||||
},
|
},
|
||||||
map[string]interface{}{"componet_name": "compile", "componet_help": "编译",
|
map[string]interface{}{"componet_name": "compile", "componet_help": "编译",
|
||||||
"componet_tmpl": "componet", "componet_view": "componet", "componet_init": "",
|
"componet_tmpl": "componet", "componet_view": "componet", "componet_init": "",
|
||||||
"componet_type": "private", "componet_ctx": "cli", "componet_cmd": "compile",
|
"componet_type": "private", "componet_ctx": "cli", "componet_cmd": "compile",
|
||||||
"componet_args": []interface{}{}, "inputs": []interface{}{
|
"componet_args": []interface{}{}, "inputs": []interface{}{
|
||||||
map[string]interface{}{"type": "select", "name": "cmd", "values": []interface{}{"plugin", "windows", "darwin", "linux", "self", "all"}},
|
map[string]interface{}{"type": "select", "name": "cmd", "values": []interface{}{"plugin", "windows", "darwin", "linux", "self", "all"}},
|
||||||
map[string]interface{}{"type": "text", "name": "who"},
|
map[string]interface{}{"type": "text", "name": "who", "imports": "plugin_see"},
|
||||||
map[string]interface{}{"type": "button", "value": "编译"},
|
map[string]interface{}{"type": "button", "value": "编译"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -148,7 +149,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
"componet_tmpl": "componet", "componet_view": "componet", "componet_init": "",
|
"componet_tmpl": "componet", "componet_view": "componet", "componet_init": "",
|
||||||
"componet_type": "private", "componet_ctx": "cli", "componet_cmd": "publish",
|
"componet_type": "private", "componet_ctx": "cli", "componet_cmd": "publish",
|
||||||
"componet_args": []interface{}{}, "inputs": []interface{}{
|
"componet_args": []interface{}{}, "inputs": []interface{}{
|
||||||
map[string]interface{}{"type": "text", "name": "who"},
|
map[string]interface{}{"type": "text", "name": "who", "imports": "plugin_see"},
|
||||||
map[string]interface{}{"type": "button", "value": "发布"},
|
map[string]interface{}{"type": "button", "value": "发布"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -283,7 +284,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
"componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route",
|
"componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route",
|
||||||
"componet_args": []interface{}{"$$", "context", "nfs", "dir", "$$", "time", "size", "line", "path"}, "inputs": []interface{}{
|
"componet_args": []interface{}{"$$", "context", "nfs", "dir", "$$", "time", "size", "line", "path"}, "inputs": []interface{}{
|
||||||
map[string]interface{}{"type": "text", "name": "pod", "imports": []interface{}{"plugin_you", "plugin_pod"}},
|
map[string]interface{}{"type": "text", "name": "pod", "imports": []interface{}{"plugin_you", "plugin_pod"}},
|
||||||
map[string]interface{}{"type": "text", "name": "dir", "value": "", "view": "long", "imports": "plugin_dir", "action": "auto"},
|
map[string]interface{}{"type": "text", "name": "dir", "value": "usr/script", "view": "long", "imports": "plugin_dir", "action": "auto"},
|
||||||
map[string]interface{}{"type": "button", "value": "查看", "action": "auto"},
|
map[string]interface{}{"type": "button", "value": "查看", "action": "auto"},
|
||||||
map[string]interface{}{"type": "button", "value": "回退", "click": "Back"},
|
map[string]interface{}{"type": "button", "value": "回退", "click": "Back"},
|
||||||
},
|
},
|
||||||
@ -350,6 +351,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
"componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route",
|
"componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route",
|
||||||
"componet_args": []interface{}{"$$", "context", "cli", "proc"}, "inputs": []interface{}{
|
"componet_args": []interface{}{"$$", "context", "cli", "proc"}, "inputs": []interface{}{
|
||||||
map[string]interface{}{"type": "text", "name": "pod", "value": "", "imports": "plugin_pod"},
|
map[string]interface{}{"type": "text", "name": "pod", "value": "", "imports": "plugin_pod"},
|
||||||
|
map[string]interface{}{"type": "text", "name": "cmd", "value": ""},
|
||||||
map[string]interface{}{"type": "text", "name": "cmd", "view": "long"},
|
map[string]interface{}{"type": "text", "name": "cmd", "view": "long"},
|
||||||
map[string]interface{}{"type": "button", "value": "执行"},
|
map[string]interface{}{"type": "button", "value": "执行"},
|
||||||
},
|
},
|
||||||
@ -387,7 +389,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
m.Add("append", "pod", key)
|
m.Add("append", "pod", key)
|
||||||
m.Add("append", "type", value["type"])
|
m.Add("append", "type", value["type"])
|
||||||
})
|
})
|
||||||
m.Sort("key").Table()
|
m.Sort("pod").Table()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -557,10 +559,10 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
m.Add("append", "help", value["componet_help"])
|
m.Add("append", "help", value["componet_help"])
|
||||||
m.Add("append", "view", value["componet_view"])
|
m.Add("append", "view", value["componet_view"])
|
||||||
if kit.Right(value["componet_init"]) {
|
if kit.Right(value["componet_init"]) {
|
||||||
script := m.Cmdx("nfs.load", path.Join(m.Conf("cli.publish", "path"), arg[0], kit.Format(value["componet_init"])), -1)
|
script := m.Cmdx("nfs.load", path.Join(m.Conf("cli.publish", "path"), arg[0], kit.Format(value["componet_init"])), -1)
|
||||||
if script == "" {
|
if script == "" {
|
||||||
script = m.Cmdx("nfs.load", path.Join("usr/librarys/plugin", kit.Format(value["componet_init"])), -1)
|
script = m.Cmdx("nfs.load", path.Join("usr/librarys/plugin", kit.Format(value["componet_init"])), -1)
|
||||||
}
|
}
|
||||||
m.Add("append", "init", script)
|
m.Add("append", "init", script)
|
||||||
} else {
|
} else {
|
||||||
m.Add("append", "init", "")
|
m.Add("append", "init", "")
|
||||||
@ -649,6 +651,8 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
} else if node.Appends("user.route") && !m.Confs("runtime", "user.route") {
|
} else if node.Appends("user.route") && !m.Confs("runtime", "user.route") {
|
||||||
m.Cmd("ssh.user", "create", node.Append("user.route"))
|
m.Cmd("ssh.user", "create", node.Append("user.route"))
|
||||||
}
|
}
|
||||||
|
m.Log("info", "script %v", m.Append("work.script"))
|
||||||
|
m.Cmd("nfs.save", "etc/temp.shy", m.Append("work.script"))
|
||||||
|
|
||||||
// 工作路由
|
// 工作路由
|
||||||
if node.Appends("work.route") && !m.Confs("runtime", "work.route") {
|
if node.Appends("work.route") && !m.Confs("runtime", "work.route") {
|
||||||
@ -676,6 +680,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
m.Append("node.route", m.Conf("runtime", "node.route"))
|
m.Append("node.route", m.Conf("runtime", "node.route"))
|
||||||
m.Append("user.route", m.Conf("runtime", "user.route"))
|
m.Append("user.route", m.Conf("runtime", "user.route"))
|
||||||
m.Append("work.route", m.Conf("runtime", "work.route"))
|
m.Append("work.route", m.Conf("runtime", "work.route"))
|
||||||
|
m.Append("work.script", m.Cmdx("nfs.load", path.Join(m.Conf("cli.publish", "script."+arg[2]))))
|
||||||
m.Echo(name).Back(m)
|
m.Echo(name).Back(m)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -554,7 +554,7 @@ function Pane(page, field) {
|
|||||||
return typeof value == "object"? {className: value[0], select: [value.slice(1), function(value, event) {
|
return typeof value == "object"? {className: value[0], select: [value.slice(1), function(value, event) {
|
||||||
value = event.target.value
|
value = event.target.value
|
||||||
typeof pane.Action == "function"? pane.Action(value, event): pane.Action[value](event, value)
|
typeof pane.Action == "function"? pane.Action(value, event): pane.Action[value](event, value)
|
||||||
}]}: value == ""? {view: ["space"]} :value == "br"? {type: "br"}: {button: [value, function(event) {
|
}]}: value == ""? {view: ["space"]} :value == "br"? {type: "br"}: {button: [value, function(value, event) {
|
||||||
typeof pane.Action == "function"? pane.Action(value, event): pane.Action[value](event, value)
|
typeof pane.Action == "function"? pane.Action(value, event): pane.Action[value](event, value)
|
||||||
}]}
|
}]}
|
||||||
})).className="action "+name)
|
})).className="action "+name)
|
||||||
@ -754,41 +754,6 @@ function Plugin(page, pane, field) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
ondaemon: {
|
ondaemon: {
|
||||||
editor: function(msg, cb) {
|
|
||||||
output.innerHTML = ""
|
|
||||||
!display.hide_append && msg.append && kit.OrderTable(kit.AppendTable(kit.AppendChild(output, "table"), ctx.Table(msg), msg.append), exports[1], function(event, value, name, line) {
|
|
||||||
page.Sync("plugin_"+exports[0]).set(plugin.onexport[exports[2]||""](value, name, line))
|
|
||||||
});
|
|
||||||
|
|
||||||
var args = [option.pod.value, option.dir.value]
|
|
||||||
|
|
||||||
if (msg.file) {
|
|
||||||
var action = kit.AppendAction(kit.AppendChild(output, [{view: ["action"]}]).last, [
|
|
||||||
"追加", "提交", "取消",
|
|
||||||
], function(value, event) {
|
|
||||||
switch (value) {
|
|
||||||
case "追加":
|
|
||||||
field.Run(event, args.concat(["dir_sed", "add"]))
|
|
||||||
break
|
|
||||||
case "提交":
|
|
||||||
field.Run(event, args.concat(["dir_sed", "put"]))
|
|
||||||
break
|
|
||||||
case "取消":
|
|
||||||
break
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
kit.AppendChild(output, [{view: ["edit", "table"], list: msg.result.map(function(value, index) {
|
|
||||||
return {view: ["line", "tr"], list: [{view: ["num", "td", index+1]}, {view: ["txt", "td"], list: [{value: value, input: [value, function(event) {
|
|
||||||
if (event.key == "Enter") {
|
|
||||||
field.Run(event, args.concat(["dir_sed", "set", index, event.target.value]))
|
|
||||||
}
|
|
||||||
}]}]}]}
|
|
||||||
})}])
|
|
||||||
}
|
|
||||||
|
|
||||||
typeof cb == "function" && cb(msg)
|
|
||||||
},
|
|
||||||
table: function(msg, cb) {
|
table: function(msg, cb) {
|
||||||
output.innerHTML = ""
|
output.innerHTML = ""
|
||||||
!display.hide_append && msg.append && kit.OrderTable(kit.AppendTable(kit.AppendChild(output, "table"), ctx.Table(msg), msg.append), exports[1], function(event, value, name, line) {
|
!display.hide_append && msg.append && kit.OrderTable(kit.AppendTable(kit.AppendChild(output, "table"), ctx.Table(msg), msg.append), exports[1], function(event, value, name, line) {
|
||||||
@ -797,6 +762,12 @@ function Plugin(page, pane, field) {
|
|||||||
(display.show_result || !msg.append) && msg.result && kit.OrderCode(kit.AppendChild(output, [{view: ["code", "div", msg.Results()]}]).first)
|
(display.show_result || !msg.append) && msg.result && kit.OrderCode(kit.AppendChild(output, [{view: ["code", "div", msg.Results()]}]).first)
|
||||||
typeof cb == "function" && cb(msg)
|
typeof cb == "function" && cb(msg)
|
||||||
},
|
},
|
||||||
|
editor: function(msg, cb) {
|
||||||
|
(output.innerHTML = "", Editor(plugin, option, output, output.clientWidth-40, 400, 10, msg))
|
||||||
|
},
|
||||||
|
canvas: function(msg, cb) {
|
||||||
|
typeof cb == "function" && !cb(msg) || (output.innerHTML = "", Canvas(plugin, option, output, output.clientWidth-40, 400, 10, msg))
|
||||||
|
},
|
||||||
trend: function(msg, cb) {
|
trend: function(msg, cb) {
|
||||||
typeof cb == "function" && !cb(msg) || (output.innerHTML = "", Canvas(plugin, output, output.clientWidth-40, 400, 10, msg))
|
typeof cb == "function" && !cb(msg) || (output.innerHTML = "", Canvas(plugin, output, output.clientWidth-40, 400, 10, msg))
|
||||||
},
|
},
|
||||||
@ -830,6 +801,9 @@ function Plugin(page, pane, field) {
|
|||||||
"": function(value, name) {
|
"": function(value, name) {
|
||||||
return value
|
return value
|
||||||
},
|
},
|
||||||
|
see: function(value, name, line) {
|
||||||
|
return value.split("/")[0]
|
||||||
|
},
|
||||||
you: function(value, name, line) {
|
you: function(value, name, line) {
|
||||||
window.event.Plugin = plugin
|
window.event.Plugin = plugin
|
||||||
line.you && name == "status" && (line.status == "start"? function() {
|
line.you && name == "status" && (line.status == "start"? function() {
|
||||||
@ -883,7 +857,40 @@ function Plugin(page, pane, field) {
|
|||||||
plugin.init(page, pane, field, option, output)
|
plugin.init(page, pane, field, option, output)
|
||||||
return page[field.id] = pane[field.id] = plugin.Field = field, field.Plugin = plugin
|
return page[field.id] = pane[field.id] = plugin.Field = field, field.Plugin = plugin
|
||||||
}
|
}
|
||||||
function Canvas(plugin, output, width, height, space, msg) {
|
function Editor(plugin, option, output, width, height, space, msg) {
|
||||||
|
exports = ["dir", "path", "dir"]
|
||||||
|
msg.append && kit.OrderTable(kit.AppendTable(kit.AppendChild(output, "table"), ctx.Table(msg), msg.append), exports[1], function(event, value, name, line) {
|
||||||
|
page.Sync("plugin_"+exports[0]).set(plugin.onexport[exports[2]||""](value, name, line))
|
||||||
|
});
|
||||||
|
|
||||||
|
var args = [option.pod.value, option.dir.value]
|
||||||
|
|
||||||
|
if (msg.file) {
|
||||||
|
var action = kit.AppendAction(kit.AppendChild(output, [{view: ["action"]}]).last, [
|
||||||
|
"追加", "提交", "取消",
|
||||||
|
], function(value, event) {
|
||||||
|
switch (value) {
|
||||||
|
case "追加":
|
||||||
|
field.Run(event, args.concat(["dir_sed", "add"]))
|
||||||
|
break
|
||||||
|
case "提交":
|
||||||
|
field.Run(event, args.concat(["dir_sed", "put"]))
|
||||||
|
break
|
||||||
|
case "取消":
|
||||||
|
break
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
kit.AppendChild(output, [{view: ["edit", "table"], list: msg.result.map(function(value, index) {
|
||||||
|
return {view: ["line", "tr"], list: [{view: ["num", "td", index+1]}, {view: ["txt", "td"], list: [{value: value, style: {width: width+"px"}, input: [value, function(event) {
|
||||||
|
if (event.key == "Enter") {
|
||||||
|
field.Run(event, args.concat(["dir_sed", "set", index, event.target.value]))
|
||||||
|
}
|
||||||
|
}]}]}]}
|
||||||
|
})}])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function Canvas(plugin, option, output, width, height, space, msg) {
|
||||||
var keys = [], data = {}, max = {}, nline = 0
|
var keys = [], data = {}, max = {}, nline = 0
|
||||||
var nrow = msg[msg.append[0]].length
|
var nrow = msg[msg.append[0]].length
|
||||||
var step = width / (nrow - 1)
|
var step = width / (nrow - 1)
|
||||||
@ -1603,3 +1610,4 @@ function Canvas(plugin, output, width, height, space, msg) {
|
|||||||
|
|
||||||
return what.reset().refresh()
|
return what.reset().refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user