forked from x/icebergs
opt nfs
This commit is contained in:
parent
3ac6548226
commit
40064c2c9c
@ -40,7 +40,6 @@ func (f *Frame) Spawn(m *ice.Message, c *ice.Context, arg ...string) ice.Server
|
||||
return &Frame{}
|
||||
}
|
||||
|
||||
const DEBUG = "debug"
|
||||
const GDB = "gdb"
|
||||
|
||||
var Index = &ice.Context{Name: GDB, Help: "事件模块", Commands: ice.Commands{
|
||||
|
@ -36,6 +36,7 @@ const (
|
||||
PID = "pid"
|
||||
)
|
||||
const (
|
||||
DEBUG = "debug"
|
||||
ERROR = "error"
|
||||
START = "start"
|
||||
RESTART = "restart"
|
||||
|
@ -90,8 +90,9 @@ const (
|
||||
VIEW = "view"
|
||||
SHOW = "show"
|
||||
)
|
||||
const LOG = "log"
|
||||
|
||||
var Index = &ice.Context{Name: "log", Help: "日志模块", Configs: ice.Configs{
|
||||
var Index = &ice.Context{Name: LOG, Help: "日志模块", Configs: ice.Configs{
|
||||
FILE: {Name: FILE, Help: "日志文件", Value: kit.Dict(
|
||||
BENCH, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, "bench.log"), mdb.LIST, []string{}),
|
||||
WATCH, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, "watch.log"), mdb.LIST, []string{
|
||||
|
@ -195,7 +195,7 @@ func HashPrunes(m *ice.Message, cb func(Map) bool) *ice.Message {
|
||||
}
|
||||
return cb == nil || cb(value)
|
||||
})
|
||||
return m.Cmdy(PRUNES, m.PrefixKey(), "", HASH).StatusTimeCount()
|
||||
return m.Cmdy(PRUNES, m.PrefixKey(), "", HASH, ice.OptionFields(HashField(m))).StatusTimeCount()
|
||||
}
|
||||
func HashExport(m *ice.Message, arg ...Any) *ice.Message {
|
||||
return m.Cmdy(EXPORT, m.PrefixKey(), "", HASH, arg)
|
||||
|
@ -137,7 +137,6 @@ const (
|
||||
JSON = "json"
|
||||
CSV = "csv"
|
||||
)
|
||||
const ()
|
||||
|
||||
const MDB = "mdb"
|
||||
|
||||
@ -259,14 +258,18 @@ func AutoConfig(args ...ice.Any) *ice.Action {
|
||||
}
|
||||
if cs := m.Target().Commands; cs[m.CommandKey()] == nil {
|
||||
return
|
||||
} else if inputs := []ice.Any{}; cs[m.CommandKey()].Actions[INSERT] != nil {
|
||||
kit.Fetch(kit.Filters(kit.Simple(m.Config(SHORT), kit.Split(ListField(m))), "", TIME, ID), func(k string) { inputs = append(inputs, k) })
|
||||
if cs[m.CommandKey()].Meta[INSERT] == nil {
|
||||
} else if cs[m.CommandKey()].Actions[INSERT] != nil {
|
||||
if inputs := []ice.Any{}; cs[m.CommandKey()].Meta[INSERT] == nil {
|
||||
kit.Fetch(kit.Filters(kit.Simple(m.Config(SHORT), kit.Split(ListField(m))), "", TIME, ID), func(k string) { inputs = append(inputs, k) })
|
||||
m.Design(INSERT, "添加", inputs...)
|
||||
}
|
||||
if inputs := []ice.Any{}; cs[m.CommandKey()].Meta[CREATE] == nil {
|
||||
kit.Fetch(kit.Filters(kit.Split(kit.Select(m.Config(SHORT), m.Config(FIELDS))), TIME, HASH, COUNT), func(k string) { inputs = append(inputs, k) })
|
||||
m.Design(CREATE, "创建", inputs...)
|
||||
}
|
||||
} else if cs[m.CommandKey()].Actions[CREATE] != nil {
|
||||
kit.Fetch(kit.Filters(kit.Split(HashField(m)), TIME, HASH), func(k string) { inputs = append(inputs, k) })
|
||||
if cs[m.CommandKey()].Meta[CREATE] == nil {
|
||||
if inputs := []ice.Any{}; cs[m.CommandKey()].Meta[CREATE] == nil {
|
||||
kit.Fetch(kit.Filters(kit.Split(HashField(m)), TIME, HASH), func(k string) { inputs = append(inputs, k) })
|
||||
m.Design(CREATE, "创建", inputs...)
|
||||
}
|
||||
}
|
||||
|
@ -94,6 +94,7 @@ const (
|
||||
BINARY = "binary"
|
||||
TARGET = "target"
|
||||
TAGS = "tags"
|
||||
TAR = "tar"
|
||||
|
||||
TEMPLATE = "template"
|
||||
MASTER = "master"
|
||||
@ -124,7 +125,6 @@ const (
|
||||
MP4 = "mp4"
|
||||
PDF = "pdf"
|
||||
|
||||
TAR = "tar"
|
||||
PWD = "./"
|
||||
PS = ice.PS
|
||||
PT = ice.PT
|
||||
@ -134,14 +134,14 @@ const CAT = "cat"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Configs: ice.Configs{
|
||||
CAT: {Value: kit.Data(SOURCE, kit.Dict(
|
||||
HTML, ice.TRUE, CSS, ice.TRUE, JS, ice.TRUE, GO, ice.TRUE, SH, ice.TRUE, SHY, ice.TRUE, CSV, ice.TRUE, JSON, ice.TRUE,
|
||||
PY, ice.TRUE, MD, ice.TRUE, TXT, ice.TRUE, IML, ice.TRUE, XML, ice.TRUE, YML, ice.TRUE, ZML, ice.TRUE,
|
||||
"license", ice.TRUE, "makefile", ice.TRUE, "configure", ice.TRUE, "conf", ice.TRUE,
|
||||
CAT: {Value: kit.Data(SOURCE, kit.DictList(
|
||||
HTML, CSS, JS, GO, SH, SHY, CSV, JSON,
|
||||
PY, MD, TXT, XML, YML, ZML, IML,
|
||||
"license", "makefile", "configure", "conf",
|
||||
))},
|
||||
}, Commands: ice.Commands{
|
||||
CAT: {Name: "cat path auto", Help: "文件", Actions: ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { aaa.White(m, ice.SRC_MAIN_SHY, ice.SRC_MAIN_GO, ice.USR_PUBLISH) }},
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { aaa.White(m, ice.SRC_MAIN_JS, ice.SRC_MAIN_GO, ice.SRC_MAIN_SHY) }},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 || strings.HasSuffix(arg[0], ice.PS) {
|
||||
m.Cmdy(DIR, arg)
|
||||
|
@ -114,7 +114,7 @@ func _dir_list(m *ice.Message, root string, dir string, level int, deep bool, di
|
||||
m.Push(field, "")
|
||||
}
|
||||
case mdb.ACTION:
|
||||
if m.IsCliUA() || m.Option(ice.MSG_USERROLE) == "void" {
|
||||
if m.IsCliUA() || m.Option(ice.MSG_USERROLE) == aaa.VOID {
|
||||
break
|
||||
}
|
||||
m.PushButton(TRASH)
|
||||
@ -164,13 +164,13 @@ const DIR = "dir"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
DIR: {Name: "dir path field auto dir_deep upload", Help: "目录", Actions: ice.Actions{
|
||||
DIR: {Name: "dir path field auto upload", Help: "目录", Actions: ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
aaa.White(m, ice.SRC, ice.BIN, ice.USR, ice.USR_LOCAL_GO)
|
||||
aaa.Black(m, ice.USR_LOCAL)
|
||||
aaa.White(m, ice.SRC, ice.BIN, ice.USR, ice.USR_PUBLISH, ice.USR_LOCAL_GO)
|
||||
aaa.Black(m, ice.BIN_BOOT_LOG, ice.USR_LOCAL)
|
||||
}},
|
||||
mdb.UPLOAD: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy("web.cache", "upload_watch", m.Option(PATH)) }},
|
||||
TRASH: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(TRASH, mdb.CREATE, m.Option(PATH)) }},
|
||||
TRASH: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(TRASH, mdb.CREATE, m.Option(PATH)) }},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
root, dir := kit.Select(PWD, m.Option(DIR_ROOT)), kit.Select(PWD, arg, 0)
|
||||
if strings.HasPrefix(dir, ice.PS) {
|
||||
@ -188,10 +188,8 @@ func init() {
|
||||
}
|
||||
|
||||
func Dir(m *ice.Message, sort string) *ice.Message {
|
||||
m.Option(DIR_TYPE, TYPE_DIR)
|
||||
m.Copy(m.Cmd(DIR, PWD).Sort(sort))
|
||||
m.Option(DIR_TYPE, TYPE_CAT)
|
||||
m.Copy(m.Cmd(DIR, PWD).Sort(sort))
|
||||
m.Copy(m.Cmd(DIR, PWD, kit.Dict(DIR_TYPE, TYPE_DIR)).Sort(sort))
|
||||
m.Copy(m.Cmd(DIR, PWD, kit.Dict(DIR_TYPE, TYPE_CAT)).Sort(sort))
|
||||
return m
|
||||
}
|
||||
func DirDeepAll(m *ice.Message, root, dir string, cb func(ice.Maps), arg ...string) *ice.Message {
|
||||
|
23
base/nfs/grep.go
Normal file
23
base/nfs/grep.go
Normal file
@ -0,0 +1,23 @@
|
||||
package nfs
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
)
|
||||
|
||||
const GREP = "grep"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
GREP: {Name: "grep word path auto", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option("cmd_dir", arg[1])
|
||||
for _, line := range strings.Split(m.Cmdx("cli.system", GREP, "--exclude=.[a-z]*", "--exclude-dir=.[a-z]*", "-rni", arg[0], ice.PT), ice.NL) {
|
||||
if ls := strings.SplitN(line, ice.DF, 3); len(ls) > 2 {
|
||||
m.Push(FILE, ls[0]).Push(LINE, ls[1]).Push(mdb.TEXT, ls[2])
|
||||
}
|
||||
}
|
||||
}},
|
||||
})
|
||||
}
|
@ -2,6 +2,8 @@ package nfs
|
||||
|
||||
import ice "shylinux.com/x/icebergs"
|
||||
|
||||
const NFS = "nfs"
|
||||
|
||||
var Index = &ice.Context{Name: "nfs", Help: "存储模块"}
|
||||
|
||||
func init() { ice.Index.Register(Index, nil, CAT, DIR, PACK, DEFS, SAVE, PUSH, COPY, LINK, TAIL, TRASH) }
|
||||
func init() { ice.Index.Register(Index, nil, CAT, DIR, PACK, DEFS, SAVE, PUSH, COPY, LINK, GREP, TAIL, TRASH) }
|
||||
|
@ -20,6 +20,9 @@ func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
PACK: {Name: "pack path auto upload create", Help: "文件系统", Actions: ice.Actions{
|
||||
mdb.UPLOAD: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(kit.Simple(m.Optionv(ice.MSG_UPLOAD))) == 1 {
|
||||
m.Cmdy("web.cache", "upload")
|
||||
}
|
||||
if c, e := DiskFile.OpenFile(m.Option(FILE)); m.Assert(e) {
|
||||
defer c.Close()
|
||||
if f, p, e := pack.CreateFile(path.Join(m.Option(PATH), m.Option(mdb.NAME))); m.Assert(e) {
|
||||
@ -113,6 +116,7 @@ func Remove(m *ice.Message, p string) error {
|
||||
return OptionFiles(m).Remove(p)
|
||||
}
|
||||
func Rename(m *ice.Message, oldname string, newname string) error {
|
||||
MkdirAll(m, path.Dir(newname))
|
||||
return OptionFiles(m).Rename(oldname, newname)
|
||||
}
|
||||
func Symlink(m *ice.Message, oldname string, newname string) error {
|
||||
|
@ -67,8 +67,7 @@ func _link_file(m *ice.Message, name string, from string) {
|
||||
return
|
||||
}
|
||||
Remove(m, name)
|
||||
MkdirAll(m, path.Dir(name))
|
||||
if m.Warn(Link(m, from, name)) && m.Warn(Symlink(m, from, name), ice.ErrWarn, from) {
|
||||
if MkdirAll(m, path.Dir(name)); m.Warn(Link(m, from, name)) && m.Warn(Symlink(m, from, name), ice.ErrWarn, from) {
|
||||
return
|
||||
}
|
||||
m.Logs(mdb.CREATE, FILE, name, FROM, from)
|
||||
@ -77,11 +76,9 @@ func _link_file(m *ice.Message, name string, from string) {
|
||||
|
||||
const (
|
||||
CONTENT = "content"
|
||||
FROM = "from"
|
||||
)
|
||||
const DEFS = "defs"
|
||||
const SAVE = "save"
|
||||
const LOAD = "load"
|
||||
const PUSH = "push"
|
||||
const COPY = "copy"
|
||||
const LINK = "link"
|
||||
|
@ -10,38 +10,33 @@ import (
|
||||
)
|
||||
|
||||
func _tail_create(m *ice.Message, arg ...string) {
|
||||
m.Debug("what %v", arg)
|
||||
h := mdb.HashCreate(m, arg)
|
||||
kit.Fetch(kit.Split(m.Option(FILE)), func(file string) {
|
||||
m.Options("cmd_output", Pipe(m, func(text string) { mdb.ZoneInsert(m, h, FILE, file, SIZE, len(text), mdb.TEXT, text) }), mdb.CACHE_CLEAR_ON_EXIT, ice.TRUE)
|
||||
m.Cmd("cli.daemon", TAIL, "-n", "0", "-f", file)
|
||||
})
|
||||
}
|
||||
|
||||
const TAIL = "tail"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
TAIL: {Name: "tail name id auto page filter:text create", Help: "日志流", Actions: ice.MergeActions(ice.Actions{
|
||||
TAIL: {Name: "tail name id auto page create", Help: "日志流", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashSelect(m.Spawn(ice.OptionFields("name,file"))).Tables(func(value ice.Maps) {
|
||||
m.Debug("what %v", value)
|
||||
m.Cmd("", mdb.CREATE, kit.SimpleKV("name,file", value))
|
||||
})
|
||||
}},
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch arg[0] {
|
||||
case FILE:
|
||||
m.Cmdy(DIR, kit.Select(PWD, arg, 1), PATH).RenameAppend(PATH, FILE).ProcessAgain()
|
||||
case mdb.NAME:
|
||||
m.Push(arg[0], kit.Split(m.Option(FILE), ice.PS))
|
||||
case mdb.LIMIT:
|
||||
m.Push(arg[0], kit.List("10", "20", "30", "50"))
|
||||
case FILE:
|
||||
m.Cmdy(DIR, kit.Select(PWD, arg, 1), PATH).RenameAppend(PATH, FILE).ProcessAgain()
|
||||
}
|
||||
}},
|
||||
mdb.CREATE: {Name: "create name file", Hand: func(m *ice.Message, arg ...string) { _tail_create(m, arg...) }},
|
||||
}, mdb.PageZoneAction(mdb.SHORT, mdb.NAME, mdb.FIELDS, "time,name,count,file", mdb.FIELD, "time,id,file,text")), Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.PageZoneSelect(m, arg...)
|
||||
}},
|
||||
mdb.CREATE: {Hand: func(m *ice.Message, arg ...string) { _tail_create(m, arg...) }},
|
||||
}, mdb.PageZoneAction(mdb.SHORT, mdb.NAME, mdb.FIELDS, "time,name,file,count", mdb.FIELD, "time,id,file,size,text"))},
|
||||
})
|
||||
}
|
||||
func Pipe(m *ice.Message, cb func(string)) io.WriteCloser {
|
||||
|
@ -23,13 +23,14 @@ func _trash_create(m *ice.Message, from string) {
|
||||
p = path.Join(ice.VAR_TRASH, kit.HashsPath(f))
|
||||
}
|
||||
}
|
||||
MkdirAll(m, path.Dir(p))
|
||||
if RemoveAll(m, p); !m.Warn(Rename(m, from, p)) {
|
||||
mdb.HashCreate(m, FROM, from, FILE, p)
|
||||
m.Result(p)
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
FROM = "from"
|
||||
)
|
||||
const TRASH = "trash"
|
||||
|
||||
func init() {
|
||||
@ -38,9 +39,8 @@ func init() {
|
||||
mdb.REVERT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
Rename(m, m.Option(FILE), m.Option(FROM))
|
||||
mdb.HashRemove(m, m.OptionSimple(mdb.HASH))
|
||||
m.ProcessRefresh()
|
||||
}},
|
||||
mdb.CREATE: {Name: "create from", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.CREATE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
_trash_create(m, m.Option(FROM))
|
||||
}},
|
||||
mdb.REMOVE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -50,12 +50,6 @@ func init() {
|
||||
mdb.PRUNES: {Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashPrunes(m, nil).Tables(func(value ice.Maps) { Remove(m, value[FILE]) })
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, FROM, mdb.FIELD, "time,hash,from,file")), Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.HashSelect(m, arg...); len(arg) == 0 || !ExistsFile(m, arg[0]) {
|
||||
m.PushAction(mdb.REVERT, mdb.REMOVE)
|
||||
return
|
||||
}
|
||||
_trash_create(m, arg[0])
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, FROM, mdb.FIELD, "time,hash,from,file", mdb.ACTION, mdb.REVERT))},
|
||||
})
|
||||
}
|
||||
|
@ -190,4 +190,20 @@ func init() {
|
||||
})
|
||||
}},
|
||||
})
|
||||
ice.AddMerges(func(c *ice.Context, key string, cmd *ice.Command, sub string, action *ice.Action) (ice.Handler, ice.Handler) {
|
||||
switch sub {
|
||||
case UPLOAD:
|
||||
if key == CACHE {
|
||||
break
|
||||
}
|
||||
hand := action.Hand
|
||||
action.Hand = func(m *ice.Message, arg ...string) {
|
||||
if len(kit.Simple(m.Optionv(ice.MSG_UPLOAD))) == 1 {
|
||||
m.Cmdy(CACHE, UPLOAD)
|
||||
}
|
||||
hand(m, arg...)
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
})
|
||||
}
|
||||
|
4
misc.go
4
misc.go
@ -312,8 +312,6 @@ func MergeActions(arg ...Any) Actions {
|
||||
for k, v := range from {
|
||||
if h, ok := list[k]; !ok {
|
||||
list[k] = v
|
||||
} else if h.Hand == nil {
|
||||
h.Hand = v.Hand
|
||||
} else if k == CTX_INIT {
|
||||
last := h.Hand
|
||||
hand := v.Hand
|
||||
@ -321,6 +319,8 @@ func MergeActions(arg ...Any) Actions {
|
||||
hand(m, arg...)
|
||||
last(m, arg...)
|
||||
}
|
||||
} else if h.Name = kit.Select(v.Name, h.Name); h.Hand == nil {
|
||||
h.Hand = v.Hand
|
||||
}
|
||||
}
|
||||
case string:
|
||||
|
Loading…
x
Reference in New Issue
Block a user