mirror of
https://shylinux.com/x/icebergs
synced 2025-05-01 19:19:24 +08:00
opt nfs
This commit is contained in:
parent
244dab2e4b
commit
3ac6548226
@ -98,13 +98,6 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
func Right(m *ice.Message, key ...ice.Any) bool {
|
||||
return m.Option(ice.MSG_USERROLE) == ROOT || !m.Warn(m.Cmdx(ROLE, RIGHT, m.Option(ice.MSG_USERROLE), key) != ice.OK,
|
||||
ice.ErrNotRight, kit.Keys(key...), USERROLE, m.Option(ice.MSG_USERROLE), logs.FileLineMeta(logs.FileLine(2)))
|
||||
}
|
||||
func RoleRight(m *ice.Message, role string, key ...string) bool {
|
||||
return m.Cmdx(ROLE, RIGHT, role, key) == ice.OK
|
||||
}
|
||||
func RoleAction(key ...string) ice.Actions {
|
||||
return ice.Actions{ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if c, ok := ice.Info.Index[m.CommandKey()].(*ice.Context); ok && c == m.Target() {
|
||||
@ -135,3 +128,21 @@ func BlackAction(key ...string) ice.Actions {
|
||||
}
|
||||
}}}
|
||||
}
|
||||
func RoleRight(m *ice.Message, role string, key ...string) bool {
|
||||
return m.Cmdx(ROLE, RIGHT, role, key) == ice.OK
|
||||
}
|
||||
func Right(m *ice.Message, key ...ice.Any) bool {
|
||||
return m.Option(ice.MSG_USERROLE) == ROOT || !m.Warn(m.Cmdx(ROLE, RIGHT, m.Option(ice.MSG_USERROLE), key) != ice.OK,
|
||||
ice.ErrNotRight, kit.Keys(key...), USERROLE, m.Option(ice.MSG_USERROLE), logs.FileLineMeta(logs.FileLine(2)))
|
||||
}
|
||||
|
||||
func White(m *ice.Message, key ...string) {
|
||||
for _, key := range key {
|
||||
m.Cmd(ROLE, WHITE, VOID, key)
|
||||
}
|
||||
}
|
||||
func Black(m *ice.Message, key ...string) {
|
||||
for _, key := range key {
|
||||
m.Cmd(ROLE, BLACK, VOID, key)
|
||||
}
|
||||
}
|
@ -48,6 +48,7 @@ func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd {
|
||||
}
|
||||
}
|
||||
cmd := exec.Command(bin, arg[1:]...)
|
||||
m.Debug("what %v", m.Option("cmd_dir"))
|
||||
if cmd.Dir = kit.TrimPath(m.Option(CMD_DIR)); len(cmd.Dir) > 0 {
|
||||
if m.Logs(mdb.EXPORT, CMD_DIR, cmd.Dir); !nfs.ExistsFile(m, cmd.Dir) {
|
||||
file.MkdirAll(cmd.Dir, ice.MOD_DIR)
|
||||
@ -128,7 +129,8 @@ const (
|
||||
CMD_ERR = "cmd_err"
|
||||
CMD_OUT = "cmd_out"
|
||||
|
||||
MAN = "man"
|
||||
MAN = "man"
|
||||
GREP = "grep"
|
||||
)
|
||||
|
||||
const SYSTEM = "system"
|
||||
@ -136,7 +138,7 @@ const SYSTEM = "system"
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SYSTEM: {Name: "system cmd run", Help: "系统命令", Actions: ice.Actions{
|
||||
nfs.FIND: {Hand: func(m *ice.Message, arg ...string) {
|
||||
"find": {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(_system_find(m, arg[0], arg[1:]...))
|
||||
}},
|
||||
nfs.PUSH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
|
@ -10,9 +10,7 @@ import (
|
||||
"shylinux.com/x/toolkits/miss"
|
||||
)
|
||||
|
||||
func _hash_fields(m *ice.Message) []string {
|
||||
return kit.Split(kit.Select(HASH_FIELD, m.OptionFields()))
|
||||
}
|
||||
func _hash_fields(m *ice.Message) []string { return kit.Split(kit.Select(HASH_FIELD, m.OptionFields())) }
|
||||
func _hash_inputs(m *ice.Message, prefix, chain string, field, value string) {
|
||||
list := map[string]int{}
|
||||
defer func() {
|
||||
@ -62,11 +60,11 @@ func _hash_select(m *ice.Message, prefix, chain, field, value string) {
|
||||
}
|
||||
func _hash_select_field(m *ice.Message, prefix, chain string, key string, field string) (value string) {
|
||||
defer RLock(m, prefix, chain)()
|
||||
Richs(m, prefix, chain, key, func(k string, v Map) {
|
||||
Richs(m, prefix, chain, key, func(key string, val Map) {
|
||||
if field == HASH {
|
||||
value = k
|
||||
value = key
|
||||
} else {
|
||||
value = kit.Format(v[field])
|
||||
value = kit.Format(val[field])
|
||||
}
|
||||
})
|
||||
return
|
||||
@ -179,7 +177,7 @@ func HashModify(m *ice.Message, arg ...Any) *ice.Message {
|
||||
}
|
||||
func HashSelect(m *ice.Message, arg ...string) *ice.Message {
|
||||
if len(arg) > 0 && arg[0] == FOREACH {
|
||||
m.OptionFields(HashField(m))
|
||||
m.Fields(0, HashField(m))
|
||||
} else {
|
||||
m.Fields(len(kit.Slice(arg, 0, 1)), HashField(m))
|
||||
}
|
||||
@ -190,7 +188,7 @@ func HashSelect(m *ice.Message, arg ...string) *ice.Message {
|
||||
return m.StatusTime()
|
||||
}
|
||||
func HashPrunes(m *ice.Message, cb func(Map) bool) *ice.Message {
|
||||
expire := kit.Select(m.Time("-72h"), m.Option("before"))
|
||||
expire := kit.Select(m.Time("-"+kit.Select("72h", m.Config(EXPIRE))), m.Option("before"))
|
||||
m.OptionCB(PRUNES, func(key string, value Map) bool {
|
||||
if kit.Format(value[TIME]) > expire {
|
||||
return false
|
||||
@ -212,16 +210,12 @@ func HashSelects(m *ice.Message, arg ...string) *ice.Message {
|
||||
}
|
||||
func HashSelectValue(m *ice.Message, cb Any) *ice.Message {
|
||||
defer RLock(m, m.PrefixKey(), "")()
|
||||
Richs(m, m.PrefixKey(), nil, FOREACH, func(key string, value Map) {
|
||||
_mdb_select(m, cb, key, value, nil, nil)
|
||||
})
|
||||
Richs(m, m.PrefixKey(), nil, FOREACH, func(key string, value Map) { _mdb_select(m, cb, key, value, nil, nil) })
|
||||
return m
|
||||
}
|
||||
func HashSelectUpdate(m *ice.Message, key string, cb Any) *ice.Message {
|
||||
defer Lock(m, m.PrefixKey(), "")()
|
||||
Richs(m, m.PrefixKey(), nil, key, func(key string, value Map) {
|
||||
_mdb_select(m, cb, key, value, nil, nil)
|
||||
})
|
||||
Richs(m, m.PrefixKey(), nil, key, func(key string, value Map) { _mdb_select(m, cb, key, value, nil, nil) })
|
||||
return m
|
||||
}
|
||||
func HashSelectDetail(m *ice.Message, key string, cb Any) (has bool) {
|
||||
|
@ -10,9 +10,7 @@ import (
|
||||
"shylinux.com/x/toolkits/miss"
|
||||
)
|
||||
|
||||
func _list_fields(m *ice.Message) []string {
|
||||
return kit.Split(kit.Select(LIST_FIELD, m.OptionFields()))
|
||||
}
|
||||
func _list_fields(m *ice.Message) []string { return kit.Split(kit.Select(LIST_FIELD, m.OptionFields())) }
|
||||
func _list_inputs(m *ice.Message, prefix, chain string, field, value string) {
|
||||
list := map[string]int{}
|
||||
defer func() {
|
||||
@ -39,6 +37,7 @@ func _list_modify(m *ice.Message, prefix, chain string, field, value string, arg
|
||||
Grows(m, prefix, chain, field, value, func(index int, val ice.Map) { _mdb_modify(m, val, field, arg...) })
|
||||
}
|
||||
func _list_select(m *ice.Message, prefix, chain, field, value string) {
|
||||
defer m.SortIntR(ID)
|
||||
fields := _list_fields(m)
|
||||
defer RLock(m, prefix, chain)()
|
||||
Grows(m, prefix, chain, kit.Select(m.Option(CACHE_FIELD), field), kit.Select(m.Option(CACHE_VALUE), value), func(value ice.Map) {
|
||||
@ -124,7 +123,6 @@ func ListField(m *ice.Message) string { return kit.Select(LIST_FIELD, m.Config(F
|
||||
func ListSelect(m *ice.Message, arg ...string) *ice.Message {
|
||||
m.Fields(len(kit.Slice(arg, 0, 1)), ListField(m))
|
||||
if m.Cmdy(SELECT, m.PrefixKey(), "", LIST, ID, arg); !m.FieldsIsDetail() {
|
||||
m.SortIntR(ID)
|
||||
return m.StatusTimeCountTotal(m.Config(COUNT))
|
||||
}
|
||||
return m.StatusTime()
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
"shylinux.com/x/toolkits/logs"
|
||||
"shylinux.com/x/toolkits/task"
|
||||
)
|
||||
|
||||
@ -113,6 +112,7 @@ const (
|
||||
DETAIL = "detail"
|
||||
RANDOM = "random"
|
||||
ACTION = "action"
|
||||
FIELDS = "fields"
|
||||
|
||||
INPUTS = "inputs"
|
||||
CREATE = "create"
|
||||
|
@ -18,6 +18,7 @@ func _zone_inputs(m *ice.Message, prefix, chain, zone string, field, value strin
|
||||
_hash_inputs(m, prefix, chain, field, value)
|
||||
return
|
||||
}
|
||||
defer RLock(m, prefix, chain)()
|
||||
h := _hash_select_field(m, prefix, chain, zone, HASH)
|
||||
_list_inputs(m, prefix, kit.Keys(chain, HASH, h), field, value)
|
||||
}
|
||||
@ -27,11 +28,13 @@ func _zone_insert(m *ice.Message, prefix, chain, zone string, arg ...string) {
|
||||
h = _hash_insert(m, prefix, chain, _mdb_getmeta(m, prefix, chain, SHORT), zone)
|
||||
}
|
||||
m.Assert(h != "")
|
||||
defer Lock(m, prefix, chain)()
|
||||
_list_insert(m, prefix, kit.Keys(chain, HASH, h), arg...)
|
||||
}
|
||||
func _zone_modify(m *ice.Message, prefix, chain, zone, id string, arg ...string) {
|
||||
h := _hash_select_field(m, prefix, chain, zone, HASH)
|
||||
m.Assert(h != "")
|
||||
defer Lock(m, prefix, chain)()
|
||||
_list_modify(m, prefix, kit.Keys(chain, HASH, h), ID, id, arg...)
|
||||
}
|
||||
func _zone_select(m *ice.Message, prefix, chain, zone string, id string) {
|
||||
@ -41,6 +44,7 @@ func _zone_select(m *ice.Message, prefix, chain, zone string, id string) {
|
||||
} else if zone == RANDOM {
|
||||
zone = RANDOMS
|
||||
}
|
||||
defer m.SortIntR(ID)
|
||||
fields := _zone_fields(m)
|
||||
defer RLock(m, prefix, chain)()
|
||||
Richs(m, prefix, chain, kit.Select(FOREACH, zone), func(key string, val Map) {
|
||||
@ -183,11 +187,10 @@ func ZoneModify(m *ice.Message, arg ...Any) {
|
||||
}
|
||||
func ZoneSelect(m *ice.Message, arg ...string) *ice.Message {
|
||||
arg = kit.Slice(arg, 0, 2)
|
||||
m.Fields(len(arg), kit.Fields(TIME, m.Config(SHORT), COUNT), ZoneField(m))
|
||||
m.Fields(len(arg), kit.Select(kit.Fields(TIME, m.Config(SHORT), COUNT), m.Config(FIELDS)), ZoneField(m))
|
||||
if m.Cmdy(SELECT, m.PrefixKey(), "", ZONE, arg, logs.FileLineMeta(logs.FileLine(-1))); len(arg) == 0 {
|
||||
m.Sort(ZoneShort(m)).StatusTimeCount().PushAction(m.Config(ACTION), REMOVE)
|
||||
} else if len(arg) == 1 {
|
||||
m.SortIntR(ID)
|
||||
m.StatusTimeCountTotal(_mdb_getmeta(m, "", kit.Keys(HASH, HashSelectField(m, arg[0], HASH)), COUNT))
|
||||
}
|
||||
return m
|
||||
|
@ -14,14 +14,14 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _cat_find(m *ice.Message, name string) (io.ReadCloser, error) {
|
||||
func _cat_find(m *ice.Message, file string) (io.ReadCloser, error) {
|
||||
if m.Option(CAT_CONTENT) != "" {
|
||||
return NewReadCloser(bytes.NewBufferString(m.Option(CAT_CONTENT))), nil
|
||||
}
|
||||
return OpenFile(m, path.Join(m.Option(DIR_ROOT), name))
|
||||
return OpenFile(m, path.Join(m.Option(DIR_ROOT), file))
|
||||
}
|
||||
func _cat_size(m *ice.Message, p string) (nline int) {
|
||||
if f, e := OpenFile(m, p); m.Warn(e) {
|
||||
func _cat_size(m *ice.Message, file string) (nline int) {
|
||||
if f, e := OpenFile(m, file); !m.Warn(e) {
|
||||
defer f.Close()
|
||||
for bio := bufio.NewScanner(f); bio.Scan(); nline++ {
|
||||
bio.Text()
|
||||
@ -29,23 +29,22 @@ func _cat_size(m *ice.Message, p string) (nline int) {
|
||||
}
|
||||
return nline
|
||||
}
|
||||
func _cat_hash(m *ice.Message, p string) string {
|
||||
if f, e := OpenFile(m, p); !m.Warn(e) {
|
||||
func _cat_hash(m *ice.Message, file string) string {
|
||||
if f, e := OpenFile(m, file); !m.Warn(e) {
|
||||
defer f.Close()
|
||||
return kit.Hashs(f)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
func _cat_list(m *ice.Message, name string) {
|
||||
if m.Option(CAT_CONTENT) == "" && !aaa.Right(m, name) {
|
||||
return // 没有权限
|
||||
func _cat_list(m *ice.Message, file string) {
|
||||
if m.Option(CAT_CONTENT) == "" && !aaa.Right(m, file) {
|
||||
return
|
||||
}
|
||||
f, e := _cat_find(m, name)
|
||||
if m.Warn(e, ice.ErrNotFound) {
|
||||
return // 没有文件
|
||||
f, e := _cat_find(m, file)
|
||||
if m.Warn(e, ice.ErrNotFound, file) {
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
switch cb := m.OptionCB("").(type) {
|
||||
case func(string, int) string:
|
||||
list := []string{}
|
||||
@ -53,28 +52,25 @@ func _cat_list(m *ice.Message, name string) {
|
||||
list = append(list, cb(bio.Text(), i))
|
||||
}
|
||||
m.Echo(strings.Join(list, ice.NL) + ice.NL)
|
||||
|
||||
case func(string, int):
|
||||
for bio, i := bufio.NewScanner(f), 0; bio.Scan(); i++ {
|
||||
cb(bio.Text(), i)
|
||||
}
|
||||
|
||||
case func(string):
|
||||
for bio := bufio.NewScanner(f); bio.Scan(); {
|
||||
cb(bio.Text())
|
||||
}
|
||||
|
||||
case func([]string, string):
|
||||
for bio := bufio.NewScanner(f); bio.Scan(); {
|
||||
cb(kit.Split(bio.Text()), bio.Text())
|
||||
}
|
||||
case nil:
|
||||
buf, begin := make([]byte, ice.MOD_BUFS), 0
|
||||
buf, size := make([]byte, ice.MOD_BUFS), 0
|
||||
for {
|
||||
if n, e := f.Read(buf[begin:]); !m.Warn(e, ice.ErrNotValid, name) {
|
||||
m.Logs(mdb.IMPORT, FILE, name, SIZE, n)
|
||||
if begin += n; begin < len(buf) {
|
||||
buf = buf[:begin]
|
||||
if n, e := f.Read(buf[size:]); !m.Warn(e, ice.ErrNotValid, file) {
|
||||
m.Logs(mdb.IMPORT, FILE, file, SIZE, n)
|
||||
if size += n; size < len(buf) {
|
||||
buf = buf[:size]
|
||||
break
|
||||
}
|
||||
buf = append(buf, make([]byte, ice.MOD_BUFS)...)
|
||||
@ -82,7 +78,7 @@ func _cat_list(m *ice.Message, name string) {
|
||||
break
|
||||
}
|
||||
}
|
||||
m.Echo(string(buf))
|
||||
m.Echo(string(buf)).StatusTime(FILE, file, SIZE, size)
|
||||
default:
|
||||
m.ErrorNotImplement(cb)
|
||||
}
|
||||
@ -92,8 +88,8 @@ const (
|
||||
CAT_CONTENT = "cat_content"
|
||||
|
||||
STDIO = "stdio"
|
||||
SOURCE = "source"
|
||||
MODULE = "module"
|
||||
SOURCE = "source"
|
||||
SCRIPT = "script"
|
||||
BINARY = "binary"
|
||||
TARGET = "target"
|
||||
@ -105,29 +101,30 @@ const (
|
||||
REPOS = "repos"
|
||||
)
|
||||
const (
|
||||
SVG = ice.SVG
|
||||
HTML = ice.HTML
|
||||
CSS = ice.CSS
|
||||
JS = ice.JS
|
||||
GO = ice.GO
|
||||
SH = ice.SH
|
||||
SHY = ice.SHY
|
||||
SVG = ice.SVG
|
||||
CSV = ice.CSV
|
||||
JSON = ice.JSON
|
||||
|
||||
PY = "py"
|
||||
MD = "md"
|
||||
TXT = "txt"
|
||||
IML = "iml"
|
||||
XML = "xml"
|
||||
YML = "yml"
|
||||
ZML = "zml"
|
||||
IML = "iml"
|
||||
|
||||
PNG = "png"
|
||||
JPG = "jpg"
|
||||
MP4 = "mp4"
|
||||
PDF = "pdf"
|
||||
|
||||
TAR = "tar"
|
||||
PWD = "./"
|
||||
PS = ice.PS
|
||||
PT = ice.PT
|
||||
@ -137,28 +134,21 @@ const CAT = "cat"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Configs: ice.Configs{
|
||||
CAT: {Name: CAT, Help: "文件", Value: kit.Data(
|
||||
SOURCE, kit.Dict(
|
||||
HTML, ice.TRUE, CSS, ice.TRUE, JS, ice.TRUE, GO, ice.TRUE, SH, ice.TRUE, CSV, ice.TRUE, JSON, ice.TRUE,
|
||||
SHY, ice.TRUE, "conf", ice.TRUE, "makefile", ice.TRUE, "license", ice.TRUE,
|
||||
PY, ice.TRUE, MD, ice.TRUE, TXT, ice.TRUE, IML, ice.TRUE, XML, ice.TRUE, YML, ice.TRUE, ZML, ice.TRUE,
|
||||
"configure", ice.TRUE,
|
||||
),
|
||||
)},
|
||||
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,
|
||||
))},
|
||||
}, Commands: ice.Commands{
|
||||
CAT: {Name: "cat path auto", Help: "文件", Actions: ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(aaa.ROLE, aaa.WHITE, aaa.VOID, ice.SRC_MAIN_SHY)
|
||||
m.Cmd(aaa.ROLE, aaa.WHITE, aaa.VOID, ice.SRC_MAIN_GO)
|
||||
m.Cmd(aaa.ROLE, aaa.WHITE, aaa.VOID, ice.USR_PUBLISH)
|
||||
}},
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { aaa.White(m, ice.SRC_MAIN_SHY, ice.SRC_MAIN_GO, ice.USR_PUBLISH) }},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 || strings.HasSuffix(arg[0], ice.PS) {
|
||||
m.Cmdy(DIR, arg)
|
||||
return
|
||||
}
|
||||
if m.Option(DIR_ROOT) != "" {
|
||||
m.Logs(mdb.SELECT, DIR_ROOT, m.Option(DIR_ROOT))
|
||||
m.Logs(mdb.SELECT, m.OptionSimple(DIR_ROOT))
|
||||
}
|
||||
_cat_list(m, arg[0])
|
||||
}},
|
||||
@ -170,13 +160,9 @@ func IsSourceFile(m *ice.Message, ext string) bool {
|
||||
func OptionLoad(m *ice.Message, file string) *ice.Message {
|
||||
if f, e := OpenFile(m, file); e == nil {
|
||||
defer f.Close()
|
||||
|
||||
var data ice.Any
|
||||
m.Assert(json.NewDecoder(f).Decode(&data))
|
||||
|
||||
kit.Fetch(data, func(key string, value ice.Any) {
|
||||
m.Option(key, kit.Simple(value))
|
||||
})
|
||||
kit.Fetch(data, func(key string, value ice.Any) { m.Option(key, kit.Simple(value)) })
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
@ -12,14 +12,14 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _dir_size(m *ice.Message, p string) int {
|
||||
if ls, e := ReadDir(m, p); !m.Warn(e) {
|
||||
func _dir_size(m *ice.Message, dir string) int {
|
||||
if ls, e := ReadDir(m, dir); !m.Warn(e) {
|
||||
return len(ls)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
func _dir_hash(m *ice.Message, p string) string {
|
||||
if ls, e := ReadDir(m, p); !m.Warn(e) {
|
||||
func _dir_hash(m *ice.Message, dir string) string {
|
||||
if ls, e := ReadDir(m, dir); !m.Warn(e) {
|
||||
meta := []string{}
|
||||
for _, s := range ls {
|
||||
meta = append(meta, kit.Format("%s%d%s", s.Name(), s.Size(), s.ModTime()))
|
||||
@ -28,30 +28,27 @@ func _dir_hash(m *ice.Message, p string) string {
|
||||
}
|
||||
return ""
|
||||
}
|
||||
func _dir_list(m *ice.Message, root string, name string, level int, deep bool, dir_type string, dir_reg *regexp.Regexp, fields []string) *ice.Message {
|
||||
list, _ := ReadDir(m, path.Join(root, name))
|
||||
|
||||
if len(list) == 0 { // 单个文件
|
||||
if s, e := StatFile(m, path.Join(root, name)); e == nil && !s.IsDir() {
|
||||
ls, _ := ReadDir(m, path.Dir(path.Join(root, name)))
|
||||
for _, s := range ls {
|
||||
if s.Name() == path.Base(name) {
|
||||
list = append(list, s)
|
||||
func _dir_list(m *ice.Message, root string, dir string, level int, deep bool, dir_type string, dir_reg *regexp.Regexp, fields []string) *ice.Message {
|
||||
ls, _ := ReadDir(m, path.Join(root, dir))
|
||||
if len(ls) == 0 {
|
||||
if s, e := StatFile(m, path.Join(root, dir)); e == nil && !s.IsDir() {
|
||||
_ls, _ := ReadDir(m, path.Dir(path.Join(root, dir)))
|
||||
for _, s := range _ls {
|
||||
if s.Name() == path.Base(dir) {
|
||||
ls = append(ls, s)
|
||||
}
|
||||
}
|
||||
name, deep = path.Dir(name), false
|
||||
dir, deep = path.Dir(dir), false
|
||||
}
|
||||
}
|
||||
|
||||
for _, f := range list {
|
||||
for _, f := range ls {
|
||||
if f.Name() == ice.PT || f.Name() == ".." {
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(f.Name(), ice.PT) && dir_type != TYPE_ALL {
|
||||
continue
|
||||
}
|
||||
|
||||
p, pp := path.Join(root, name, f.Name()), path.Join(name, f.Name())
|
||||
p, _dir := path.Join(root, dir, f.Name()), path.Join(dir, f.Name())
|
||||
isDir := f.IsDir() || kit.IsDir(p)
|
||||
if !(dir_type == TYPE_CAT && isDir || dir_type == TYPE_DIR && !isDir) && (dir_reg == nil || dir_reg.MatchString(f.Name())) {
|
||||
switch cb := m.OptionCB("").(type) {
|
||||
@ -65,14 +62,12 @@ func _dir_list(m *ice.Message, root string, name string, level int, deep bool, d
|
||||
default:
|
||||
m.ErrorNotImplement(cb)
|
||||
}
|
||||
|
||||
for _, field := range fields {
|
||||
switch field {
|
||||
case mdb.TIME:
|
||||
m.Push(field, f.ModTime().Format(ice.MOD_TIME))
|
||||
case mdb.TYPE:
|
||||
m.Push(field, kit.Select(CAT, DIR, isDir))
|
||||
|
||||
case TREE:
|
||||
if level == 0 {
|
||||
m.Push(field, f.Name())
|
||||
@ -82,12 +77,11 @@ func _dir_list(m *ice.Message, root string, name string, level int, deep bool, d
|
||||
case FULL:
|
||||
m.Push(field, p+kit.Select("", ice.PS, isDir))
|
||||
case PATH:
|
||||
m.Push(field, pp+kit.Select("", ice.PS, isDir))
|
||||
m.Push(field, _dir+kit.Select("", ice.PS, isDir))
|
||||
case FILE:
|
||||
m.Push(field, f.Name()+kit.Select("", ice.PS, isDir))
|
||||
case NAME:
|
||||
m.Push(field, f.Name())
|
||||
|
||||
case SIZE:
|
||||
if isDir {
|
||||
m.Push(field, _dir_size(m, p))
|
||||
@ -129,14 +123,12 @@ func _dir_list(m *ice.Message, root string, name string, level int, deep bool, d
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if deep && isDir {
|
||||
switch f.Name() {
|
||||
case "node_modules", "pluged", "target", "trash":
|
||||
continue // 禁用递归
|
||||
continue
|
||||
}
|
||||
|
||||
_dir_list(m, root, pp, level+1, deep, dir_type, dir_reg, fields)
|
||||
_dir_list(m, root, _dir, level+1, deep, dir_type, dir_reg, fields)
|
||||
}
|
||||
}
|
||||
return m
|
||||
@ -172,33 +164,25 @@ const DIR = "dir"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
DIR: {Name: "dir path field auto upload", Help: "目录", Actions: ice.Actions{
|
||||
DIR: {Name: "dir path field auto dir_deep upload", Help: "目录", Actions: ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(aaa.ROLE, aaa.WHITE, aaa.VOID, ice.SRC)
|
||||
m.Cmd(aaa.ROLE, aaa.WHITE, aaa.VOID, ice.BIN)
|
||||
m.Cmd(aaa.ROLE, aaa.WHITE, aaa.VOID, ice.USR)
|
||||
m.Cmd(aaa.ROLE, aaa.BLACK, aaa.VOID, ice.USR_LOCAL)
|
||||
m.Cmd(aaa.ROLE, aaa.WHITE, aaa.VOID, ice.USR_LOCAL_GO)
|
||||
}},
|
||||
mdb.UPLOAD: {Name: "upload", Help: "上传", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy("web.cache", "upload_watch", m.Option(PATH))
|
||||
}},
|
||||
TRASH: {Name: "trash", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(TRASH, mdb.CREATE, m.Option(PATH))
|
||||
aaa.White(m, ice.SRC, ice.BIN, ice.USR, ice.USR_LOCAL_GO)
|
||||
aaa.Black(m, 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)) }},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
root, name := kit.Select(PWD, m.Option(DIR_ROOT)), kit.Select(PWD, arg, 0)
|
||||
if strings.HasPrefix(name, ice.PS) {
|
||||
root, dir := kit.Select(PWD, m.Option(DIR_ROOT)), kit.Select(PWD, arg, 0)
|
||||
if strings.HasPrefix(dir, ice.PS) {
|
||||
root = ice.PS
|
||||
}
|
||||
if !aaa.Right(m, path.Join(root, name)) {
|
||||
return // 没有权限
|
||||
if !aaa.Right(m, path.Join(root, dir)) {
|
||||
return
|
||||
}
|
||||
fields := kit.Split(kit.Select(kit.Select(DIR_DEF_FIELDS, m.OptionFields()), kit.Join(kit.Slice(arg, 1))))
|
||||
m.Logs(mdb.SELECT, DIR_ROOT, m.Option(DIR_ROOT), DIR_REG, m.Option(DIR_REG), mdb.FIELD, kit.Join(fields, ","))
|
||||
_dir_list(m, root, name, 0, m.Option(DIR_DEEP) == ice.TRUE, kit.Select(TYPE_BOTH, m.Option(DIR_TYPE)), kit.Regexp(m.Option(DIR_REG)), fields)
|
||||
m.SortTimeR(mdb.TIME)
|
||||
m.StatusTimeCount()
|
||||
m.Logs(mdb.SELECT, DIR_ROOT, m.Option(DIR_ROOT), DIR_REG, m.Option(DIR_REG), mdb.FIELD, kit.Join(fields, ice.FS))
|
||||
_dir_list(m, root, dir, 0, m.Option(DIR_DEEP) == ice.TRUE, kit.Select(TYPE_BOTH, m.Option(DIR_TYPE)), kit.Regexp(m.Option(DIR_REG)), fields)
|
||||
m.Sort(PATH).StatusTimeCount()
|
||||
}},
|
||||
})
|
||||
}
|
||||
@ -211,10 +195,8 @@ func Dir(m *ice.Message, sort string) *ice.Message {
|
||||
return m
|
||||
}
|
||||
func DirDeepAll(m *ice.Message, root, dir string, cb func(ice.Maps), arg ...string) *ice.Message {
|
||||
m.Option(DIR_TYPE, CAT)
|
||||
m.Option(DIR_ROOT, root)
|
||||
m.Option(DIR_DEEP, ice.TRUE)
|
||||
if msg := m.Cmd(DIR, dir, arg).Sort(PATH).Tables(cb); cb == nil {
|
||||
m.Options(DIR_TYPE, CAT, DIR_ROOT, root, DIR_DEEP, ice.TRUE)
|
||||
if msg := m.Cmd(DIR, dir, arg).Tables(cb); cb == nil {
|
||||
return m.Copy(msg)
|
||||
} else {
|
||||
return msg
|
||||
|
@ -1,19 +0,0 @@
|
||||
package nfs
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
)
|
||||
|
||||
const FIND = "find"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
FIND: {Name: "find path word auto", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
for _, file := range strings.Split(m.Cmdx("cli.system", FIND, PWD, "-name", arg[1]), ice.NL) {
|
||||
m.Push(FILE, strings.TrimPrefix(file, PWD))
|
||||
}
|
||||
}},
|
||||
})
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
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])
|
||||
m.Push(LINE, ls[1])
|
||||
m.Push(mdb.TEXT, ls[2])
|
||||
}
|
||||
}
|
||||
}},
|
||||
})
|
||||
}
|
@ -4,6 +4,4 @@ import ice "shylinux.com/x/icebergs"
|
||||
|
||||
var Index = &ice.Context{Name: "nfs", Help: "存储模块"}
|
||||
|
||||
func init() {
|
||||
ice.Index.Register(Index, nil, TAR, CAT, DIR, PACK, DEFS, SAVE, PUSH, COPY, LINK, TAIL, TRASH, GREP)
|
||||
}
|
||||
func init() { ice.Index.Register(Index, nil, CAT, DIR, PACK, DEFS, SAVE, PUSH, COPY, LINK, TAIL, TRASH) }
|
||||
|
@ -1,7 +0,0 @@
|
||||
chapter "nfs"
|
||||
|
||||
field "文件" nfs.cat
|
||||
field "目录" nfs.dir
|
||||
field "跟踪" nfs.tail
|
||||
field "删除" nfs.trash
|
||||
|
@ -19,18 +19,18 @@ func init() {
|
||||
pack := PackFile
|
||||
Index.MergeCommands(ice.Commands{
|
||||
PACK: {Name: "pack path auto upload create", Help: "文件系统", Actions: ice.Actions{
|
||||
mdb.UPLOAD: {Name: "upload", Help: "上传", Hand: func(m *ice.Message, arg ...string) {
|
||||
if b, h, e := m.R.FormFile(mdb.UPLOAD); m.Assert(e) {
|
||||
defer b.Close()
|
||||
if f, p, e := pack.CreateFile(path.Join(m.Option(PATH), h.Filename)); m.Assert(e) {
|
||||
mdb.UPLOAD: {Hand: func(m *ice.Message, arg ...string) {
|
||||
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) {
|
||||
defer f.Close()
|
||||
if n, e := io.Copy(f, b); m.Assert(e) {
|
||||
if n, e := io.Copy(f, c); m.Assert(e) {
|
||||
m.Logs(mdb.EXPORT, FILE, p, SIZE, n)
|
||||
}
|
||||
}
|
||||
}
|
||||
}},
|
||||
mdb.CREATE: {Name: "create path=h1/h2/hi.txt text=hello", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.CREATE: {Name: "create path=src/hi/hi.txt text=hello", Hand: func(m *ice.Message, arg ...string) {
|
||||
if f, p, e := pack.CreateFile(m.Option(PATH)); m.Assert(e) {
|
||||
defer f.Close()
|
||||
if n, e := f.Write([]byte(m.Option(mdb.TEXT))); m.Assert(e) {
|
||||
@ -38,9 +38,7 @@ func init() {
|
||||
}
|
||||
}
|
||||
}},
|
||||
mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
pack.Remove(path.Clean(m.Option(PATH)))
|
||||
}},
|
||||
mdb.REMOVE: {Hand: func(m *ice.Message, arg ...string) { pack.Remove(path.Clean(m.Option(PATH))) }},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
p := kit.Select("", arg, 0)
|
||||
if p != "" && !strings.HasSuffix(p, PS) {
|
||||
@ -52,16 +50,13 @@ func init() {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
ls, _ := pack.ReadDir(p)
|
||||
for _, f := range ls {
|
||||
m.Push(mdb.TIME, f.ModTime().Format(ice.MOD_TIME))
|
||||
m.Push(PATH, path.Join(p, f.Name())+kit.Select("", PS, f.IsDir()))
|
||||
m.Push(SIZE, kit.FmtSize(f.Size()))
|
||||
}
|
||||
m.Sort("time,path")
|
||||
m.PushAction(mdb.REMOVE)
|
||||
m.StatusTimeCount()
|
||||
m.Sort(PATH).PushAction(mdb.REMOVE).StatusTimeCount()
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -23,46 +23,42 @@ func _defs_file(m *ice.Message, name string, text ...string) {
|
||||
func _save_file(m *ice.Message, name string, text ...string) {
|
||||
if f, p, e := CreateFile(m, path.Join(m.Option(DIR_ROOT), name)); m.Assert(e) {
|
||||
defer f.Close()
|
||||
|
||||
defer m.Echo(p)
|
||||
for _, v := range text {
|
||||
if n, e := fmt.Fprint(f, v); m.Assert(e) {
|
||||
m.Logs(mdb.EXPORT, FILE, p, SIZE, n)
|
||||
}
|
||||
}
|
||||
m.Echo(p)
|
||||
}
|
||||
}
|
||||
func _push_file(m *ice.Message, name string, text ...string) {
|
||||
if f, p, e := AppendFile(m, path.Join(m.Option(DIR_ROOT), name)); m.Assert(e) {
|
||||
defer f.Close()
|
||||
|
||||
defer m.Echo(p)
|
||||
for _, k := range text {
|
||||
if n, e := fmt.Fprint(f, k); m.Assert(e) {
|
||||
m.Logs(mdb.EXPORT, FILE, p, SIZE, n)
|
||||
}
|
||||
}
|
||||
m.Echo(p)
|
||||
}
|
||||
}
|
||||
func _copy_file(m *ice.Message, name string, from ...string) {
|
||||
if f, p, e := CreateFile(m, path.Join(m.Option(DIR_ROOT), name)); m.Assert(e) {
|
||||
defer f.Close()
|
||||
|
||||
defer m.Echo(p)
|
||||
for _, v := range from {
|
||||
if s, e := OpenFile(m, path.Join(m.Option(DIR_ROOT), v)); !m.Warn(e, ice.ErrNotFound, name) {
|
||||
if s, e := OpenFile(m, path.Join(m.Option(DIR_ROOT), v)); !m.Warn(e, ice.ErrNotFound, v) {
|
||||
defer s.Close()
|
||||
|
||||
if n, e := io.Copy(f, s); !m.Warn(e, ice.ErrNotFound, name) {
|
||||
if n, e := io.Copy(f, s); !m.Warn(e, ice.ErrNotValid, v) {
|
||||
m.Logs(mdb.IMPORT, FILE, v, SIZE, n)
|
||||
m.Logs(mdb.EXPORT, FILE, p, SIZE, n)
|
||||
}
|
||||
}
|
||||
}
|
||||
m.Echo(p)
|
||||
}
|
||||
}
|
||||
func _link_file(m *ice.Message, name string, from string) {
|
||||
if m.Warn(from == "", ice.ErrNotValid, from) {
|
||||
if m.Warn(from == "", ice.ErrNotValid, FROM) {
|
||||
return
|
||||
}
|
||||
name = path.Join(m.Option(DIR_ROOT), name)
|
||||
@ -72,10 +68,8 @@ func _link_file(m *ice.Message, name string, from string) {
|
||||
}
|
||||
Remove(m, name)
|
||||
MkdirAll(m, path.Dir(name))
|
||||
if m.Warn(Link(m, from, name)) {
|
||||
if m.Warn(Symlink(m, from, name), ice.ErrWarn, from) {
|
||||
return
|
||||
}
|
||||
if m.Warn(Link(m, from, name)) && m.Warn(Symlink(m, from, name), ice.ErrWarn, from) {
|
||||
return
|
||||
}
|
||||
m.Logs(mdb.CREATE, FILE, name, FROM, from)
|
||||
m.Echo(name)
|
||||
@ -94,22 +88,22 @@ const LINK = "link"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
DEFS: {Name: "defs file text...", Help: "默认", Hand: func(m *ice.Message, arg ...string) {
|
||||
DEFS: {Name: "defs file text run", Help: "默认", Hand: func(m *ice.Message, arg ...string) {
|
||||
_defs_file(m, arg[0], arg[1:]...)
|
||||
}},
|
||||
SAVE: {Name: "save file text...", Help: "保存", Hand: func(m *ice.Message, arg ...string) {
|
||||
SAVE: {Name: "save file text run", Help: "保存", Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 1 {
|
||||
arg = append(arg, m.Option(CONTENT))
|
||||
}
|
||||
_save_file(m, arg[0], arg[1:]...)
|
||||
}},
|
||||
PUSH: {Name: "push file text...", Help: "追加", Hand: func(m *ice.Message, arg ...string) {
|
||||
PUSH: {Name: "push file text run", Help: "追加", Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 1 {
|
||||
arg = append(arg, m.Option(CONTENT))
|
||||
}
|
||||
_push_file(m, arg[0], arg[1:]...)
|
||||
}},
|
||||
COPY: {Name: "copy file from...", Help: "复制", Hand: func(m *ice.Message, arg ...string) {
|
||||
COPY: {Name: "copy file from run", Help: "复制", Hand: func(m *ice.Message, arg ...string) {
|
||||
for _, file := range arg[1:] {
|
||||
if ExistsFile(m, file) {
|
||||
_copy_file(m, arg[0], arg[1:]...)
|
||||
@ -117,7 +111,7 @@ func init() {
|
||||
}
|
||||
}
|
||||
}},
|
||||
LINK: {Name: "link file from", Help: "链接", Hand: func(m *ice.Message, arg ...string) {
|
||||
LINK: {Name: "link file from run", Help: "链接", Hand: func(m *ice.Message, arg ...string) {
|
||||
_link_file(m, arg[0], arg[1])
|
||||
}},
|
||||
})
|
||||
|
@ -3,7 +3,6 @@ package nfs
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
@ -11,66 +10,46 @@ import (
|
||||
)
|
||||
|
||||
func _tail_create(m *ice.Message, arg ...string) {
|
||||
h := m.Cmdx(mdb.INSERT, m.PrefixKey(), "", mdb.HASH, arg)
|
||||
|
||||
kit.ForEach(kit.Split(m.Option(FILE)), func(file string) {
|
||||
r, w := io.Pipe()
|
||||
m.Go(func() {
|
||||
for bio := bufio.NewScanner(r); bio.Scan(); {
|
||||
m.Logs(mdb.IMPORT, FILE, file, SIZE, len(bio.Text()))
|
||||
mdb.Grow(m, TAIL, kit.Keys(mdb.HASH, h), kit.Dict(
|
||||
FILE, file, SIZE, len(bio.Text()), mdb.TEXT, bio.Text(),
|
||||
))
|
||||
}
|
||||
})
|
||||
|
||||
m.Option("cmd_output", w)
|
||||
m.Option(mdb.CACHE_CLEAR_ON_EXIT, ice.TRUE)
|
||||
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)
|
||||
})
|
||||
}
|
||||
func _tail_count(m *ice.Message, name string) string {
|
||||
return m.Conf(TAIL, kit.KeyHash(name, kit.Keym(mdb.COUNT)))
|
||||
}
|
||||
|
||||
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{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.Richs(m, TAIL, "", mdb.FOREACH, func(key string, value ice.Map) {
|
||||
value, _ = kit.GetMeta(value), m.Option(mdb.HASH, key)
|
||||
m.Cmd(TAIL, mdb.CREATE, kit.SimpleKV("file,name", value))
|
||||
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)
|
||||
m.ProcessAgain()
|
||||
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"))
|
||||
}
|
||||
}},
|
||||
mdb.CREATE: {Name: "create file name", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
_tail_create(m, arg...)
|
||||
}},
|
||||
}, mdb.ZoneAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,id,file,text")), Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Fields(len(kit.Slice(arg, 0, 2)), "time,name,count,file", mdb.ZoneField(m))
|
||||
mdb.OptionPage(m, kit.Slice(arg, 2)...)
|
||||
|
||||
mdb.ZoneSelect(m.Spawn(), arg...).Table(func(index int, value ice.Maps, head []string) {
|
||||
if strings.Contains(value[mdb.TEXT], m.Option(mdb.CACHE_FILTER)) {
|
||||
m.Push("", value, head)
|
||||
}
|
||||
})
|
||||
|
||||
if len(arg) > 0 {
|
||||
m.StatusTimeCountTotal(_tail_count(m, arg[0]))
|
||||
}
|
||||
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...)
|
||||
}},
|
||||
})
|
||||
}
|
||||
func Pipe(m *ice.Message, cb func(string)) io.WriteCloser {
|
||||
r, w := io.Pipe()
|
||||
m.Go(func() {
|
||||
for bio := bufio.NewScanner(r); bio.Scan(); {
|
||||
cb(bio.Text())
|
||||
}
|
||||
})
|
||||
return w
|
||||
}
|
||||
|
@ -1,85 +0,0 @@
|
||||
package nfs
|
||||
|
||||
import (
|
||||
"archive/tar"
|
||||
"compress/gzip"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const TAR = "tar"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
TAR: {Name: "tar file path auto", Help: "打包", Actions: ice.Actions{
|
||||
mdb.IMPORT: {Name: "import", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 1 {
|
||||
arg = append(arg, arg[0])
|
||||
}
|
||||
if !strings.HasSuffix(arg[0], ".tar.gz") {
|
||||
arg[0] += ".tar.gz"
|
||||
}
|
||||
m.Cmd("cli.system", "tar", "zcvf", arg)
|
||||
m.Echo(arg[0])
|
||||
}},
|
||||
mdb.EXPORT: {Name: "export", Help: "导出", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd("cli.system", "tar", "xvf", arg)
|
||||
m.Echo(arg[0])
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option("cmd_dir", m.Option(DIR_ROOT))
|
||||
m.Cmdy("cli.system", "tar", "zcvf", arg)
|
||||
return
|
||||
|
||||
file, _, err := CreateFile(m, arg[0])
|
||||
m.Assert(err)
|
||||
defer file.Close()
|
||||
|
||||
var out io.WriteCloser = file
|
||||
if strings.HasSuffix(arg[0], ".gz") {
|
||||
out = gzip.NewWriter(out)
|
||||
defer out.Close()
|
||||
}
|
||||
t := tar.NewWriter(out)
|
||||
defer t.Close()
|
||||
|
||||
dir_root := m.Option(DIR_ROOT)
|
||||
var count, total int64
|
||||
for _, k := range arg[1:] {
|
||||
m.Option(DIR_TYPE, TYPE_CAT)
|
||||
m.Option(DIR_DEEP, ice.TRUE)
|
||||
m.Cmdy(DIR, k, func(f os.FileInfo, p string) {
|
||||
total += f.Size()
|
||||
|
||||
header, err := tar.FileInfoHeader(f, p)
|
||||
if m.Warn(err != nil, err) {
|
||||
return
|
||||
}
|
||||
|
||||
header.Name = strings.TrimPrefix(p, dir_root+ice.PS)
|
||||
if err = t.WriteHeader(header); m.Warn(err) {
|
||||
return
|
||||
}
|
||||
|
||||
file, err := OpenFile(m, p)
|
||||
if m.Warn(err) {
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
if _, err = io.Copy(t, file); m.Warn(err) {
|
||||
return
|
||||
}
|
||||
|
||||
count++
|
||||
})
|
||||
}
|
||||
m.StatusTimeCountTotal(kit.FmtSize(total))
|
||||
}},
|
||||
})
|
||||
}
|
@ -8,25 +8,25 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _trash_create(m *ice.Message, name string) {
|
||||
if m.Warn(name == "", ice.ErrNotValid, name) {
|
||||
func _trash_create(m *ice.Message, from string) {
|
||||
if m.Warn(from == "", ice.ErrNotValid, FROM) {
|
||||
return
|
||||
}
|
||||
s, e := StatFile(m, name)
|
||||
if m.Warn(e, ice.ErrNotFound, name) {
|
||||
s, e := StatFile(m, from)
|
||||
if m.Warn(e, ice.ErrNotFound, from) {
|
||||
return
|
||||
}
|
||||
p := path.Join(ice.VAR_TRASH, path.Base(name))
|
||||
p := path.Join(ice.VAR_TRASH, path.Base(from))
|
||||
if !s.IsDir() {
|
||||
if f, e := OpenFile(m, name); m.Assert(e) {
|
||||
if f, e := OpenFile(m, from); m.Assert(e) {
|
||||
defer f.Close()
|
||||
p = path.Join(ice.VAR_TRASH, kit.HashsPath(f))
|
||||
}
|
||||
}
|
||||
|
||||
MkdirAll(m, path.Dir(p))
|
||||
if RemoveAll(m, p); !m.Warn(Rename(m, name, p)) {
|
||||
mdb.HashCreate(m, FROM, name, FILE, p)
|
||||
if RemoveAll(m, p); !m.Warn(Rename(m, from, p)) {
|
||||
mdb.HashCreate(m, FROM, from, FILE, p)
|
||||
m.Result(p)
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,32 +35,22 @@ const TRASH = "trash"
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
TRASH: {Name: "trash hash auto prunes", Help: "回收站", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.REVERT: {Name: "revert", Help: "恢复", Hand: func(m *ice.Message, arg ...string) {
|
||||
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 path", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
p := path.Join(ice.VAR_TRASH, path.Base(m.Option(PATH)))
|
||||
RemoveAll(m, p)
|
||||
if MkdirAll(m, path.Dir(p)); !m.Warn(Rename(m, m.Option(PATH), p)) {
|
||||
mdb.HashCreate(m, FROM, m.Option(PATH), FILE, p)
|
||||
m.ProcessRefresh()
|
||||
m.Echo(p)
|
||||
}
|
||||
mdb.CREATE: {Name: "create from", Hand: func(m *ice.Message, arg ...string) {
|
||||
_trash_create(m, m.Option(FROM))
|
||||
}},
|
||||
mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.REMOVE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
Remove(m, m.Option(FILE))
|
||||
mdb.HashRemove(m, m.OptionSimple(mdb.HASH))
|
||||
}},
|
||||
mdb.PRUNES: {Name: "prunes before@date", Help: "清理", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashPrunes(m, func(value ice.Map) bool {
|
||||
return true
|
||||
}).Tables(func(value ice.Maps) {
|
||||
Remove(m, value[FILE])
|
||||
})
|
||||
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,file,from")), Hand: func(m *ice.Message, arg ...string) {
|
||||
}, 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
|
||||
|
@ -1,8 +0,0 @@
|
||||
chapter "ssh"
|
||||
|
||||
field "脚本" source
|
||||
field "模块" target
|
||||
field "提示" prompt
|
||||
field "输出" printf
|
||||
field "屏显" screen
|
||||
|
@ -1,6 +0,0 @@
|
||||
chapter "tcp"
|
||||
|
||||
field "主机" host
|
||||
field "端口" port
|
||||
field "客户端" client
|
||||
field "服务器" server
|
@ -1,16 +0,0 @@
|
||||
chapter "web"
|
||||
label "web" `
|
||||
share serve space dream
|
||||
route spide cache story
|
||||
`
|
||||
|
||||
field "蜘蛛侠" web.spide
|
||||
field "缓存池" web.cache
|
||||
field "故事会" web.story
|
||||
field "路由器" web.route
|
||||
|
||||
field "共享链" web.share
|
||||
field "服务器" web.serve
|
||||
field "空间站" web.space
|
||||
field "梦想家" web.dream
|
||||
|
@ -1 +0,0 @@
|
||||
chapter "yac"
|
@ -37,7 +37,7 @@ func _inner_exec(m *ice.Message, ext, file, dir string) {
|
||||
}
|
||||
}
|
||||
func _inner_tags(m *ice.Message, dir string, value string) {
|
||||
for _, l := range strings.Split(m.Cmdx(cli.SYSTEM, nfs.GREP, "^"+value+"\\>", nfs.TAGS, kit.Dict(cli.CMD_DIR, dir)), ice.NL) {
|
||||
for _, l := range strings.Split(m.Cmdx(cli.SYSTEM, cli.GREP, "^"+value+"\\>", nfs.TAGS, kit.Dict(cli.CMD_DIR, dir)), ice.NL) {
|
||||
if strings.HasPrefix(l, "!_") {
|
||||
continue
|
||||
}
|
||||
@ -119,8 +119,8 @@ func init() {
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { _inner_show(m, arg[0], arg[1], arg[2]) }},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { _inner_exec(m, arg[0], arg[1], arg[2]) }},
|
||||
|
||||
nfs.GREP: {Name: "grep", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(nfs.GREP, arg[0], m.Option(nfs.PATH)).StatusTimeCount(mdb.INDEX, 0)
|
||||
cli.GREP: {Name: "grep", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(cli.GREP, arg[0], m.Option(nfs.PATH)).StatusTimeCount(mdb.INDEX, 0)
|
||||
}},
|
||||
nfs.TAGS: {Name: "tags", Help: "索引", Hand: func(m *ice.Message, arg ...string) {
|
||||
if _inner_tags(m, m.Option(nfs.PATH), arg[0]); m.Length() == 0 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user