1
0
mirror of https://shylinux.com/x/ContextOS synced 2025-04-25 16:58:06 +08:00

opt cli.project

This commit is contained in:
shaoying 2019-07-15 08:49:22 +08:00
parent d2304e5bda
commit 13520059c7
53 changed files with 559 additions and 253 deletions

View File

@ -8,6 +8,7 @@
config load tmp/data.json ktv config load tmp/data.json ktv
~wiki ~wiki
config load tmp/wiki.json wiki_visit config load tmp/wiki.json wiki_visit
source etc/common.shy source etc/common.shy
~ssh ~ssh
remote auto remote auto

View File

@ -6,6 +6,7 @@ import (
"contexts/ctx" "contexts/ctx"
"encoding/csv" "encoding/csv"
"encoding/json" "encoding/json"
"io/ioutil"
"os/exec" "os/exec"
"os/user" "os/user"
"path" "path"
@ -144,13 +145,8 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
"action": &ctx.Config{Name: "action", Value: map[string]interface{}{}, Help: "交互任务"}, "action": &ctx.Config{Name: "action", Value: map[string]interface{}{}, Help: "交互任务"},
"project": &ctx.Config{Name: "project", Value: map[string]interface{}{ "project": &ctx.Config{Name: "project", Value: map[string]interface{}{
// vim git golang "github": "https://github.com/shylinux/context",
"ubuntu": map[string]interface{}{}, "goproxy": "https://goproxy.cn", "import": []interface{}{
"github": "https://github.com/shylinux/context",
"env": map[string]interface{}{
"GOPATH": "https://github.com/shylinux/context",
},
"import": []interface{}{
"github.com/nsf/termbox-go", "github.com/nsf/termbox-go",
"github.com/gomodule/redigo/redis", "github.com/gomodule/redigo/redis",
"github.com/go-sql-driver/mysql", "github.com/go-sql-driver/mysql",
@ -159,13 +155,28 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
"github.com/skip2/go-qrcode", "github.com/skip2/go-qrcode",
"github.com/PuerkitoBio/goquery", "github.com/PuerkitoBio/goquery",
"github.com/go-cas/cas", "github.com/go-cas/cas",
}, "plugin": map[string]interface{}{
"path": "src/plugin", "list": []interface{}{
map[string]interface{}{"name": "index.go", "text": ""},
map[string]interface{}{"name": "index.js", "text": ""},
map[string]interface{}{"name": "local.shy", "text": ""},
},
}, "script": map[string]interface{}{
"path": "usr/script",
}, },
}, Help: "运行环境"}, }, Help: "项目管理"},
"compile": &ctx.Config{Name: "compile", Value: map[string]interface{}{ "compile": &ctx.Config{Name: "compile", Value: map[string]interface{}{
"bench": "src/extend/bench.go", "bench": "src/extend/bench.go", "list": []interface{}{
"tmp": "var/tmp/go", map[string]interface{}{"os": "linux", "cpu": "amd64"},
"env": []interface{}{"GOPATH", "PATH"}, map[string]interface{}{"os": "linux", "cpu": "386"},
}, Help: "运行环境"}, map[string]interface{}{"os": "linux", "cpu": "arm"},
map[string]interface{}{"os": "windows", "cpu": "amd64"},
map[string]interface{}{"os": "windows", "cpu": "386"},
map[string]interface{}{"os": "darwin", "cpu": "amd64"},
},
"env": []interface{}{"GOPATH", "PATH"},
"tmp": "var/tmp/go",
}, Help: "源码编译"},
"publish": &ctx.Config{Name: "publish", Value: map[string]interface{}{ "publish": &ctx.Config{Name: "publish", Value: map[string]interface{}{
"path": "usr/publish", "list": map[string]interface{}{ "path": "usr/publish", "list": map[string]interface{}{
"boot_sh": "bin/boot.sh", "boot_sh": "bin/boot.sh",
@ -177,7 +188,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
"template_tar_gz": "usr/template", "template_tar_gz": "usr/template",
"librarys_tar_gz": "usr/librarys", "librarys_tar_gz": "usr/librarys",
}, },
}, 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"},
"portal": []interface{}{"template.tar.gz", "librarys.tar.gz"}, "portal": []interface{}{"template.tar.gz", "librarys.tar.gz"},
@ -193,10 +204,10 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
"template_tar_gz": "usr/template.tar.gz", "template_tar_gz": "usr/template.tar.gz",
"librarys_tar_gz": "usr/librarys.tar.gz", "librarys_tar_gz": "usr/librarys.tar.gz",
}, },
}, Help: "日志地址"}, }, Help: "服务升级"},
"missyou": &ctx.Config{Name: "missyou", Value: map[string]interface{}{ "missyou": &ctx.Config{Name: "missyou", Value: map[string]interface{}{
"path": "usr/work", "path": "usr/local/work", "local": "usr/local",
}, Help: "免密登录"}, }, Help: "任务管理"},
"timer": &ctx.Config{Name: "timer", Value: map[string]interface{}{}, Help: "定时器"}, "timer": &ctx.Config{Name: "timer", Value: map[string]interface{}{}, Help: "定时器"},
"timer_next": &ctx.Config{Name: "timer_next", Value: "", Help: "定时器"}, "timer_next": &ctx.Config{Name: "timer_next", Value: "", Help: "定时器"},
@ -639,28 +650,24 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
return return
}}, }},
"project": &ctx.Command{Name: "project", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { "project": &ctx.Command{Name: "project init|stat|import|plugin", Help: "项目管理, ", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
switch arg[0] { switch arg[0] {
case "prepare":
case "init": case "init":
if _, e := os.Stat(".git"); e == nil { if _, e := os.Stat(".git"); e == nil {
m.Cmdp(0, []string{"git update"}, []string{"cli.system", "git"}, [][]string{ m.Cmdp(0, []string{"git update"}, []string{"cli.system", "git"}, [][]string{
[]string{"git", "stash"}, []string{"git", "stash"}, []string{"git", "pull"}, []string{"git", "stash", "pop"},
[]string{"git", "pull"},
[]string{"git", "stash", "pop"},
}) })
m.Cmdy("nfs.git", "status")
return e return e
} }
m.Cmdp(0, []string{"git init"}, []string{"cli.system", "git"}, [][]string{ m.Cmdp(0, []string{"git init"}, []string{"cli.system", "git"}, [][]string{
[]string{"init"}, []string{"init"}, []string{"remote", "add", kit.Select("origin", arg, 1), kit.Select(m.Conf("project", "github"), arg, 2)},
[]string{"remote", "add", kit.Select("origin", arg, 1), kit.Select(m.Conf("project", "github"), arg, 2)}, []string{"stash"}, []string{"pull"}, []string{"checkout", "-f", "master"}, []string{"stash", "pop"},
[]string{"stash"},
[]string{"pull"},
[]string{"checkout", "-f", "master"},
[]string{"stash", "pop"},
}) })
case "stat":
m.Cmdy("nfs.dir", "src", "dir_deep", "dir_type", "file", "dir_sort", "line", "int_r").CopyTo(m, "append")
case "import": case "import":
list := [][]string{} list := [][]string{}
m.Confm("project", "import", func(index int, value string) { m.Confm("project", "import", func(index int, value string) {
@ -671,44 +678,67 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
m.Table() m.Table()
m.Cmdp(time.Second, []string{"go init"}, []string{"cli.system", "go", "get", m.Cmdp(time.Second, []string{"go init"}, []string{"cli.system", "go", "get",
"cmd_env", "GOPROXY", m.Conf("project", "goproxy"),
"cmd_env", "GOPATH", m.Conf("runtime", "boot.ctx_path")}, list) "cmd_env", "GOPATH", m.Conf("runtime", "boot.ctx_path")}, list)
case "stat":
m.Cmd("nfs.dir", "src", "dir_deep", "dir_type", "file").CopyTo(m, "append") case "plugin":
m.Cmd("nfs.dir", "usr/librarys", "dir_deep", "dir_type", "file").CopyTo(m, "append") arg = arg[1:]
m.Set("result").Table() if len(arg) == 0 {
m.Cmdy("nfs.dir", m.Conf("project", "plugin.path"))
break
}
fallthrough
default:
p := path.Join(m.Conf("project", "plugin.path"), arg[0])
if _, e := os.Stat(p); os.IsNotExist(e) && m.Assert(os.MkdirAll(p, 0777)) {
m.Confm("project", "plugin.list", func(index int, value map[string]interface{}) {
ioutil.WriteFile(path.Join(p, kit.Format(value["name"])), []byte(kit.Format(value["text"])), 0666)
})
}
m.Cmdy("nfs.dir", p, "time", "size", "line", "path")
} }
return return
}}, }},
"compile": &ctx.Command{Name: "compile [OS [ARCH]]", Help: "解析脚本, script: 脚本文件, stdio: 命令终端, snippet: 代码片段", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { "compile": &ctx.Command{Name: "compile all|self|[[[plugin] name] [OS [ARCH]]]", Help: "源码编译", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
m.Cmd("cli.version", "create") switch arg[0] {
if len(arg) > 0 && arg[0] == "self" { case "all":
if m.Cmdy("cli.system", "go", "install", m.Cmdx("nfs.path", m.Conf("compile", "bench"))); m.Result(0) == "" { list := [][]string{}
m.Echo("%v: %v ", version.host, version.self) m.Confm("compile", "list", func(index int, value map[string]interface{}) {
m.Cmdy("cli.quit", 1) list = append(list, []string{kit.Format(value["os"]), kit.Format(value["cpu"])})
}
return
}
if len(arg) > 0 && arg[0] == "all" {
m.Cmdp(0, []string{"go build"}, []string{"cli.compile"}, [][]string{
[]string{"linux", "386"},
[]string{"linux", "amd64"},
[]string{"linux", "arm"},
[]string{"windows", "386"},
[]string{"windows", "amd64"},
[]string{"darwin", "amd64"},
}) })
m.Echo("done %s", m.Time()) m.Cmdp(0, []string{"go build"}, []string{"cli.compile"}, list)
return m.Cmdy("nfs.dir", m.Conf("publish", "path"), "dir_reg", "bench")
}
if len(arg) > 0 { case "self":
m.Cmd("cli.version", "create")
if m.Cmdy("cli.system", "go", "install", m.Cmdx("nfs.path", m.Conf("compile", "bench"))); m.Result(0) == "" {
m.Cmdy("cli.quit", 1)
m.Append("host", version.host)
m.Append("self", version.self)
m.Table()
}
case "plugin":
arg = arg[1:]
if len(arg) == 0 {
m.Cmdy("nfs.dir", m.Conf("publish", "path"), "dir_deep", "dir_reg", ".*\\.so", "time", "size", "hash", "path")
break
}
fallthrough
default:
p, q, o := path.Join(m.Conf("project", "plugin.path"), arg[0], "index.go"), "", []string{}
if _, e := os.Stat(p); e == nil {
q = path.Join(m.Conf("publish", "path"), arg[0], "index.so")
o = []string{"-buildmode=plugin"}
arg = arg[1:]
}
goos := kit.Select(m.Conf("runtime", "host.GOOS"), arg, 0) goos := kit.Select(m.Conf("runtime", "host.GOOS"), arg, 0)
arch := kit.Select(m.Conf("runtime", "host.GOARCH"), arg, 1) arch := kit.Select(m.Conf("runtime", "host.GOARCH"), arg, 1)
name := strings.Join([]string{"bench", goos, arch}, "_")
wd, _ := os.Getwd() wd, _ := os.Getwd()
os.MkdirAll(m.Conf("compile", "tmp"), 0777) os.MkdirAll(m.Conf("compile", "tmp"), 0777)
env := []string{"cmd_env", "GOOS", goos, "cmd_env", "GOARCH", arch, "cmd_env", env := []string{"cmd_env", "GOOS", goos, "cmd_env", "GOARCH", arch,
"cmd_env", "GOTMPDIR", path.Join(wd, m.Conf("compile", "tmp")), "cmd_env", "GOTMPDIR", path.Join(wd, m.Conf("compile", "tmp")),
"cmd_env", "GOCACHE", path.Join(wd, m.Conf("compile", "tmp")), "cmd_env", "GOCACHE", path.Join(wd, m.Conf("compile", "tmp")),
} }
@ -716,18 +746,21 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
env = append(env, "cmd_env", key, kit.Select(os.Getenv(key), m.Option(key))) env = append(env, "cmd_env", key, kit.Select(os.Getenv(key), m.Option(key)))
}) })
p := m.Cmdx("nfs.path", m.Conf("compile", "bench")) if q == "" {
q := path.Join(m.Conf("publish", "path"), name) q = path.Join(m.Conf("publish", "path"), strings.Join([]string{"bench", goos, arch}, "_"))
if m.Cmdy("cli.system", env, "go", "build", "-o", q, p); m.Result(0) == "" { p = m.Cmdx("nfs.path", m.Conf("compile", "bench"))
}
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("bin", name) m.Append("bin", q)
m.Append("hash", kit.Hashs(q)) m.Append("hash", kit.Hashs(q))
m.Table() m.Table()
} }
} }
return return
}}, }},
"publish": &ctx.Command{Name: "publish", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { "publish": &ctx.Command{Name: "publish", Help: "版本发布", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
dir := m.Conf("publish", "path") dir := m.Conf("publish", "path")
m.Assert(os.MkdirAll(dir, 0777)) m.Assert(os.MkdirAll(dir, 0777))
@ -740,6 +773,16 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
return return
} }
p := path.Join(m.Conf("project", "plugin.path"), arg[0])
q := path.Join(m.Conf("publish", "path"), arg[0])
if _, e := os.Stat(p); e == nil && m.Assert(os.MkdirAll(q, 0777)) {
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.Cmdy("nfs.dir", q, "time", "size", "hash", "path")
return e
}
for _, key := range arg { for _, key := range arg {
key = kit.Key(key) key = kit.Key(key)
value := m.Conf("publish", []string{"list", key}) value := m.Conf("publish", []string{"list", key})
@ -757,105 +800,91 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
} }
} }
m.Table() m.Table()
// m.Cmdy("nfs.dir", dir, "dir_sort", "time", "time_r")
return return
}}, }},
"version": &ctx.Command{Name: "version", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { "upgrade": &ctx.Command{Name: "upgrade project|bench|system|portal|plugin|script", Help: "服务升级", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
if len(arg) == 0 {
types := reflect.TypeOf(version)
value := reflect.ValueOf(version)
for i := 0; i < types.NumField(); i++ {
key := types.Field(i)
val := value.Field(i)
m.Add("append", "name", key.Name)
m.Add("append", "type", key.Type.Name())
m.Add("append", "value", fmt.Sprintf("%v", val))
}
m.Table()
return
}
m.Cmd("nfs.save", path.Join(m.Conf("runtime", "boot.ctx_home"), "src/contexts/cli/version.go"), fmt.Sprintf(`package cli
var version = struct {
time string
host string
self int
}{
"%s", "%s", %d,
}
`, m.Time(), m.Conf("runtime", "node.route"), version.self+1))
m.Append("directory", "")
return
}},
"upgrade": &ctx.Command{Name: "upgrade project|bench|system|plugin|portal|script", Help: "服务升级", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
if len(arg) == 0 { if len(arg) == 0 {
m.Cmdy("ctx.config", "upgrade") m.Cmdy("ctx.config", "upgrade")
return return
} }
if len(arg) > 0 && arg[0] == "project" { switch arg[0] {
case "project":
m.Cmd("cli.project", "init") m.Cmd("cli.project", "init")
m.Cmd("cli.compile", "all") m.Cmd("cli.compile", "all")
m.Cmd("cli.publish") m.Cmd("cli.publish")
return
} case "script":
if len(arg) > 0 && arg[0] == "plugin" { if len(arg) == 1 {
m.Cmdy("web.get", "dev", fmt.Sprintf("publish/%s", arg[1]), m.Cmdy("nfs.dir", m.Conf("project", "script.path"), "time", "size", "line", "hash", "path")
"upgrade", "plugin", "save", path.Join("src/plugin", arg[1])) break
m.Cmdy("cli.plugin", "test.so") }
return
}
if len(arg) > 1 && arg[0] == "script" {
miss := "" miss := ""
if len(arg) > 2 { if len(arg) > 2 {
miss, arg = arg[1], arg[2:] miss, arg = arg[1], arg[1:]
} else {
arg = arg[1:]
} }
for _, v := range arg { for _, v := range arg[1:] {
m.Cmdy("web.get", "dev", fmt.Sprintf("publish/%s", v), m.Cmdy("web.get", "dev", fmt.Sprintf("publish/%s", v),
"upgrade", "script", "missyou", miss, "save", path.Join("usr/script", v)) "upgrade", "script", "missyou", miss, "save", path.Join("usr/script", v))
} }
return
}
restart := false case "plugin":
for _, link := range kit.View([]string{arg[0]}, m.Confm("upgrade")) { if arg = arg[1:]; len(arg) == 0 {
file := kit.Select(link, m.Conf("upgrade", []string{"list", strings.Replace(link, ".", "_", -1)})) m.Cmdy("cli.context")
if arg[0] == "script" { break
file = path.Join("usr/script", file)
} }
fallthrough
m.Cmd("web.get", "dev", fmt.Sprintf("publish/%s", link), default:
"GOARCH", m.Conf("runtime", "host.GOARCH"), if p, e := plugin.Open(path.Join(m.Conf("publish", "path"), arg[0], "index.so")); e == nil {
"GOOS", m.Conf("runtime", "host.GOOS"), if s, e := p.Lookup("Index"); m.Assert(e) {
"upgrade", arg[0], "save", file) msg := m.Spawn(c.Register(*(s.(**ctx.Context)), nil, arg[0])).Cmd("_init", arg[1:])
msg.Cap("stream", arg[0])
if strings.HasPrefix(file, "bin/") { msg.Confm("index", func(index int, value map[string]interface{}) {
if m.Cmd("cli.system", "chmod", "a+x", file); link == "bench" { value["componet_ctx"] = "cli." + arg[0]
m.Cmd("cli.system", "mv", "bin/bench", fmt.Sprintf("bin/bench_%s", m.Time("20060102_150405"))) m.Conf("ssh.componet", []interface{}{arg[0], index}, value)
m.Cmd("cli.system", "mv", "bin/bench.new", "bin/bench") m.Add("append", "index", index)
file = "bin/bench" m.Add("append", "name", value["componet_name"])
m.Add("append", "help", value["componet_help"])
})
m.Table()
} }
restart = true return e
} }
m.Add("append", "time", m.Time()) restart := false
m.Add("append", "file", file) for _, link := range kit.View([]string{arg[0]}, m.Confm("upgrade")) {
m.Add("append", "hash", kit.Hashs(file)) file := kit.Select(link, m.Conf("upgrade", []string{"list", strings.Replace(link, ".", "_", -1)}))
if strings.HasSuffix(link, ".tar.gz") { m.Cmd("web.get", "dev", fmt.Sprintf("publish/%s", link),
m.Cmd("cli.system", "tar", "-xvf", file, "-C", path.Dir(file)) "GOARCH", m.Conf("runtime", "host.GOARCH"),
"GOOS", m.Conf("runtime", "host.GOOS"),
"upgrade", arg[0], "save", file)
if strings.HasPrefix(file, "bin/") {
if m.Cmd("cli.system", "chmod", "a+x", file); link == "bench" {
m.Cmd("cli.system", "mv", "bin/bench", fmt.Sprintf("bin/bench_%s", m.Time("20060102_150405")))
m.Cmd("cli.system", "mv", "bin/bench.new", "bin/bench")
file = "bin/bench"
}
restart = true
}
m.Add("append", "time", m.Time())
m.Add("append", "file", file)
m.Add("append", "hash", kit.Hashs(file))
if strings.HasSuffix(link, ".tar.gz") {
m.Cmd("cli.system", "tar", "-xvf", file, "-C", path.Dir(file))
}
}
if m.Table(); restart {
m.Cmd("cli.quit", 1)
} }
} }
m.Table()
if restart {
m.Cmd("cli.quit", 1)
}
return return
}}, }},
"missyou": &ctx.Command{Name: "missyou", Help: "服务升级", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { "missyou": &ctx.Command{Name: "missyou [name [stop]]", Help: "任务管理", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
if len(arg) == 0 { if len(arg) == 0 {
m.Option("dir_root", "") m.Option("dir_root", "")
m.Cmd("nfs.dir", m.Conf("missyou", "path")).Table(func(value map[string]string) { m.Cmd("nfs.dir", m.Conf("missyou", "path")).Table(func(value map[string]string) {
@ -888,31 +917,56 @@ var version = struct {
p := path.Join(m.Conf("missyou", "path"), arg[0]) p := path.Join(m.Conf("missyou", "path"), arg[0])
if _, e := os.Stat(p); e != nil { if _, e := os.Stat(p); e != nil {
m.Cmd("nfs.copy", path.Join(p, "etc/local.shy"), "usr/missyou/job.shy") m.Cmd("nfs.copy", path.Join(p, "etc/local.shy"), path.Join(m.Conf("publish", "path"), kit.Select("hello", arg, 1), "local.shy"))
m.Confm("missyou", "local", func(index string, local string) { m.Confm("missyou", "local", func(index string, local string) {
m.Cmd("nfs.git", "clone", local, path.Join(p, "usr/local", index)) m.Cmd("nfs.git", "clone", local, path.Join(p, m.Conf("missyou", "local"), index))
}) })
} }
m.Cmdy("cli.system", path.Join(m.Conf("runtime", "boot.ctx_home"), "bin/node.sh"), "create", arg[0], args := []string{
"daemon", "daemon", "cmd_dir", p,
"cmd_env", "PATH", os.Getenv("path"), "cmd_env", "PATH", os.Getenv("PATH"),
"cmd_dir", m.Conf("missyou", "path"),
"cmd_env", "ctx_home", m.Conf("runtime", "boot.ctx_home"), "cmd_env", "ctx_home", m.Conf("runtime", "boot.ctx_home"),
"cmd_env", "ctx_ups", fmt.Sprintf("127.0.0.1%s", m.Conf("runtime", "boot.ssh_port")), "cmd_env", "ctx_ups", fmt.Sprintf("127.0.0.1%s", m.Conf("runtime", "boot.ssh_port")),
"cmd_env", "ctx_box", fmt.Sprintf("http://127.0.0.1%s", m.Conf("runtime", "boot.web_port")), "cmd_env", "ctx_box", fmt.Sprintf("http://127.0.0.1%s", m.Conf("runtime", "boot.web_port")),
"cmd_daemon", "true", "cmd_daemon", "true",
) }
return if m.Conf("runtime", "host.GOOS") == "windows" {
m.Cmdy("cli.system", m.Conf("runtime", "boot.ctx_bin"), "daemon", m.Cmdy("cli.system", path.Join(m.Conf("runtime", "boot.ctx_home"), "bin/node.sh"), args)
"cmd_dir", p, } else {
"cmd_env", "ctx_home", m.Conf("runtime", "boot.ctx_home"), m.Cmdy("cli.system", m.Conf("runtime", "boot.ctx_bin"), args)
"cmd_env", "ctx_box", fmt.Sprintf("http://127.0.0.1%s", m.Conf("runtime", "boot.web_port")), }
"cmd_daemon", "true",
)
return return
}}, }},
"version": &ctx.Command{Name: "version", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
if len(arg) == 0 {
types := reflect.TypeOf(version)
value := reflect.ValueOf(version)
for i := 0; i < types.NumField(); i++ {
key := types.Field(i)
val := value.Field(i)
m.Add("append", "name", key.Name)
m.Add("append", "type", key.Type.Name())
m.Add("append", "value", fmt.Sprintf("%v", val))
}
m.Table()
return
}
m.Cmd("nfs.save", path.Join(m.Conf("runtime", "boot.ctx_home"), "src/contexts/cli/version.go"), fmt.Sprintf(`package cli
var version = struct {
time string
host string
self int
}{
"%s", "%s", %d,
}
`, m.Time(), m.Conf("runtime", "node.route"), version.self+1))
m.Append("directory", "")
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) { "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 { if len(arg) == 0 {
m.Cmdy("dir", "", "dir_deep", "dir_reg", ".*\\.(sh|shy|py)$") m.Cmdy("dir", "", "dir_deep", "dir_reg", ".*\\.(sh|shy|py)$")

View File

@ -4,5 +4,5 @@ var version = struct {
host string host string
self int self int
}{ }{
"2019-07-13 14:35:25", "ZYB-20190522USI", 141, "2019-07-15 02:05:42", "com.mac", 169,
} }

View File

@ -8,41 +8,51 @@ import (
"toolkit" "toolkit"
) )
func (c *Context) Register(s *Context, x Server, args ...interface{}) { func (c *Context) Register(s *Context, x Server, args ...interface{}) *Context {
force := false name, force := s.Name, false
if len(args) > 0 { if len(args) > 0 {
switch arg := args[0].(type) { switch arg := args[0].(type) {
case bool: case bool:
force = arg force = arg
case string:
name, s.Name = arg, arg
} }
} }
if c.contexts == nil { if c.contexts == nil {
c.contexts = make(map[string]*Context) c.contexts = make(map[string]*Context)
} }
if x, ok := c.contexts[s.Name]; ok && !force { if x, ok := c.contexts[name]; ok && !force {
panic(errors.New(c.Name + "上下文中已存在模块:" + x.Name)) panic(errors.New(c.Name + "上下文中已存在模块:" + x.Name))
} }
c.contexts[s.Name] = s c.contexts[name] = s
s.context = c s.context = c
s.Server = x s.Server = x
return s
} }
func (c *Context) Plugin(args []string) string { func (c *Context) Plugin(s *Context, args []string) string {
Index.Register(c, nil) c.Register(s, nil)
m := &Message{code: 0, time: time.Now(), source: c, target: c, Meta: map[string][]string{}} m := &Message{code: 0, time: time.Now(), source: s, target: s, Meta: map[string][]string{}}
m.Option("log.disable", true) m.Option("log.disable", true)
if len(args) == 0 { if len(args) == 0 {
m.Echo("%s: %s\n\n", c.Name, c.Help) m.Echo("%s: %s\n\n", s.Name, s.Help)
m.Echo("命令列表:\n") m.Echo("命令列表:\n")
for k, v := range c.Commands { for k, v := range s.Commands {
m.Echo(" %s: %s\n %v\n\n", k, v.Name, v.Help) if !strings.HasPrefix(k, "_") {
m.Echo(" %s: %s\n %v\n\n", k, v.Name, v.Help)
}
} }
m.Echo("配置列表:\n") m.Echo("配置列表:\n")
for k, v := range c.Configs { for k, v := range s.Configs {
m.Echo(" %s(%v): %s\n", k, v.Value, v.Help) if !strings.HasPrefix(k, "_") {
m.Echo("--%s(%v): %s\n", k, kit.Formats(v.Value), v.Help)
}
} }
} else { } else {
if Index.Begin(Pulse, args...); Index.Start(Pulse, args...) {
}
m.Cmd(args) m.Cmd(args)
} }
return strings.Join(m.Meta["result"], "") return strings.Join(m.Meta["result"], "")
@ -369,7 +379,7 @@ func (m *Message) CallBack(sync bool, cb func(msg *Message) (sub *Message), arg
select { select {
case <-time.After(kit.Duration(m.Confx("call_timeout"))): case <-time.After(kit.Duration(m.Confx("call_timeout"))):
m.Log("sync", m.Format("timeout", "detail", "option")) m.Log("sync", m.Format("timeout", "detail", "option"))
m.Echo("time out %v", m.Confx("call_timeout")) m.Echo("time out %v", m.Confx("call_timeout"))
case <-wait: case <-wait:
} }
return m return m

View File

@ -39,7 +39,6 @@ func (ctx *CTX) Begin(m *Message, arg ...string) Server {
} }
func (ctx *CTX) Start(m *Message, arg ...string) bool { func (ctx *CTX) Start(m *Message, arg ...string) bool {
m.Cmd("ctx._init") m.Cmd("ctx._init")
kit.Log("fuck", "what")
if m.Optionv("ps_target", Index); len(arg) == 0 { if m.Optionv("ps_target", Index); len(arg) == 0 {
m.Option("cli.modal", "active") m.Option("cli.modal", "active")
m.Option("log.disable", false) m.Option("log.disable", false)
@ -47,12 +46,10 @@ func (ctx *CTX) Start(m *Message, arg ...string) bool {
m.Cmd("log._init") m.Cmd("log._init")
m.Cmd("yac._init") m.Cmd("yac._init")
m.Cmd("gdb._init") m.Cmd("gdb._init")
m.Log("fuck", "what")
m.Cmd("cli.source", m.Conf("system", "script.init")).Cmd("cli.source", "stdio").Cmd("cli.source", m.Conf("system", "script.exit")) m.Cmd("cli.source", m.Conf("system", "script.init")).Cmd("cli.source", "stdio").Cmd("cli.source", m.Conf("system", "script.exit"))
} else { } else {
m.Option("cli.modal", "action") m.Option("cli.modal", "action")
m.Cmd("yac._init") // m.Cmd("yac._init")
m.Log("fuck", "what")
for _, v := range m.Spawn().Cmd(arg).Meta["result"] { for _, v := range m.Spawn().Cmd(arg).Meta["result"] {
fmt.Printf("%s", v) fmt.Printf("%s", v)
} }
@ -667,9 +664,9 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
switch action { switch action {
case "cmd": case "cmd":
if arg[0] == "command" { if arg[0] == "command" {
arg = arg[1:] arg = arg[1:]
} }
if msg.Cmd(arg); !msg.Hand { if msg.Cmd(arg); !msg.Hand {
msg = msg.Cmd("cli.cmd", arg) msg = msg.Cmd("cli.cmd", arg)
} }

View File

@ -1210,12 +1210,58 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
}}, }},
"dir": &ctx.Command{Name: "dir [path [fields...]]", Help: []string{"查看目录, path: 路径, fields...: 查询字段, time|type|full|path|tree|filename|size|line|hash", "dir": &ctx.Command{Name: "dir [path [fields...]]", Help: []string{"查看目录, path: 路径, fields...: 查询字段, time|type|full|path|tree|filename|size|line|hash",
"dir_deep: 递归查询", "dir_type both|file|dir|all: 文件类型", "dir_reg reg: 正则表达式", "dir_sort field order: 排序"}, "dir_deep: 递归查询", "dir_type both|file|dir|all: 文件类型", "dir_reg reg: 正则表达式", "dir_sort field order: 排序"},
Form: map[string]int{"dir_deep": 0, "dir_type": 1, "dir_reg": 1, "dir_sort": 2}, Form: map[string]int{"dir_deep": 0, "dir_type": 1, "dir_reg": 1, "dir_sort": 2, "dir_sed": -1},
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
if len(arg) == 0 { if len(arg) == 0 {
arg = append(arg, "") arg = append(arg, "")
} }
p := arg[0]
p0 := p + ".tmp0"
p1 := p + ".tmp1"
if args := kit.Trans(m.Optionv("dir_sed")); len(args) > 0 {
if _, e := os.Stat(p1); e == nil {
return e
}
out, e := os.Create(p1)
defer os.Remove(p1)
defer out.Close()
m.Log("info", "open %v", p1)
if _, e := os.Stat(p0); e != nil {
m.Cmd("nfs.copy", p0, p)
}
in, e := os.Open(p0)
defer in.Close()
m.Log("info", "open %v", p0)
switch args[0] {
case "set":
defer os.Rename(p1, p0)
defer os.Remove(p0)
index := kit.Int(args[1])
for bio, i := bufio.NewScanner(in), 0; bio.Scan(); i++ {
if i == index {
out.WriteString(args[2])
} else {
out.WriteString(bio.Text())
}
out.WriteString("\n")
}
return e
case "add":
out0, _ := os.OpenFile(p0, os.O_WRONLY|os.O_APPEND, 0666)
defer out0.Close()
out0.WriteString("\n")
case "put":
defer os.Rename(p0, p)
}
return e
}
wd, e := os.Getwd() wd, e := os.Getwd()
m.Assert(e) m.Assert(e)
trip := len(wd) + 1 trip := len(wd) + 1
@ -1231,7 +1277,25 @@ 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 {
m.Append("directory", p) if s.Size() < 100 {
p0 := p + ".tmp0"
f, e := os.Open(p0)
if e != nil {
f, e = os.Open(p)
m.Log("info", "open %v", p)
} else {
p = p0
m.Log("info", "open %v", p0)
}
for bio := bufio.NewScanner(f); bio.Scan(); {
m.Echo(bio.Text())
}
m.Append("file", p)
m.Append("size", s.Size())
m.Append("time", s.ModTime().Format(m.Conf("time_format")))
} else {
m.Append("directory", p)
}
} }
return true return true
} }
@ -1247,7 +1311,9 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
m.Echo(v).Echo(" ") m.Echo(v).Echo(" ")
} }
} else { } else {
m.Table() if !m.Appends("file") {
m.Table()
}
} }
return return
}}, }},

View File

@ -112,7 +112,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
"componet_args": []interface{}{"$$", "context", "$$", "show"}, "inputs": []interface{}{ "componet_args": []interface{}{"$$", "context", "$$", "show"}, "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": "text", "name": "ctx", "value": "db1"}, map[string]interface{}{"type": "text", "name": "ctx", "value": "db1"},
map[string]interface{}{"type": "text", "name": "cmd", "value": "tblStudentLesson0", "imports": "plugin_db_table", "action": "auto"}, map[string]interface{}{"type": "text", "name": "cmd", "value": "tblStudentLesson0", "imports": "plugin_db_table", "action": "auto"},
map[string]interface{}{"type": "button", "value": "查看 "}, map[string]interface{}{"type": "button", "value": "查看 "},
}, },
"exports": []interface{}{"db_table", "Tables"}, "exports": []interface{}{"db_table", "Tables"},
@ -130,45 +130,44 @@ 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": "project", "componet_type": "private", "componet_ctx": "cli", "componet_cmd": "project",
"componet_args": []interface{}{}, "inputs": []interface{}{ "componet_args": []interface{}{}, "inputs": []interface{}{
map[string]interface{}{"type": "select", "name": "cmd", "values": []interface{}{"import"}}, map[string]interface{}{"type": "select", "name": "cmd", "values": []interface{}{"plugin", "stat", "init"}},
map[string]interface{}{"type": "text", "name": "who"},
map[string]interface{}{"type": "button", "value": "执行"}, map[string]interface{}{"type": "button", "value": "执行"},
}, },
}, },
map[string]interface{}{"componet_name": "compile", "componet_help": "编译", map[string]interface{}{"componet_name": "compile", "componet_help": "编译",
"componet_tmpl": "componet", "componet_view": "Compile", "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": "action", "values": []interface{}{"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": "button", "value": "编译"}, map[string]interface{}{"type": "button", "value": "编译"},
}, },
"display": map[string]interface{}{"hide_append": true, "show_result": true},
}, },
map[string]interface{}{"componet_name": "publish", "componet_help": "发布", map[string]interface{}{"componet_name": "publish", "componet_help": "发布",
"componet_tmpl": "componet", "componet_view": "Compile", "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": "action"}, map[string]interface{}{"type": "text", "name": "who"},
map[string]interface{}{"type": "button", "value": "发布"}, map[string]interface{}{"type": "button", "value": "发布"},
}, },
"display": map[string]interface{}{"hide_append": true, "show_result": true},
}, },
map[string]interface{}{"componet_name": "upgrade", "componet_help": "升级", map[string]interface{}{"componet_name": "upgrade", "componet_help": "升级",
"componet_tmpl": "componet", "componet_view": "Compile", "componet_init": "", "componet_tmpl": "componet", "componet_view": "componet", "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"}, "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", "plugin", "bench"}}, map[string]interface{}{"type": "select", "name": "action", "values": []interface{}{"script", "plugin", "portal", "system", "bench"}},
map[string]interface{}{"type": "text", "name": "action"}, map[string]interface{}{"type": "text", "name": "who"},
map[string]interface{}{"type": "button", "value": "升级"}, map[string]interface{}{"type": "button", "value": "升级"},
}, },
"display": map[string]interface{}{"hide_append": true, "show_result": true},
"options": map[string]interface{}{"call_timeout": "180s"}, "options": map[string]interface{}{"call_timeout": "180s"},
}, },
map[string]interface{}{"componet_name": "missyou", "componet_help": "任务", map[string]interface{}{"componet_name": "missyou", "componet_help": "任务",
"componet_tmpl": "componet", "componet_view": "Compile", "componet_init": "", "componet_tmpl": "componet", "componet_view": "Compile", "componet_init": "",
"componet_type": "private", "componet_ctx": "cli", "componet_cmd": "missyou", "componet_type": "private", "componet_ctx": "cli", "componet_cmd": "missyou",
"componet_args": []interface{}{}, "inputs": []interface{}{ "componet_args": []interface{}{}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "action", "view": "long"}, map[string]interface{}{"type": "text", "name": "action", "view": "long"},
map[string]interface{}{"type": "button", "value": "行动", "action": "auto"}, map[string]interface{}{"type": "button", "value": "行动", "action": "auto"},
}, },
"exports": []interface{}{"you", "", "you"}, "exports": []interface{}{"you", "", "you"},
@ -254,7 +253,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
"componet_tmpl": "componet", "componet_view": "Context", "componet_init": "", "componet_tmpl": "componet", "componet_view": "Context", "componet_init": "",
"componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route", "componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route",
"componet_args": []interface{}{"$$", "context", "ssh", "remote"}, "inputs": []interface{}{ "componet_args": []interface{}{"$$", "context", "ssh", "remote"}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "pod", "view": "long"}, map[string]interface{}{"type": "text", "name": "pod", "view": "long"},
map[string]interface{}{"type": "button", "value": "执行", "action": "auto"}, map[string]interface{}{"type": "button", "value": "执行", "action": "auto"},
}, },
"exports": []interface{}{"pod", "", "pod"}, "exports": []interface{}{"pod", "", "pod"},
@ -288,7 +287,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
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"},
}, },
"display": map[string]interface{}{"hide_result": true}, "display": map[string]interface{}{"deal": "editor"},
"exports": []interface{}{"dir", "", "dir"}, "exports": []interface{}{"dir", "", "dir"},
"dir_root": []interface{}{"/"}, "dir_root": []interface{}{"/"},
}, },

View File

@ -652,7 +652,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
res, e := web.Client.Do(req) res, e := web.Client.Do(req)
if e != nil { if e != nil {
m.Log("warn", "%v", e) m.Log("warn", "%v", e)
m.Echo("%v", e) m.Echo("%v", e)
return e return e
} }
@ -1126,17 +1126,17 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
} }
p := "" p := ""
if m.Option("upgrade") == "plugin" { if m.Option("upgrade") == "plugin" {
if !strings.HasSuffix(key, ".so") { if !strings.HasSuffix(key, ".so") {
key += ".so" key += ".so"
} }
p = m.Cmdx("nfs.path", path.Join("src/plugin", key)) p = m.Cmdx("nfs.path", path.Join("src/plugin", key))
} }
if m.Option("upgrade") == "script" { if m.Option("upgrade") == "script" {
if m.Options("missyou") { if m.Options("missyou") {
p = m.Cmdx("nfs.path", path.Join(m.Conf("missyou", "path"), m.Option("missyou"), "usr/script", key)) p = m.Cmdx("nfs.path", path.Join(m.Conf("missyou", "path"), m.Option("missyou"), "usr/script", key))
} else { } else {
p = m.Cmdx("nfs.path", path.Join("usr/script", key)) p = m.Cmdx("nfs.path", path.Join("usr/script", key))
} }
} }
key = strings.Replace(key, ".", "_", -1) key = strings.Replace(key, ".", "_", -1)
if p == "" { if p == "" {

View File

@ -54,11 +54,11 @@ var Index = &ctx.Context{Name: "wiki", Help: "文档中心",
}, },
}, Help: "组件列表"}, }, Help: "组件列表"},
"wiki_level": &ctx.Config{Name: "wiki_level", Value: "wiki/自然/编程", Help: "路由数量"}, "wiki_level": &ctx.Config{Name: "wiki_level", Value: "local/wiki/自然/编程", Help: "路由数量"},
"wiki_favor": &ctx.Config{Name: "wiki_favor", Value: "index.md", Help: "路由数量"}, "wiki_favor": &ctx.Config{Name: "wiki_favor", Value: "index.md", Help: "路由数量"},
"wiki_visit": &ctx.Config{Name: "wiki_visit", Value: map[string]interface{}{}, Help: "路由数量"}, "wiki_visit": &ctx.Config{Name: "wiki_visit", Value: map[string]interface{}{}, Help: "路由数量"},
"wiki_dir": &ctx.Config{Name: "wiki_dir", Value: "wiki", Help: "路由数量"}, "wiki_dir": &ctx.Config{Name: "wiki_dir", Value: "usr/local/wiki", Help: "路由数量"},
"wiki_list": &ctx.Config{Name: "wiki_list", Value: []interface{}{}, Help: "路由数量"}, "wiki_list": &ctx.Config{Name: "wiki_list", Value: []interface{}{}, Help: "路由数量"},
"wiki_list_show": &ctx.Config{Name: "wiki_list_show", Value: map[string]interface{}{ "wiki_list_show": &ctx.Config{Name: "wiki_list_show", Value: map[string]interface{}{
"md": true, "md": true,

View File

@ -1,13 +1,16 @@
package main package main
import ( import (
"contexts/cli"
"contexts/ctx" "contexts/ctx"
_ "contexts/nfs"
"toolkit"
"fmt" "fmt"
"math" "math"
"math/rand" "math/rand"
"os" "os"
"strings" "strings"
"toolkit"
) )
func Merge(left []int, right []int) []int { func Merge(left []int, right []int) []int {
@ -55,10 +58,21 @@ func QuickSort(m *ctx.Message, level int, data []int, left int, right int) {
} }
var Index = &ctx.Context{Name: "sort", Help: "sort code", var Index = &ctx.Context{Name: "sort", Help: "sort code",
Caches: map[string]*ctx.Cache{},
Configs: map[string]*ctx.Config{ Configs: map[string]*ctx.Config{
"data": &ctx.Config{Name: "data", Value: map[string]interface{}{ "data": &ctx.Config{Name: "data", Value: map[string]interface{}{
"seed": []int{47, 59, 81, 40, 56, 0, 94, 11, 18, 25}, "seed": []int{47, 59, 81, 40, 56, 0, 94, 11, 18, 25},
}}, }},
"index": &ctx.Config{Name: "index", Value: []interface{}{
map[string]interface{}{"componet_name": "select", "componet_help": "选择排序",
"componet_tmpl": "componet", "componet_view": "componet", "componet_init": "",
"componet_type": "public", "componet_ctx": "sort", "componet_cmd": "select",
"componet_args": []interface{}{}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"},
map[string]interface{}{"type": "button", "value": "执行"},
},
},
}},
}, },
Commands: map[string]*ctx.Command{ Commands: map[string]*ctx.Command{
"_init": &ctx.Command{Name: "_init", Help: "_init", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { "_init": &ctx.Command{Name: "_init", Help: "_init", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
@ -180,5 +194,5 @@ var Index = &ctx.Context{Name: "sort", Help: "sort code",
} }
func main() { func main() {
fmt.Print(Index.Plugin(os.Args[1:])) fmt.Print(cli.Index.Plugin(Index, os.Args[1:]))
} }

View File

@ -1,25 +1,27 @@
package main package main
import ( import (
"runtime" "contexts/cli"
"contexts/ctx"
"toolkit"
"bufio" "bufio"
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"contexts/ctx"
kit "toolkit"
"io" "io"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"os" "os"
"path" "path"
"runtime"
"strings" "strings"
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
) )
func Input(m *ctx.Message, file string, input chan[]string) { func Input(m *ctx.Message, file string, input chan []string) {
f, e := os.Open(file) f, e := os.Open(file)
m.Assert(e) m.Assert(e)
defer f.Close() defer f.Close()
@ -38,7 +40,7 @@ func Input(m *ctx.Message, file string, input chan[]string) {
} }
input <- []string{fmt.Sprintf("%d", nline), uri, arg} input <- []string{fmt.Sprintf("%d", nline), uri, arg}
if nline++; nline % kit.Int(m.Confx("nsleep")) == 0 { if nline++; nline%kit.Int(m.Confx("nsleep")) == 0 {
fmt.Printf("nline:%d sleep 1s...\n", nline) fmt.Printf("nline:%d sleep 1s...\n", nline)
time.Sleep(time.Second) time.Sleep(time.Second)
} }
@ -46,7 +48,7 @@ func Input(m *ctx.Message, file string, input chan[]string) {
close(input) close(input)
} }
func Output(m *ctx.Message, output <-chan[]string) { func Output(m *ctx.Message, output <-chan []string) {
os.MkdirAll(m.Conf("outdir"), 0777) os.MkdirAll(m.Conf("outdir"), 0777)
files := map[string]*os.File{} files := map[string]*os.File{}
@ -62,7 +64,7 @@ func Output(m *ctx.Message, output <-chan[]string) {
defer f.Close() defer f.Close()
files[uri] = f files[uri] = f
} }
for _, v:= range data { for _, v := range data {
fmt.Fprintf(files[uri], v) fmt.Fprintf(files[uri], v)
} }
} }
@ -88,11 +90,11 @@ func Process(m *ctx.Message, file string, cb func(*ctx.Message, *http.Client, []
break break
} }
atomic.AddInt32(&nline, 1) atomic.AddInt32(&nline, 1)
cb(msg, &http.Client{Timeout:kit.Duration(m.Conf("timeout"))}, word, output) cb(msg, &http.Client{Timeout: kit.Duration(m.Conf("timeout"))}, word, output)
} }
}(m.Spawn()) }(m.Spawn())
} }
runtime.Gosched() runtime.Gosched()
wg.Wait() wg.Wait()
close(output) close(output)
return nline, time.Since(begin) return nline, time.Since(begin)
@ -120,20 +122,32 @@ func Compare(b1 []byte, b2 []byte) bool {
var Index = &ctx.Context{Name: "test", Help: "测试工具", var Index = &ctx.Context{Name: "test", Help: "测试工具",
Caches: map[string]*ctx.Cache{}, Caches: map[string]*ctx.Cache{},
Configs: map[string]*ctx.Config{ Configs: map[string]*ctx.Config{
"nread": {Name: "nread", Help: "读取Channel长度", Value: 1}, "nread": {Name: "nread", Help: "读取Channel长度", Value: 1},
"nwork": {Name: "nwork", Help: "协程数量", Value: 20}, "nwork": {Name: "nwork", Help: "协程数量", Value: 20},
"limit":{Name: "limit", Help: "请求数量", Value: 100}, "limit": {Name: "limit", Help: "请求数量", Value: 100},
"nskip": {Name: "nskip", Help: "请求限长", Value: 100}, "nskip": {Name: "nskip", Help: "请求限长", Value: 100},
"nsleep": {Name: "nsleep", Help: "阻塞时长", Value: "10000"}, "nsleep": {Name: "nsleep", Help: "阻塞时长", Value: "10000"},
"nwrite":{Name: "nwrite", Help: "输出Channel长度", Value: 1}, "nwrite": {Name: "nwrite", Help: "输出Channel长度", Value: 1},
"outdir": {Name: "outdir", Help: "输出目录", Value: "tmp"}, "outdir": {Name: "outdir", Help: "输出目录", Value: "tmp"},
"timeout": {Name: "timeout", Help: "请求超时", Value: "10s"}, "timeout": {Name: "timeout", Help: "请求超时", Value: "10s"},
"prefix0": {Name: "prefix0", Help: "请求前缀", Value: "uri["}, "prefix0": {Name: "prefix0", Help: "请求前缀", Value: "uri["},
"prefix1": {Name: "prefix1", Help: "参数前缀", Value: "request_param["}, "prefix1": {Name: "prefix1", Help: "参数前缀", Value: "request_param["},
"index": &ctx.Config{Name: "index", Value: []interface{}{
map[string]interface{}{"componet_name": "status", "componet_help": "状态",
"componet_tmpl": "componet", "componet_view": "Company", "componet_init": "",
"componet_type": "private", "componet_ctx": "test", "componet_cmd": "diff",
"componet_args": []interface{}{}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"},
map[string]interface{}{"type": "select", "name": "sub", "values": []interface{}{"status", ""}},
map[string]interface{}{"type": "button", "value": "执行"},
},
},
}},
}, },
Commands: map[string]*ctx.Command{ Commands: map[string]*ctx.Command{
"diff": {Name: "diff file server1 server2", Form: map[string]int{"nsleep": 1}, Help:"接口对比工具", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { "diff": {Name: "diff file server1 server2", Form: map[string]int{"nsleep": 1}, Help: "接口对比工具", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
if len(arg) < 3 { if len(arg) < 3 {
m.Echo("usage: %v", "diff file server1 server2") m.Echo("usage: %v", "diff file server1 server2")
return return
@ -203,7 +217,7 @@ var Index = &ctx.Context{Name: "test", Help: "测试工具",
result1 = append(result1, string(b2)) result1 = append(result1, string(b2))
result1 = append(result1, "\n") result1 = append(result1, "\n")
result1 = append(result1, "\n") result1 = append(result1, "\n")
output <- result1 output <- result1
} }
size1 = len(b1) size1 = len(b1)
size2 = len(b2) size2 = len(b2)
@ -228,43 +242,43 @@ var Index = &ctx.Context{Name: "test", Help: "测试工具",
m.Sort("time1", "int").Table() m.Sort("time1", "int").Table()
return return
}}, }},
"cost": {Name: "cost file server nroute", Help:"接口耗时测试", Form: map[string]int{"nwork": 1, "limit": 1, "nsleep": 1}, Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { "cost": {Name: "cost file server nroute", Help: "接口耗时测试", Form: map[string]int{"nwork": 1, "limit": 1, "nsleep": 1}, Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
var success int32 = 0 var success int32 = 0
var times time.Duration var times time.Duration
mu := sync.Mutex{} mu := sync.Mutex{}
limit := kit.Int(m.Confx("limit")) limit := kit.Int(m.Confx("limit"))
nline := 0 nline := 0
_, cost := Process(m, arg[0], func(msg *ctx.Message, client *http.Client, word []string, output chan []string) { _, cost := Process(m, arg[0], func(msg *ctx.Message, client *http.Client, word []string, output chan []string) {
key, uri, args := word[0], word[1], word[2] key, uri, args := word[0], word[1], word[2]
for _, host := range arg[1:]{ for _, host := range arg[1:] {
fmt.Printf("%v/%v post: %v\t%v\n", key, limit, host+uri, args) fmt.Printf("%v/%v post: %v\t%v\n", key, limit, host+uri, args)
begin := time.Now() begin := time.Now()
res, err := client.Post(host+uri, "application/json", bytes.NewReader([]byte(args))) res, err := client.Post(host+uri, "application/json", bytes.NewReader([]byte(args)))
if res.StatusCode == http.StatusOK { if res.StatusCode == http.StatusOK {
io.Copy(ioutil.Discard, res.Body) io.Copy(ioutil.Discard, res.Body)
atomic.AddInt32(&success, 1) atomic.AddInt32(&success, 1)
} else { } else {
fmt.Printf("%v/%v error: %v\n", key, limit, err) fmt.Printf("%v/%v error: %v\n", key, limit, err)
} }
t := time.Since(begin) t := time.Since(begin)
times += t times += t
mu.Lock() mu.Lock()
nline++ nline++
m.Add("append", "host", host) m.Add("append", "host", host)
m.Add("append", "uri", uri) m.Add("append", "uri", uri)
m.Add("append", "cost", t/1000000) m.Add("append", "cost", t/1000000)
mu.Unlock() mu.Unlock()
} }
}) })
m.Sort("cost", "int_r") m.Sort("cost", "int_r")
m.Echo("\n\nnclient: %v nreq: %v success: %v time: %v average: %vms", m.Echo("\n\nnclient: %v nreq: %v success: %v time: %v average: %vms",
m.Confx("nwork"), nline, success, cost, int(times)/int(nline)/1000000) m.Confx("nwork"), nline, success, cost, int(times)/int(nline)/1000000)
return return
}}, }},
"cmd": {Name: "cmd file", Help:"生成测试命令", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { "cmd": {Name: "cmd file", Help: "生成测试命令", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
str := kit.Select("./hey -n 10000 -c 100 -m POST -T \"application/json\" -d '%s' http://127.0.0.1:6363%s\n", arg, 1) str := kit.Select("./hey -n 10000 -c 100 -m POST -T \"application/json\" -d '%s' http://127.0.0.1:6363%s\n", arg, 1)
Process(m, arg[0], func(msg *ctx.Message, client *http.Client, word []string, output chan []string) { Process(m, arg[0], func(msg *ctx.Message, client *http.Client, word []string, output chan []string) {
m.Echo(str, word[2], word[1]) m.Echo(str, word[2], word[1])
@ -273,7 +287,7 @@ var Index = &ctx.Context{Name: "test", Help: "测试工具",
}}, }},
}, },
} }
func main() { func main() {
kit.DisableLog = true fmt.Print(cli.Index.Plugin(Index, os.Args[1:]))
fmt.Print(Index.Plugin(os.Args[1:]))
} }

View File

@ -83,6 +83,18 @@ fieldset>div.output table td {
word-break:keep-all; word-break:keep-all;
min-width:40px; min-width:40px;
} }
fieldset>div.output>table.edit {
}
fieldset>div.output>table.edit td {
min-width:4px;
padding:0px;
}
fieldset>div.output>table.edit td>input {
width:600px;
padding:0px;
}
fieldset>div.output table.edit {
}
fieldset.toast { fieldset.toast {
border:solid 2px red; border:solid 2px red;

View File

@ -754,6 +754,41 @@ 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) {
@ -819,14 +854,8 @@ function Plugin(page, pane, field) {
return value return value
} }
var deal = display.deal
var back = option.dir.value
display.deal = "void"
option.dir.value = value option.dir.value = value
plugin.Runs(window.event, function() { plugin.Runs(window.event)
display.deal = deal
option.dir.value = back
})
}, },
}, },
display: function(arg) { display: function(arg) {

33
usr/local/wiki/index.md Normal file
View File

@ -0,0 +1,33 @@
天行健,君子以自强不息
|--------|----|----|----|--------|----|----|----|--------|----|----|----|
|--------|----|----|----|--------|----|----|----|--------|----|----|----|
|**人文**|感性|理性|灵性|**社会**|行业|企业|产业|**自然**|微观|宏观|宇观|
|**哲学**|世界|价值|人生|**史学**|经济|政治|文化|**科学**|实验|理论|方程|
|--------|----|----|----|--------|----|----|----|--------|----|----|----|
|**意识**|生活|工作|学习|**意志**|学位|职位|地位|**意义**|问题|难题|课题|
|**欲望**|幸福|财富|智慧|**缘份**|同学|同事|同行|**成就**|创造|创新|创始|
|--------|----|----|----|--------|----|----|----|--------|----|----|----|
|**做人**|随缘|随性|随心|**做事**|交易|交流|交情|**做学**|多做|多看|多想|
|**教育**|习惯|信用|道德|**资本**|资源|资格|资历|**工程**|技术|学术|艺术|
|--------|----|----|----|--------|----|----|----|--------|----|----|----|
|--------|----|----|----|--------|----|----|----|--------|----|----|----|
|--------|----|----|----|--------|----|----|----|--------|----|----|----|
|**精神**|需求|追求|要求|**历史**|英雄|家族|阶级|**宇宙**|天文|气象|地质|
|**语言**|词汇|语法|语义|**经济**|生产|市场|消费|**物理**|物质|能量|信息|
|**文学**|散文|诗歌|小说|**政治**|外交|法制|民生|**数学**|代数|函数|几何|
|**艺术**|音乐|美术|体育|**军事**|战略|战术|战争|**生命**|基因|组织|系统|
|--------|----|----|----|--------|----|----|----|--------|----|----|----|
|**信仰**|科学|民主|自由|**人际**|心理|伦理|道理|**传感**|属性|关系|规律|
|**表达**|意识|情感|意志|**管理**|物力|人力|才力|**编程**|语言|框架|平台|
|**修养**|益智|怡情|养性|**物流**|交通|管道|电信|**控制**|过程|状态|特征|
|**阅读**|摘要|情节|典故|**金融**|基金|股票|保险|**设计**|功能|性能|智能|
|--------|----|----|----|--------|----|----|----|--------|----|----|----|
|**黑客**|博学|博识|博爱|**总裁**|路线|方针|政策|**建筑**|地基|栋梁|装饰|
|**读者**|搜集|检索|查阅|**经理**|客户|产品|服务|**机械**|原动|传动|制动|
|**朋友**|相识|相知|相交|**总监**|行情|行规|行家|**电子**|输入|处理|输出|
|**演讲**|论点|论据|论证|**董事**|提案|表决|监督|**电脑**|硬件|软件|文件|
|--------|----|----|----|--------|----|----|----|--------|----|----|----|
地势坤,君子以厚德载物

View File

@ -0,0 +1,79 @@
# Common builder
ARG GO_IMAGE
FROM ${GO_IMAGE} as builder
COPY hack/dockerfile/install/tini.installer /
COPY hack/dockerfile/install/proxy.installer /
RUN apt-get update && apt-get install -y \
bash \
btrfs-tools \
ca-certificates \
cmake \
gcc \
git \
libc-dev \
libgcc-6-dev \
libltdl-dev \
libtool \
make
RUN grep "_COMMIT=" /*.installer |cut -f2- -d: > /binaries-commits
# dockerd
FROM builder as dockerd-builder
WORKDIR /go/src/github.com/docker/docker
COPY . /go/src/github.com/docker/docker
ARG VERSION
ARG GITCOMMIT
ARG BUILDTIME
ARG PLATFORM
ARG PRODUCT
ARG DEFAULT_PRODUCT_LICENSE
ENV VERSION ${VERSION}
ENV GITCOMMIT ${GITCOMMIT}
ENV BUILDTIME ${BUILDTIME}
ENV PLATFORM ${PLATFORM}
ENV PRODUCT ${PRODUCT}
ENV DEFAULT_PRODUCT_LICENSE ${DEFAULT_PRODUCT_LICENSE}
# TODO The way we set the version could easily be simplified not to depend on hack/...
RUN bash ./hack/make/.go-autogen
RUN go build -o /sbin/dockerd \
-tags 'autogen netgo static_build selinux journald' \
-installsuffix netgo -a -buildmode=pie -ldflags '-w -extldflags "-static" ' \
github.com/docker/docker/cmd/dockerd
# docker-proxy
# TODO if libnetwork folds into the docker tree this can be combined above
FROM builder as proxy-builder
RUN git clone https://github.com/docker/libnetwork.git /go/src/github.com/docker/libnetwork
WORKDIR /go/src/github.com/docker/libnetwork
RUN . /binaries-commits && \
git checkout -q "$LIBNETWORK_COMMIT" && \
CGO_ENABLED=0 go build -buildmode=pie -ldflags="$PROXY_LDFLAGS" \
-o /sbin/docker-proxy \
github.com/docker/libnetwork/cmd/proxy
# docker-init - TODO move this out, last time we bumped was 2016!
FROM builder as init-builder
RUN git clone https://github.com/krallin/tini.git /tini
WORKDIR /tini
RUN . /binaries-commits && \
git checkout -q "$TINI_COMMIT" && \
cmake . && make tini-static && \
cp tini-static /sbin/docker-init
# runc
FROM builder as runc-builder
RUN apt-get install -y libseccomp-dev
RUN git clone https://github.com/opencontainers/runc.git /go/src/github.com/opencontainers/runc
WORKDIR /go/src/github.com/opencontainers/runc
RUN . /binaries-commits && \
git checkout -q "$RUNC_COMMIT" && \
make BUILDTAGS='seccomp apparmor' static && make install
# Final docker image
FROM scratch
COPY --from=dockerd-builder /sbin/dockerd /sbin/
COPY --from=proxy-builder /sbin/docker-proxy /sbin/
COPY --from=init-builder /sbin/docker-init /sbin/
COPY --from=runc-builder /usr/local/sbin/runc /sbin/
ENTRYPOINT ["/sbin/dockerd"]

@ -0,0 +1 @@
Subproject commit 007921611b04d8fca5ad0b1d4e7b0461b47cd435

3
why.go
View File

@ -1,3 +0,0 @@
package main
func main() {}