mirror of
https://shylinux.com/x/icebergs
synced 2025-04-25 17:18:05 +08:00
opt publish
This commit is contained in:
parent
67e5d07a13
commit
6c9b2c0b8b
@ -414,6 +414,7 @@ const (
|
||||
SCRIPT = "script"
|
||||
COMMIT = "commit"
|
||||
SOURCE = "source"
|
||||
UPLOAD = "upload"
|
||||
)
|
||||
const (
|
||||
CACHE_LIMIT = "cache.limit"
|
||||
|
@ -1,130 +0,0 @@
|
||||
package nfs
|
||||
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func travel(m *ice.Message, root string, name string, cb func(name string)) {
|
||||
if fs, e := ioutil.ReadDir(path.Join(root, name)); e != nil {
|
||||
cb(name)
|
||||
} else {
|
||||
for _, f := range fs {
|
||||
if f.Name() == "." || f.Name() == ".." {
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(f.Name(), ".") {
|
||||
continue
|
||||
}
|
||||
|
||||
p := path.Join(root, name, f.Name())
|
||||
if f, e = os.Lstat(p); e != nil {
|
||||
m.Log("info", "%s", e)
|
||||
continue
|
||||
} else if (f.Mode()&os.ModeSymlink) != 0 && f.IsDir() {
|
||||
continue
|
||||
}
|
||||
if f.IsDir() {
|
||||
travel(m, root, path.Join(name, f.Name()), cb)
|
||||
cb(path.Join(name, f.Name()))
|
||||
} else {
|
||||
cb(path.Join(name, f.Name()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
SEARCH = "search"
|
||||
COMMEND = "commend"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Index.Register(&ice.Context{Name: "search", Help: "搜索",
|
||||
Commands: map[string]*ice.Command{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmd(SEARCH, "add", "dir", "base", m.AddCmd(&ice.Command{Name: "search word", Help: "搜索引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
switch arg[0] {
|
||||
case "set":
|
||||
m.Cmdy("nfs.dir", arg[5])
|
||||
return
|
||||
}
|
||||
|
||||
travel(m, "./", "", func(name string) {
|
||||
if strings.Contains(name, arg[0]) {
|
||||
s, e := os.Stat(name)
|
||||
m.Assert(e)
|
||||
m.Push("pod", m.Option(ice.MSG_USERPOD))
|
||||
m.Push("engine", "dir")
|
||||
m.Push("favor", "file")
|
||||
m.Push("id", kit.FmtSize(s.Size()))
|
||||
m.Push("time", s.ModTime().Format(ice.MOD_TIME))
|
||||
m.Push("type", strings.TrimPrefix(path.Ext(name), "."))
|
||||
m.Push("name", path.Base(name))
|
||||
m.Push("text", name)
|
||||
}
|
||||
})
|
||||
}}))
|
||||
m.Cmd(COMMEND, "add", "dir", "base", m.AddCmd(&ice.Command{Name: "commend word", Help: "推荐引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
switch arg[0] {
|
||||
case "set":
|
||||
m.Cmdy("nfs.dir", arg[5])
|
||||
return
|
||||
}
|
||||
|
||||
travel(m, "./", "", func(name string) {
|
||||
score := 0
|
||||
m.Richs(COMMEND, "meta.user", m.Option(ice.MSG_USERNAME), func(key string, value map[string]interface{}) {
|
||||
m.Grows(COMMEND, kit.Keys("meta.user", kit.MDB_HASH, key, "like"), "", "", func(index int, value map[string]interface{}) {
|
||||
switch kit.Value(value, "extra.engine") {
|
||||
case "dir":
|
||||
if value["type"] == strings.TrimPrefix(path.Ext(name), ".") {
|
||||
score += 1
|
||||
}
|
||||
if value["name"] == path.Base(name) {
|
||||
score += 2
|
||||
}
|
||||
if value["text"] == name {
|
||||
score += 3
|
||||
}
|
||||
default:
|
||||
}
|
||||
})
|
||||
m.Grows(cmd, kit.Keys("meta.user", kit.MDB_HASH, key, "hate"), "", "", func(index int, value map[string]interface{}) {
|
||||
switch kit.Value(value, "extra.engine") {
|
||||
case "dir":
|
||||
if value["type"] == strings.TrimPrefix(path.Ext(name), ".") {
|
||||
score -= 1
|
||||
}
|
||||
if value["name"] == path.Base(name) {
|
||||
score -= 2
|
||||
}
|
||||
if value["text"] == name {
|
||||
score -= 3
|
||||
}
|
||||
default:
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
if s, e := os.Stat(name); e == nil {
|
||||
m.Push("pod", m.Option(ice.MSG_USERPOD))
|
||||
m.Push("engine", "dir")
|
||||
m.Push("favor", "file")
|
||||
m.Push("id", kit.FmtSize(s.Size()))
|
||||
m.Push("score", score)
|
||||
m.Push("type", strings.TrimPrefix(path.Ext(name), "."))
|
||||
m.Push("name", path.Base(name))
|
||||
m.Push("text", name)
|
||||
}
|
||||
})
|
||||
}}))
|
||||
}},
|
||||
},
|
||||
}, nil)
|
||||
}
|
464
base/nfs/nfs.go
464
base/nfs/nfs.go
@ -2,457 +2,25 @@ package nfs
|
||||
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"bufio"
|
||||
"bytes"
|
||||
"crypto/sha1"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func _file_ext(name string) string {
|
||||
return strings.ToLower(kit.Select(path.Base(name), strings.TrimPrefix(path.Ext(name), ".")))
|
||||
}
|
||||
var Index = &ice.Context{Name: "nfs", Help: "存储模块", Commands: map[string]*ice.Command{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Load()
|
||||
m.Cmd(mdb.RENDER, mdb.CREATE, CAT)
|
||||
m.Cmd(mdb.SEARCH, mdb.CREATE, DIR)
|
||||
m.Cmd(mdb.RENDER, mdb.CREATE, DIR)
|
||||
|
||||
func _file_list(m *ice.Message, root string, name string, level int, deep bool, dir_type string, dir_reg *regexp.Regexp, fields []string) {
|
||||
switch strings.Split(name, "/")[0] {
|
||||
case "etc", "var":
|
||||
if m.Option(ice.MSG_USERROLE) == "void" {
|
||||
return // 保护目录
|
||||
}
|
||||
}
|
||||
m.Richs(TAIL, "", kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||
value, _ = kit.GetMeta(value), m.Option(kit.MDB_HASH, key)
|
||||
m.Cmd(TAIL, mdb.CREATE, kit.MDB_FILE, kit.Format(value[kit.MDB_FILE]), kit.MDB_NAME, kit.Format(value[kit.MDB_NAME]))
|
||||
})
|
||||
}},
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Save()
|
||||
}},
|
||||
}}
|
||||
|
||||
fs, e := ioutil.ReadDir(path.Join(root, name))
|
||||
if e != nil {
|
||||
ls, _ := ioutil.ReadDir(path.Dir(path.Join(root, name)))
|
||||
for _, k := range ls {
|
||||
if k.Name() == path.Base(name) {
|
||||
fs = append(fs, k)
|
||||
}
|
||||
}
|
||||
name = path.Dir(name)
|
||||
}
|
||||
|
||||
for _, f := range fs {
|
||||
if f.Name() == "." || f.Name() == ".." {
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(f.Name(), ".") && dir_type != TYPE_ALL {
|
||||
continue
|
||||
}
|
||||
|
||||
p := path.Join(root, name, f.Name())
|
||||
|
||||
if !(dir_type == TYPE_FILE && f.IsDir() || dir_type == TYPE_DIR && !f.IsDir()) && (dir_reg == nil || dir_reg.MatchString(f.Name())) {
|
||||
for _, field := range fields {
|
||||
switch field {
|
||||
case "time":
|
||||
m.Push("time", f.ModTime().Format(ice.MOD_TIME))
|
||||
case "type":
|
||||
if m.Assert(e) && f.IsDir() {
|
||||
m.Push("type", DIR)
|
||||
} else {
|
||||
m.Push("type", FILE)
|
||||
}
|
||||
case "tree":
|
||||
if level == 0 {
|
||||
m.Push("tree", f.Name())
|
||||
} else {
|
||||
m.Push("tree", strings.Repeat("| ", level-1)+"|-"+f.Name())
|
||||
}
|
||||
case "full":
|
||||
if f.IsDir() {
|
||||
m.Push("full", path.Join(root, name, f.Name())+"/")
|
||||
} else {
|
||||
m.Push("full", path.Join(root, name, f.Name()))
|
||||
}
|
||||
case "path":
|
||||
if f.IsDir() {
|
||||
m.Push("path", path.Join(name, f.Name())+"/")
|
||||
} else {
|
||||
m.Push("path", path.Join(name, f.Name()))
|
||||
}
|
||||
case "file":
|
||||
if f.IsDir() {
|
||||
m.Push("file", f.Name()+"/")
|
||||
} else {
|
||||
m.Push("file", f.Name())
|
||||
}
|
||||
case "name":
|
||||
m.Push("name", f.Name())
|
||||
case "link":
|
||||
if f.IsDir() {
|
||||
m.Push("link", "")
|
||||
} else {
|
||||
m.PushDownload(f.Name(), path.Join(root, name, f.Name()))
|
||||
}
|
||||
|
||||
case "size":
|
||||
if f.IsDir() {
|
||||
if ls, e := ioutil.ReadDir(path.Join(root, name, f.Name())); e == nil {
|
||||
m.Push("size", len(ls))
|
||||
} else {
|
||||
m.Push("size", 0)
|
||||
}
|
||||
} else {
|
||||
m.Push("size", kit.FmtSize(f.Size()))
|
||||
}
|
||||
case "line":
|
||||
if f.IsDir() {
|
||||
if ls, e := ioutil.ReadDir(path.Join(root, name, f.Name())); e == nil {
|
||||
m.Push("size", len(ls))
|
||||
} else {
|
||||
m.Push("size", 0)
|
||||
}
|
||||
} else {
|
||||
nline := 0
|
||||
if f, e := os.Open(p); m.Assert(e) {
|
||||
defer f.Close()
|
||||
for bio := bufio.NewScanner(f); bio.Scan(); nline++ {
|
||||
bio.Text()
|
||||
}
|
||||
}
|
||||
m.Push("line", nline)
|
||||
}
|
||||
case "hash", "hashs":
|
||||
var h [20]byte
|
||||
if f.IsDir() {
|
||||
if d, e := ioutil.ReadDir(p); m.Assert(e) {
|
||||
meta := []string{}
|
||||
for _, v := range d {
|
||||
meta = append(meta, fmt.Sprintf("%s%d%s", v.Name(), v.Size(), v.ModTime()))
|
||||
}
|
||||
sort.Strings(meta)
|
||||
h = sha1.Sum([]byte(strings.Join(meta, "")))
|
||||
}
|
||||
} else {
|
||||
if f, e := ioutil.ReadFile(path.Join(name, f.Name())); m.Assert(e) {
|
||||
h = sha1.Sum(f)
|
||||
}
|
||||
}
|
||||
if field == "hash" {
|
||||
m.Push("hash", hex.EncodeToString(h[:]))
|
||||
} else {
|
||||
m.Push("hash", hex.EncodeToString(h[:6]))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if f.IsDir() && deep {
|
||||
_file_list(m, root, path.Join(name, f.Name()), level+1, deep, dir_type, dir_reg, fields)
|
||||
}
|
||||
}
|
||||
}
|
||||
func _file_show(m *ice.Message, name string) {
|
||||
if f, e := os.Open(path.Join(m.Option(DIR_ROOT), name)); e == nil {
|
||||
defer f.Close()
|
||||
|
||||
switch cb := m.Optionv(CAT_CB).(type) {
|
||||
case func(string, int):
|
||||
bio := bufio.NewScanner(f)
|
||||
for i := 0; bio.Scan(); i++ {
|
||||
cb(bio.Text(), i)
|
||||
}
|
||||
|
||||
default:
|
||||
if s, e := f.Stat(); m.Assert(e) {
|
||||
buf := make([]byte, s.Size())
|
||||
if n, e := f.Read(buf); m.Assert(e) {
|
||||
m.Log_IMPORT(kit.MDB_FILE, name, kit.MDB_SIZE, n)
|
||||
m.Echo(string(buf[:n]))
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if b, ok := ice.BinPack["/"+name]; ok {
|
||||
m.Info("binpack %v %v", len(b), name)
|
||||
m.Echo(string(b))
|
||||
return // 打包文件
|
||||
}
|
||||
|
||||
// 远程文件
|
||||
switch cb := m.Optionv(CAT_CB).(type) {
|
||||
case func(string, int):
|
||||
bio := bufio.NewScanner(bytes.NewBufferString(m.Cmdx("web.spide", "dev", "raw", "GET", path.Join("/share/local/", name))))
|
||||
for i := 0; bio.Scan(); i++ {
|
||||
cb(bio.Text(), i)
|
||||
}
|
||||
default:
|
||||
m.Cmdy("web.spide", "dev", "raw", "GET", path.Join("/share/local/", name))
|
||||
}
|
||||
}
|
||||
func _file_save(m *ice.Message, name string, text ...string) {
|
||||
if f, p, e := kit.Create(path.Join(m.Option(DIR_ROOT), name)); m.Assert(e) {
|
||||
defer f.Close()
|
||||
|
||||
for _, v := range text {
|
||||
if n, e := f.WriteString(v); m.Assert(e) {
|
||||
m.Log_EXPORT(kit.MDB_FILE, p, kit.MDB_SIZE, n)
|
||||
}
|
||||
}
|
||||
m.Echo(p)
|
||||
}
|
||||
}
|
||||
func _file_copy(m *ice.Message, name string, from ...string) {
|
||||
if f, p, e := kit.Create(name); m.Assert(e) {
|
||||
defer f.Close()
|
||||
|
||||
for _, v := range from {
|
||||
if s, e := os.Open(v); !m.Warn(e != nil, e) {
|
||||
defer s.Close()
|
||||
|
||||
if n, e := io.Copy(f, s); !m.Warn(e != nil, e) {
|
||||
m.Log_EXPORT(kit.MDB_FILE, p, kit.MDB_SIZE, n)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
func _file_link(m *ice.Message, name string, from string) {
|
||||
if from == "" {
|
||||
return
|
||||
}
|
||||
os.Remove(name)
|
||||
os.MkdirAll(path.Dir(name), 0750)
|
||||
os.Link(from, name)
|
||||
m.Echo(name)
|
||||
}
|
||||
func _file_trash(m *ice.Message, name string) {
|
||||
if s, e := os.Stat(name); e == nil {
|
||||
if s.IsDir() {
|
||||
tar := path.Base(name) + ".tar.gz"
|
||||
m.Cmd(cli.SYSTEM, "tar", "zcf", tar, name)
|
||||
name = tar
|
||||
}
|
||||
|
||||
if f, e := os.Open(name); m.Assert(e) {
|
||||
defer f.Close()
|
||||
|
||||
h := kit.Hashs(f)
|
||||
p := path.Join(m.Conf(TRASH, "meta.path"), h[:2], h)
|
||||
os.MkdirAll(path.Dir(p), 0777)
|
||||
os.Rename(name, p)
|
||||
m.Cmdy("mdb.insert", m.Prefix(TRASH), "", "list", "file", p, "from", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
func _file_search(m *ice.Message, kind, name, text string, arg ...string) {
|
||||
if kind == kit.MDB_FOREACH {
|
||||
return
|
||||
}
|
||||
rg, e := regexp.Compile("")
|
||||
m.Assert(e)
|
||||
|
||||
msg := m.Spawn()
|
||||
_file_list(msg, "./", "", 0, true, TYPE_ALL, rg, []string{"time", "size", "type", "path"})
|
||||
|
||||
msg.Table(func(index int, value map[string]string, head []string) {
|
||||
if !strings.Contains(value["path"], name) {
|
||||
return
|
||||
}
|
||||
|
||||
ext := _file_ext(value["path"])
|
||||
if value["type"] == DIR {
|
||||
ext = DIR
|
||||
} else if m.Richs(mdb.RENDER, nil, ext, nil) == nil {
|
||||
ext = value["type"]
|
||||
}
|
||||
|
||||
m.PushSearch("cmd", FILE, "time", value["time"], "size", value["size"], "type", ext, "name", value["path"], "text", "")
|
||||
})
|
||||
}
|
||||
|
||||
const (
|
||||
OPEN = "open"
|
||||
CLOSE = "close"
|
||||
)
|
||||
const (
|
||||
CAT_CB = "cat_cb"
|
||||
CAT = "cat"
|
||||
SAVE = "save"
|
||||
COPY = "copy"
|
||||
LINK = "link"
|
||||
TAIL = "tail"
|
||||
)
|
||||
const (
|
||||
DIR_ROOT = "dir_root"
|
||||
DIR_TYPE = "dir_type"
|
||||
DIR_DEEP = "dir_deep"
|
||||
DIR_REG = "dir_reg"
|
||||
)
|
||||
const (
|
||||
TYPE_ALL = "all"
|
||||
TYPE_BOTH = "both"
|
||||
TYPE_FILE = "file"
|
||||
TYPE_DIR = "dir"
|
||||
)
|
||||
|
||||
const TRASH = "trash"
|
||||
const FILE = "file"
|
||||
const DIR = "dir"
|
||||
|
||||
var Index = &ice.Context{Name: "nfs", Help: "存储模块",
|
||||
Configs: map[string]*ice.Config{
|
||||
DIR: {Name: DIR, Help: "目录", Value: kit.Data()},
|
||||
FILE: {Name: FILE, Help: "文件", Value: kit.Data(
|
||||
"source", kit.Dict(
|
||||
"sh", "true", "shy", "true", "py", "true",
|
||||
"go", "true", "vim", "true", "js", "true",
|
||||
"conf", "true", "json", "true",
|
||||
"makefile", "true",
|
||||
),
|
||||
)},
|
||||
TRASH: {Name: TRASH, Help: "删除", Value: kit.Data("path", "var/trash")},
|
||||
|
||||
TAIL: {Name: TAIL, Help: "跟踪", Value: kit.Data()},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Load()
|
||||
m.Cmd(mdb.SEARCH, mdb.CREATE, DIR)
|
||||
m.Cmd(mdb.RENDER, mdb.CREATE, DIR)
|
||||
|
||||
m.Cmd(mdb.SEARCH, mdb.CREATE, FILE, m.Prefix(FILE))
|
||||
m.Cmd(mdb.RENDER, mdb.CREATE, FILE, m.Prefix(FILE))
|
||||
m.Richs(TAIL, "", kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||
value = kit.GetMeta(value)
|
||||
m.Option(kit.MDB_HASH, key)
|
||||
m.Cmd(TAIL, mdb.CREATE,
|
||||
kit.MDB_FILE, kit.Format(value[kit.MDB_FILE]),
|
||||
kit.MDB_NAME, kit.Format(value[kit.MDB_NAME]),
|
||||
)
|
||||
})
|
||||
}},
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Save()
|
||||
}},
|
||||
DIR: {Name: "dir path field... auto upload", Help: "目录", Action: map[string]*ice.Action{
|
||||
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
_file_search(m, arg[0], arg[1], arg[2], arg[3:]...)
|
||||
}},
|
||||
mdb.RENDER: {Name: "render type name text", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
|
||||
_file_list(m, arg[2], arg[1], 0, m.Option(DIR_DEEP) == "true", kit.Select(TYPE_BOTH, m.Option(DIR_TYPE)),
|
||||
nil, []string{"time", "size", "type", "path"})
|
||||
}},
|
||||
|
||||
"upload": {Name: "upload", Help: "上传", Hand: func(m *ice.Message, arg ...string) {
|
||||
up := kit.Simple(m.Optionv(ice.MSG_UPLOAD))
|
||||
|
||||
if p := path.Join(m.Option("path"), up[1]); m.Option(ice.MSG_USERPOD) == "" {
|
||||
m.Cmdy("cache", "watch", up[0], p)
|
||||
} else {
|
||||
m.Cmdy("spide", "dev", "save", p, "GET", kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/share/cache/"+up[0]))
|
||||
}
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
arg = append(arg, "")
|
||||
}
|
||||
reg, _ := regexp.Compile(m.Option(DIR_REG))
|
||||
_file_list(m, kit.Select("./", m.Option(DIR_ROOT)), arg[0],
|
||||
0, m.Options(DIR_DEEP), kit.Select(TYPE_BOTH, m.Option(DIR_TYPE)), reg,
|
||||
kit.Split(kit.Select("time size path", strings.Join(arg[1:], " "))))
|
||||
m.SortTimeR(kit.MDB_TIME)
|
||||
}},
|
||||
FILE: {Name: "file path auto", Help: "文件", Action: map[string]*ice.Action{
|
||||
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
_file_search(m, arg[0], arg[1], arg[2], arg[3:]...)
|
||||
}},
|
||||
mdb.RENDER: {Name: "render type name text", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
|
||||
_file_show(m, path.Join(arg[2], arg[1]))
|
||||
}},
|
||||
|
||||
"append": {Name: "append", Help: "追加", Hand: func(m *ice.Message, arg ...string) {
|
||||
if strings.Contains(arg[0], "/") {
|
||||
os.MkdirAll(path.Dir(arg[0]), ice.MOD_DIR)
|
||||
}
|
||||
|
||||
if f, e := os.OpenFile(arg[0], os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0664); m.Assert(e) {
|
||||
defer f.Close()
|
||||
|
||||
for _, k := range arg[1:] {
|
||||
if n, e := f.WriteString(k); m.Assert(e) {
|
||||
m.Log_EXPORT(kit.MDB_FILE, arg[0], kit.MDB_SIZE, n)
|
||||
}
|
||||
}
|
||||
}
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 0 || strings.HasSuffix(arg[0], "/") {
|
||||
m.Cmdy(DIR, arg)
|
||||
return
|
||||
}
|
||||
_file_show(m, arg[0])
|
||||
}},
|
||||
|
||||
CAT: {Name: "cat file", Help: "查看", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
_file_show(m, arg[0])
|
||||
}},
|
||||
SAVE: {Name: "save file text...", Help: "保存", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 1 {
|
||||
arg = append(arg, m.Option("content"))
|
||||
}
|
||||
_file_save(m, arg[0], arg[1:]...)
|
||||
}},
|
||||
COPY: {Name: "copy file from...", Help: "复制", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
_file_copy(m, arg[0], arg[1:]...)
|
||||
}},
|
||||
LINK: {Name: "link file from", Help: "链接", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
_file_link(m, arg[0], arg[1])
|
||||
}},
|
||||
TRASH: {Name: "trash file", Help: "删除", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
_file_trash(m, arg[0])
|
||||
}},
|
||||
|
||||
TAIL: {Name: "tail hash id auto create", Help: "文件", Action: map[string]*ice.Action{
|
||||
mdb.CREATE: {Name: "create file name", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(kit.MDB_HASH) == "" {
|
||||
m.Cmdy(mdb.INSERT, TAIL, "", mdb.HASH, arg)
|
||||
m.Option(kit.MDB_HASH, m.Result())
|
||||
}
|
||||
h := m.Option(kit.MDB_HASH)
|
||||
for _, file := range kit.Split(m.Option(kit.MDB_FILE), ",") {
|
||||
func(file string) {
|
||||
r, w := io.Pipe()
|
||||
m.Go(func() {
|
||||
for bio := bufio.NewScanner(r); bio.Scan(); {
|
||||
m.Grow(TAIL, kit.Keys(kit.MDB_HASH, h), kit.Dict(
|
||||
kit.MDB_FILE, file, kit.MDB_TEXT, bio.Text(),
|
||||
))
|
||||
}
|
||||
})
|
||||
m.Option(cli.CMD_STDOUT, w)
|
||||
m.Option(cli.CMD_STDERR, w)
|
||||
m.Option(mdb.CACHE_CLEAR_ON_EXIT, "true")
|
||||
m.Cmd(cli.DAEMON, "tail", "-n", "0", "-f", file)
|
||||
}(file)
|
||||
}
|
||||
}},
|
||||
mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(mdb.DELETE, TAIL, "", mdb.HASH, kit.MDB_HASH, m.Option(kit.MDB_HASH))
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Option(mdb.FIELDS, kit.Select("time,hash,count,name,file", kit.Select("time,id,file,text", mdb.DETAIL, len(arg) > 1), len(arg) > 0))
|
||||
m.Cmdy(mdb.SELECT, TAIL, "", mdb.ZONE, arg)
|
||||
m.PushAction(kit.Select("", mdb.REMOVE, len(arg) == 0))
|
||||
if len(arg) == 1 {
|
||||
m.Option(ice.MSG_CONTROL, "_page")
|
||||
}
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
||||
func init() { ice.Index.Register(Index, nil, DIR, CAT, SAVE, COPY, LINK, TRASH, TAIL) }
|
||||
func init() { ice.Index.Register(Index, nil, CAT, DIR, TAIL, TRASH, SAVE, PUSH, COPY, LINK, DEFS) }
|
||||
|
@ -1,6 +1,7 @@
|
||||
chapter "nfs"
|
||||
|
||||
field "文件" nfs.cat
|
||||
field "目录" nfs.dir
|
||||
field "文件" nfs.file
|
||||
field "日志" nfs.tail
|
||||
field "跟踪" nfs.tail
|
||||
field "删除" nfs.trash
|
||||
|
||||
|
@ -241,7 +241,7 @@ func (f *Frame) scan(m *ice.Message, h, line string, r io.Reader) *Frame {
|
||||
|
||||
m.I, m.O = r, f.stdout
|
||||
bio := bufio.NewScanner(r)
|
||||
m.Sleep("3s")
|
||||
m.Sleep("300ms")
|
||||
for f.prompt(m, ps...); bio.Scan() && !f.exit; f.prompt(m, ps...) {
|
||||
if h == STDIO && len(bio.Text()) == 0 {
|
||||
continue // 空行
|
||||
|
@ -33,7 +33,7 @@ func _dream_show(m *ice.Message, name string) {
|
||||
if !strings.Contains(name, "-") || !strings.HasPrefix(name, "20") {
|
||||
name = m.Time("20060102-") + strings.ReplaceAll(name, "-", "_")
|
||||
}
|
||||
m.Option("name", name)
|
||||
m.Option(kit.MDB_NAME, name)
|
||||
|
||||
// 任务目录
|
||||
p := path.Join(m.Conf(DREAM, kit.META_PATH), name)
|
||||
@ -44,11 +44,11 @@ func _dream_show(m *ice.Message, name string) {
|
||||
}
|
||||
|
||||
// 任务模板
|
||||
if m.Option("template") != "" {
|
||||
for _, file := range []string{"etc/miss.sh", "src/main.shy", "src/main.go", "go.mod", "Makefile"} {
|
||||
if m.Option(kit.MDB_TEMPLATE) != "" {
|
||||
for _, file := range []string{ice.ETC_MISS, ice.SRC_MAIN, ice.SRC_MAIN_GO, ice.GO_MOD, ice.MAKEFILE} {
|
||||
if _, e := os.Stat(path.Join(p, file)); os.IsNotExist(e) {
|
||||
switch m.Cmdy(nfs.COPY, path.Join(p, file), path.Join(m.Option("template"), file)); file {
|
||||
case "go.mod":
|
||||
switch m.Cmdy(nfs.COPY, path.Join(p, file), path.Join(m.Option(kit.MDB_TEMPLATE), file)); file {
|
||||
case ice.GO_MOD:
|
||||
kit.Rewrite(path.Join(p, file), func(line string) string {
|
||||
return kit.Select(line, "module "+name, strings.HasPrefix(line, "module"))
|
||||
})
|
||||
@ -58,12 +58,12 @@ func _dream_show(m *ice.Message, name string) {
|
||||
}
|
||||
|
||||
// 任务脚本
|
||||
miss := path.Join(p, "etc/miss.sh")
|
||||
miss := path.Join(p, ice.ETC_MISS)
|
||||
if _, e := os.Stat(miss); os.IsNotExist(e) {
|
||||
m.Cmd(nfs.SAVE, miss, m.Conf(DREAM, "meta.miss"))
|
||||
m.Cmd(nfs.SAVE, miss, m.Conf(DREAM, kit.Keym("miss")))
|
||||
}
|
||||
|
||||
if b, e := ioutil.ReadFile(path.Join(p, m.Conf(gdb.SIGNAL, "meta.pid"))); e == nil {
|
||||
if b, e := ioutil.ReadFile(path.Join(p, m.Conf(gdb.SIGNAL, kit.Keym(kit.SSH_PID)))); e == nil {
|
||||
if s, e := os.Stat("/proc/" + string(b)); e == nil && s.IsDir() {
|
||||
m.Info("already exists %v", string(b))
|
||||
return // 已经启动
|
||||
@ -75,14 +75,14 @@ func _dream_show(m *ice.Message, name string) {
|
||||
m.Optionv(cli.CMD_ENV, kit.Simple(
|
||||
// "ctx_dev", m.Conf(cli.RUNTIME, "conf.ctx_dev"),
|
||||
"ctx_dev", "http://:"+m.Cmd(SERVE).Append(tcp.PORT),
|
||||
"PATH", kit.Path(path.Join(p, "bin"))+":"+kit.Path("bin")+":"+os.Getenv("PATH"),
|
||||
"USER", ice.Info.UserName, m.Confv(DREAM, "meta.env"),
|
||||
"PATH", kit.Path(path.Join(p, kit.SSH_BIN))+":"+kit.Path(kit.SSH_BIN)+":"+os.Getenv("PATH"),
|
||||
"USER", ice.Info.UserName, m.Confv(DREAM, kit.Keym(kit.SSH_ENV)),
|
||||
))
|
||||
// 启动任务
|
||||
kit.Path(os.Args[0])
|
||||
|
||||
m.Optionv(cli.CMD_STDERR, path.Join(p, m.Conf(DREAM, "meta.env.ctx_log")))
|
||||
m.Cmd(cli.DAEMON, m.Confv(DREAM, "meta.cmd"), SPIDE_DEV, SPIDE_DEV, kit.MDB_NAME, name)
|
||||
m.Optionv(cli.CMD_STDERR, path.Join(p, m.Conf(DREAM, kit.Keym(kit.SSH_ENV, "ctx_log"))))
|
||||
m.Cmd(cli.DAEMON, m.Confv(DREAM, kit.Keym(kit.SSH_CMD)), SPIDE_DEV, SPIDE_DEV, kit.MDB_NAME, name)
|
||||
m.Event(DREAM_CREATE, kit.MDB_TYPE, m.Option(kit.MDB_TYPE), kit.MDB_NAME, name)
|
||||
m.Sleep(ice.MOD_TICK)
|
||||
}
|
||||
@ -104,7 +104,7 @@ func init() {
|
||||
switch arg[0] {
|
||||
case kit.MDB_NAME:
|
||||
m.Cmdy(nfs.DIR, m.Conf(DREAM, kit.META_PATH), "name,time")
|
||||
case kit.SSH_TEMPLATE:
|
||||
case kit.MDB_TEMPLATE:
|
||||
m.Cmdy(nfs.DIR, m.Conf(DREAM, kit.META_PATH), "path,size,time")
|
||||
m.SortStrR(kit.MDB_PATH)
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ func init() {
|
||||
m.Cmdy(nfs.DIR, m.Conf(DREAM, kit.META_PATH), "name,size,time")
|
||||
m.SortStrR(kit.MDB_PATH)
|
||||
|
||||
case kit.SSH_TEMPLATE:
|
||||
case kit.MDB_TEMPLATE:
|
||||
m.Cmdy(nfs.DIR, m.Conf(DREAM, kit.META_PATH), "path,size,time")
|
||||
m.SortStrR(kit.MDB_PATH)
|
||||
}
|
||||
|
@ -70,10 +70,11 @@ const (
|
||||
|
||||
ContentType = "Content-Type"
|
||||
ContentLength = "Content-Length"
|
||||
ContentFORM = "application/x-www-form-urlencoded"
|
||||
ContentJSON = "application/json"
|
||||
ContentHTML = "text/html"
|
||||
ContentPNG = "image/png"
|
||||
|
||||
ContentFORM = "application/x-www-form-urlencoded"
|
||||
ContentJSON = "application/json"
|
||||
ContentHTML = "text/html"
|
||||
ContentPNG = "image/png"
|
||||
)
|
||||
const (
|
||||
ADDRESS = "address"
|
||||
|
23
conf.go
23
conf.go
@ -1,6 +1,6 @@
|
||||
package ice
|
||||
|
||||
const ( //MOD
|
||||
const ( // MOD
|
||||
MOD_DIR = 0750
|
||||
MOD_FILE = 0640
|
||||
|
||||
@ -11,6 +11,26 @@ const ( //MOD
|
||||
MOD_DATE = "2006-01-02"
|
||||
MOD_TIME = "2006-01-02 15:04:05"
|
||||
)
|
||||
const ( // REPOS
|
||||
VOLCANOS = "volcanos"
|
||||
ICEBERGS = "icebergs"
|
||||
CONTEXTS = "contexts"
|
||||
INTSHELL = "intshell"
|
||||
)
|
||||
const ( // DIR
|
||||
ETC_MISS = "etc/miss.sh"
|
||||
ETC_INIT = "etc/init.shy"
|
||||
ETC_EXIT = "etc/exit.shy"
|
||||
SRC_MAIN = "src/main.shy"
|
||||
SRC_MAIN_GO = "src/main.go"
|
||||
BIN_ICE_BIN = "bin/ice.bin"
|
||||
BIN_ICE = "bin/ice.sh"
|
||||
MAKEFILE = "makefile"
|
||||
ORDER_SH = "order.sh"
|
||||
ORDER_JS = "order.js"
|
||||
GO_MOD = "go.mod"
|
||||
GO_SUM = "go.sum"
|
||||
)
|
||||
const ( // MSG
|
||||
MSG_DETAIL = "detail"
|
||||
MSG_OPTION = "option"
|
||||
@ -67,6 +87,7 @@ const ( // PROCESS
|
||||
PROCESS_FOLLOW = "_follow"
|
||||
PROCESS_INNER = "_inner"
|
||||
PROCESS_FIELD = "_field"
|
||||
PROCESS_OPEN = "_open"
|
||||
|
||||
FIELD_PREFIX = "_prefix"
|
||||
CONTROL_PAGE = "_page"
|
||||
|
@ -28,7 +28,7 @@ func init() {
|
||||
m.Cmd(mdb.SELECT, cmd, "", mdb.HASH, kit.MDB_HASH, arg).Table(func(index int, value map[string]string, head []string) {
|
||||
m.Push("", value, kit.Split(kit.Select("time,size,type,name", "time,size,type,name", len(arg) > 0)))
|
||||
|
||||
if m.PushDownload(value[kit.MDB_NAME], "/share/cache/"+value[kit.MDB_DATA]); len(arg) > 0 {
|
||||
if m.PushDownload(kit.MDB_LINK, value[kit.MDB_NAME], "/share/cache/"+value[kit.MDB_DATA]); len(arg) > 0 {
|
||||
switch {
|
||||
case kit.ExtIsImage(value[kit.MDB_NAME]):
|
||||
m.PushImages(kit.MDB_IMAGE, "/share/cache/"+value[kit.MDB_DATA])
|
||||
|
@ -14,15 +14,61 @@ import (
|
||||
)
|
||||
|
||||
func _autogen_script(m *ice.Message, dir string) {
|
||||
if b, e := kit.Render(m.Conf(AUTOGEN, "meta.shy"), m); m.Assert(e) {
|
||||
if b, e := kit.Render(m.Conf(AUTOGEN, kit.Keym(SHY)), m); m.Assert(e) {
|
||||
m.Cmd(nfs.SAVE, dir, string(b))
|
||||
}
|
||||
}
|
||||
func _autogen_source(m *ice.Message, name string) {
|
||||
m.Cmd("nfs.file", "append", "src/main.shy", "\n", `source `+name+"/"+name+".shy", "\n")
|
||||
m.Cmd(nfs.PUSH, path.Join(kit.SSH_SRC, kit.Keys(kit.MDB_MAIN, SHY)),
|
||||
"\n", kit.SSH_SOURCE+` `+path.Join(name, kit.Keys(name, SHY)), "\n")
|
||||
}
|
||||
func _autogen_module(m *ice.Message, dir string, ctx string, from string) (list []string) {
|
||||
name, value := "", ""
|
||||
key := strings.ToUpper(ctx)
|
||||
m.Cmd(nfs.CAT, from, func(line string, index int) {
|
||||
if strings.HasPrefix(line, "package") {
|
||||
line = "package " + ctx
|
||||
}
|
||||
|
||||
if name == "" && strings.HasPrefix(line, "const") {
|
||||
if ls := kit.Split(line); len(ls) > 3 {
|
||||
name, value = ls[1], ls[3]
|
||||
}
|
||||
}
|
||||
if name != "" {
|
||||
line = strings.ReplaceAll(line, name, key)
|
||||
line = strings.ReplaceAll(line, value, ctx)
|
||||
}
|
||||
|
||||
list = append(list, line)
|
||||
})
|
||||
|
||||
m.Cmd(nfs.SAVE, dir, strings.Join(list, "\n"))
|
||||
return
|
||||
}
|
||||
func _autogen_import(m *ice.Message, main string, ctx string, mod string) (list []string) {
|
||||
m.Cmd(nfs.CAT, main, func(line string, index int) {
|
||||
if list = append(list, line); strings.HasPrefix(line, "import (") {
|
||||
list = append(list, kit.Format(` _ "%s/src/%s"`, mod, ctx), "")
|
||||
}
|
||||
})
|
||||
|
||||
m.Cmd(nfs.SAVE, main, strings.Join(list, "\n"))
|
||||
return
|
||||
}
|
||||
func _autogen_mod(m *ice.Message, file string) (mod string) {
|
||||
m.Cmd(nfs.CAT, file, func(line string, index int) {
|
||||
if strings.HasPrefix(line, "module") {
|
||||
mod = strings.Split(line, " ")[1]
|
||||
m.Logs("module", mod)
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func _autogen_version(m *ice.Message) {
|
||||
m.Cmdy(nfs.SAVE, "src/version.go", kit.Format(`package main
|
||||
file := "src/version.go"
|
||||
m.Cmd(nfs.SAVE, file, kit.Format(`package main
|
||||
|
||||
import (
|
||||
"github.com/shylinux/icebergs"
|
||||
@ -45,52 +91,17 @@ func init() {
|
||||
strings.TrimSpace(m.Cmdx(cli.SYSTEM, "git", "describe", "--tags")),
|
||||
ice.Info.HostName, ice.Info.UserName,
|
||||
))
|
||||
m.Cmdy(nfs.DIR, "src/binpack.go", "time,size,line,path")
|
||||
m.Cmdy(nfs.DIR, file, "time,size,line,path")
|
||||
m.Cmdy(nfs.CAT, file)
|
||||
}
|
||||
func _autogen_index(m *ice.Message, dir string, from string, ctx string) {
|
||||
list := []string{}
|
||||
|
||||
up, low := "", ""
|
||||
key := strings.ToUpper(ctx)
|
||||
m.Option(nfs.CAT_CB, func(line string, index int) {
|
||||
if strings.HasPrefix(line, "package") {
|
||||
line = "package " + ctx
|
||||
}
|
||||
if up == "" && strings.HasPrefix(line, "const") {
|
||||
if ls := kit.Split(line); len(ls) > 3 {
|
||||
up, low = ls[1], ls[3]
|
||||
}
|
||||
}
|
||||
if up != "" {
|
||||
line = strings.ReplaceAll(line, up, key)
|
||||
line = strings.ReplaceAll(line, low, ctx)
|
||||
}
|
||||
|
||||
list = append(list, line)
|
||||
})
|
||||
m.Cmd(nfs.CAT, from)
|
||||
|
||||
m.Cmdy(nfs.SAVE, dir, strings.Join(list, "\n"))
|
||||
}
|
||||
func _autogen_main(m *ice.Message, file string, mod string, ctx string) {
|
||||
list := []string{}
|
||||
m.Option(nfs.CAT_CB, func(line string, index int) {
|
||||
if list = append(list, line); strings.HasPrefix(line, "import (") {
|
||||
list = append(list, kit.Format(` _ "%s/src/%s"`, mod, ctx), "")
|
||||
}
|
||||
})
|
||||
m.Cmd(nfs.CAT, file)
|
||||
|
||||
m.Cmd(nfs.SAVE, file, strings.Join(list, "\n"))
|
||||
}
|
||||
func _autogen_mod(m *ice.Message, file string) (mod string) {
|
||||
m.Option(nfs.CAT_CB, func(line string, index int) {
|
||||
if strings.HasPrefix(line, "module") {
|
||||
mod = strings.Split(line, " ")[1]
|
||||
m.Info("module %s", mod)
|
||||
}
|
||||
})
|
||||
m.Cmd(nfs.CAT, "go.mod")
|
||||
return
|
||||
func _autogen_miss(m *ice.Message) {
|
||||
file := "etc/miss.sh"
|
||||
if _, e := os.Stat(file); os.IsNotExist(e) {
|
||||
m.Cmd(nfs.SAVE, file, m.Conf(web.DREAM, kit.Keym("miss")))
|
||||
}
|
||||
m.Cmdy(nfs.DIR, file, "time,size,line,path")
|
||||
m.Cmdy(nfs.CAT, file)
|
||||
}
|
||||
|
||||
const AUTOGEN = "autogen"
|
||||
@ -100,46 +111,40 @@ func init() {
|
||||
Commands: map[string]*ice.Command{
|
||||
AUTOGEN: {Name: "autogen path auto create binpack script", Help: "生成", Action: map[string]*ice.Action{
|
||||
mdb.CREATE: {Name: "create main=src/main.go@key name=hi@key from=usr/icebergs/misc/bash/bash.go@key", Help: "模块", Hand: func(m *ice.Message, arg ...string) {
|
||||
if p := path.Join("src", m.Option("name"), m.Option("name")+".shy"); !kit.FileExists(p) {
|
||||
if p := path.Join(kit.SSH_SRC, m.Option(kit.MDB_NAME), kit.Keys(m.Option(kit.MDB_NAME), SHY)); !kit.FileExists(p) {
|
||||
_autogen_script(m, p)
|
||||
_autogen_source(m, m.Option("name"))
|
||||
_autogen_source(m, m.Option(kit.MDB_NAME))
|
||||
}
|
||||
|
||||
if p := path.Join("src", m.Option("name"), m.Option("name")+".go"); !kit.FileExists(p) {
|
||||
_autogen_index(m, p, m.Option("from"), m.Option("name"))
|
||||
_autogen_main(m, m.Option("main"), _autogen_mod(m, "go.mod"), m.Option("name"))
|
||||
if p := path.Join(kit.SSH_SRC, m.Option(kit.MDB_NAME), kit.Keys(m.Option(kit.MDB_NAME), GO)); !kit.FileExists(p) {
|
||||
_autogen_module(m, p, m.Option(kit.MDB_NAME), m.Option(kit.MDB_FROM))
|
||||
_autogen_import(m, m.Option(kit.MDB_MAIN), m.Option(kit.MDB_NAME), _autogen_mod(m, "go.mod"))
|
||||
}
|
||||
m.Cmdy(cli.SYSTEM, "make")
|
||||
m.Option(ice.MSG_PROCESS, ice.PROCESS_INNER)
|
||||
}},
|
||||
BINPACK: {Name: "binpack", Help: "打包", Hand: func(m *ice.Message, arg ...string) {
|
||||
_autogen_version(m)
|
||||
m.Cmdy(BINPACK, mdb.CREATE)
|
||||
}},
|
||||
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
||||
switch arg[0] {
|
||||
case "main":
|
||||
m.Option(nfs.DIR_REG, ".*.go")
|
||||
m.Cmdy(nfs.DIR, "src", "path,size,time")
|
||||
m.RenameAppend("path", arg[0])
|
||||
case kit.MDB_MAIN:
|
||||
m.Option(nfs.DIR_REG, `.*\.go`)
|
||||
m.Cmdy(nfs.DIR, kit.SSH_SRC, "path,size,time")
|
||||
m.RenameAppend(kit.MDB_PATH, arg[0])
|
||||
|
||||
case "from":
|
||||
case kit.MDB_FROM:
|
||||
m.Option(nfs.DIR_DEEP, true)
|
||||
m.Option(nfs.DIR_REG, ".*.go")
|
||||
m.Cmdy(nfs.DIR, "src/", "path,size,time")
|
||||
m.Option(nfs.DIR_REG, `.*\.go`)
|
||||
m.Cmdy(nfs.DIR, kit.SSH_SRC, "path,size,time")
|
||||
m.Cmdy(nfs.DIR, "usr/icebergs/misc/", "path,size,time")
|
||||
m.RenameAppend("path", arg[0])
|
||||
m.RenameAppend(kit.MDB_PATH, arg[0])
|
||||
}
|
||||
}},
|
||||
BINPACK: {Name: "binpack", Help: "打包", Hand: func(m *ice.Message, arg ...string) {
|
||||
_autogen_version(m)
|
||||
m.Cmd(BINPACK, mdb.CREATE)
|
||||
}},
|
||||
mdb.SCRIPT: {Name: "script", Help: "脚本", Hand: func(m *ice.Message, arg ...string) {
|
||||
miss := "etc/miss.sh"
|
||||
if _, e := os.Stat(miss); os.IsNotExist(e) {
|
||||
m.Cmd(nfs.SAVE, miss, m.Conf(web.DREAM, "meta.miss"))
|
||||
}
|
||||
m.Echo(miss)
|
||||
_autogen_miss(m)
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if m.Option(nfs.DIR_ROOT, "src"); len(arg) == 0 || strings.HasSuffix(arg[0], "/") {
|
||||
if m.Option(nfs.DIR_ROOT, kit.SSH_SRC); len(arg) == 0 || strings.HasSuffix(arg[0], "/") {
|
||||
m.Cmdy(nfs.DIR, kit.Select("./", arg, 0))
|
||||
} else {
|
||||
m.Cmdy(nfs.CAT, arg[0])
|
||||
@ -148,8 +153,7 @@ func init() {
|
||||
},
|
||||
Configs: map[string]*ice.Config{
|
||||
AUTOGEN: {Name: AUTOGEN, Help: "生成", Value: kit.Data(
|
||||
"shy", `
|
||||
chapter "{{.Option "name"}}"
|
||||
SHY, `chapter "{{.Option "name"}}"
|
||||
field "{{.Option "name"}}" web.code.{{.Option "name"}}.{{.Option "name"}}
|
||||
`,
|
||||
)},
|
||||
|
@ -37,7 +37,7 @@ func _pack_file(m *ice.Message, file string) string {
|
||||
func _pack_dir(m *ice.Message, pack *os.File, dir string) {
|
||||
m.Option(nfs.DIR_ROOT, dir)
|
||||
m.Option(nfs.DIR_DEEP, "true")
|
||||
m.Option(nfs.DIR_TYPE, nfs.FILE)
|
||||
m.Option(nfs.DIR_TYPE, nfs.CAT)
|
||||
|
||||
m.Cmd(nfs.DIR, "./").Table(func(index int, value map[string]string, head []string) {
|
||||
switch strings.Split(value[kit.MDB_PATH], "/")[0] {
|
||||
@ -54,7 +54,7 @@ func _pack_dir(m *ice.Message, pack *os.File, dir string) {
|
||||
func _pack_volcanos(m *ice.Message, pack *os.File, dir string) {
|
||||
m.Option(nfs.DIR_ROOT, dir)
|
||||
m.Option(nfs.DIR_DEEP, "true")
|
||||
m.Option(nfs.DIR_TYPE, nfs.FILE)
|
||||
m.Option(nfs.DIR_TYPE, nfs.CAT)
|
||||
|
||||
for _, k := range []string{"favicon.ico", "proto.js", "frame.js", "index.html"} {
|
||||
pack.WriteString(fmt.Sprintf(" \"/%s\": %s,\n",
|
||||
|
@ -64,7 +64,7 @@ func init() {
|
||||
|
||||
m.Log_EXPORT("source", main, "target", file)
|
||||
m.Push(kit.MDB_TIME, m.Time())
|
||||
m.PushDownload(file)
|
||||
m.PushDownload(kit.MDB_LINK, file)
|
||||
m.Echo(file)
|
||||
}},
|
||||
},
|
||||
|
@ -91,7 +91,7 @@ func init() {
|
||||
|
||||
} else {
|
||||
m.Table(func(index int, value map[string]string, head []string) {
|
||||
m.PushDownload("pprof.pd.gz", value[kit.MDB_FILE])
|
||||
m.PushDownload(kit.MDB_LINK, "pprof.pd.gz", value[kit.MDB_FILE])
|
||||
m.PushButton(web.SERVE)
|
||||
})
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ import (
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
"github.com/shylinux/icebergs/base/nfs"
|
||||
"github.com/shylinux/icebergs/base/tcp"
|
||||
"github.com/shylinux/icebergs/base/web"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"fmt"
|
||||
@ -14,54 +16,68 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const PUBLISH = "publish"
|
||||
|
||||
func _publish_file(m *ice.Message, file string, arg ...string) string {
|
||||
if s, e := os.Stat(file); m.Assert(e) && s.IsDir() {
|
||||
if strings.HasSuffix(file, "ice.bin") {
|
||||
// 打包应用
|
||||
arg = append(arg, kit.Keys("ice", runtime.GOOS, runtime.GOARCH))
|
||||
if _, e := os.Stat(path.Join(m.Conf(PUBLISH, kit.META_PATH), kit.Select(path.Base(file), arg, 0))); e == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
} else if s, e := os.Stat(file); m.Assert(e) && s.IsDir() {
|
||||
// 打包目录
|
||||
p := path.Base(file) + ".tar.gz"
|
||||
m.Cmd(cli.SYSTEM, "tar", "-zcf", p, file)
|
||||
defer func() { os.Remove(p) }()
|
||||
file = p
|
||||
}
|
||||
if strings.HasSuffix(file, "ice.bin") {
|
||||
arg = append(arg, kit.Keys("ice", runtime.GOOS, runtime.GOARCH))
|
||||
}
|
||||
|
||||
// 发布文件
|
||||
target := path.Join(m.Conf(PUBLISH, kit.META_PATH), kit.Select(path.Base(file), arg, 0))
|
||||
m.Log_EXPORT(PUBLISH, target, kit.MDB_FROM, file)
|
||||
m.Cmd(nfs.LINK, target, file)
|
||||
|
||||
// 发布记录
|
||||
m.Log_EXPORT(PUBLISH, target, "from", file)
|
||||
return target
|
||||
}
|
||||
|
||||
const PUBLISH = "publish"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
PUBLISH: {Name: PUBLISH, Help: "发布", Value: kit.Data(
|
||||
kit.MDB_SHORT, kit.MDB_NAME, kit.MDB_PATH, "usr/publish", "contexts", _contexts,
|
||||
kit.MDB_PATH, "usr/publish", ice.CONTEXTS, _contexts,
|
||||
SH, `#!/bin/bash
|
||||
echo "hello world"
|
||||
`,
|
||||
JS, `Volcanos("onengine", {_init: function(can, sub) {
|
||||
can.base.Log("hello volcanos world")
|
||||
}, river: {
|
||||
|
||||
}})
|
||||
`,
|
||||
)},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
PUBLISH: {Name: "publish path auto create can ice ish", Help: "发布", Action: map[string]*ice.Action{
|
||||
PUBLISH: {Name: "publish path auto create dream volcanos icebergs intshell", Help: "发布", Action: map[string]*ice.Action{
|
||||
mdb.CREATE: {Name: "create file", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||
_publish_file(m, m.Option(kit.MDB_FILE))
|
||||
}},
|
||||
"can": {Name: "can", Help: "火山架", Hand: func(m *ice.Message, arg ...string) {
|
||||
defer func() { m.Cmdy(PUBLISH, "contexts", "miss") }()
|
||||
m.Cmd(PUBLISH, mdb.CREATE, kit.MDB_FILE, "etc/miss.sh")
|
||||
m.Cmd(PUBLISH, mdb.CREATE, kit.MDB_FILE, "go.mod")
|
||||
ice.VOLCANOS: {Name: "volcanos", Help: "火山架", Hand: func(m *ice.Message, arg ...string) {
|
||||
defer func() { m.EchoQRCode(m.Option(ice.MSG_USERWEB)) }()
|
||||
defer func() { m.Cmdy(PUBLISH, ice.CONTEXTS, "miss") }()
|
||||
m.Cmd(PUBLISH, mdb.CREATE, kit.MDB_FILE, ice.ETC_MISS)
|
||||
m.Cmd(PUBLISH, mdb.CREATE, kit.MDB_FILE, ice.GO_MOD)
|
||||
m.Cmd(nfs.DEFS, path.Join(m.Conf(PUBLISH, kit.META_PATH), ice.ORDER_JS), m.Conf(PUBLISH, kit.Keym(JS)))
|
||||
|
||||
m.Option(nfs.DIR_DEEP, true)
|
||||
m.Option(nfs.DIR_REG, `.*\.(html|css|js)$`)
|
||||
m.Option(nfs.DIR_ROOT, m.Conf(PUBLISH, kit.META_PATH))
|
||||
m.Cmdy(nfs.DIR, "./", "time,size,line,path,link")
|
||||
}},
|
||||
"ice": {Name: "ice", Help: "冰山架", Hand: func(m *ice.Message, arg ...string) {
|
||||
defer func() { m.Cmdy(PUBLISH, "contexts", "base") }()
|
||||
m.Cmd(PUBLISH, mdb.CREATE, kit.MDB_FILE, "bin/ice.sh")
|
||||
m.Cmd(PUBLISH, mdb.CREATE, kit.MDB_FILE, "bin/ice.bin")
|
||||
ice.ICEBERGS: {Name: "icebergs", Help: "冰山架", Hand: func(m *ice.Message, arg ...string) {
|
||||
defer func() { m.Cmdy(PUBLISH, ice.CONTEXTS, "base") }()
|
||||
m.Cmd(PUBLISH, mdb.CREATE, kit.MDB_FILE, ice.BIN_ICE_BIN)
|
||||
m.Cmd(PUBLISH, mdb.CREATE, kit.MDB_FILE, ice.BIN_ICE)
|
||||
|
||||
p := m.Option(cli.CMD_DIR, m.Conf(PUBLISH, kit.META_PATH))
|
||||
ls := strings.Split(strings.TrimSpace(m.Cmd(cli.SYSTEM, "bash", "-c", "ls |xargs file |grep executable").Append(cli.CMD_OUT)), "\n")
|
||||
@ -71,22 +87,22 @@ func init() {
|
||||
m.Push(kit.MDB_TIME, s.ModTime())
|
||||
m.Push(kit.MDB_SIZE, kit.FmtSize(s.Size()))
|
||||
m.Push(kit.MDB_FILE, file)
|
||||
m.PushDownload(file, path.Join(p, file))
|
||||
m.PushDownload(kit.MDB_LINK, file, path.Join(p, file))
|
||||
}
|
||||
}
|
||||
}
|
||||
m.SortTimeR(kit.MDB_TIME)
|
||||
}},
|
||||
"ish": {Name: "ish", Help: "神农架", Hand: func(m *ice.Message, arg ...string) {
|
||||
defer func() { m.Cmdy(PUBLISH, "contexts", "tmux") }()
|
||||
m.Cmd(PUBLISH, mdb.CREATE, kit.MDB_FILE, "etc/miss.sh")
|
||||
ice.INTSHELL: {Name: "intshell", Help: "神农架", Hand: func(m *ice.Message, arg ...string) {
|
||||
defer func() { m.Cmdy(PUBLISH, ice.CONTEXTS, "tmux") }()
|
||||
m.Cmd(nfs.DEFS, path.Join(m.Conf(PUBLISH, kit.META_PATH), ice.ORDER_SH), m.Conf(PUBLISH, kit.Keym(SH)))
|
||||
|
||||
m.Option(nfs.DIR_DEEP, true)
|
||||
m.Option(nfs.DIR_REG, ".*\\.(sh|vim|conf)$")
|
||||
m.Option(nfs.DIR_ROOT, m.Conf(PUBLISH, kit.META_PATH))
|
||||
m.Cmdy(nfs.DIR, "./", "time,size,line,path,link")
|
||||
}},
|
||||
"contexts": {Name: "contexts", Help: "环境", Hand: func(m *ice.Message, arg ...string) {
|
||||
ice.CONTEXTS: {Name: "contexts", Help: "环境", Hand: func(m *ice.Message, arg ...string) {
|
||||
u := kit.ParseURL(m.Option(ice.MSG_USERWEB))
|
||||
m.Option("httphost", fmt.Sprintf("%s://%s:%s", u.Scheme, strings.Split(u.Host, ":")[0], kit.Select(kit.Select("80", "443", u.Scheme == "https"), strings.Split(u.Host, ":"), 1)))
|
||||
m.Option("hostport", fmt.Sprintf("%s:%s", strings.Split(u.Host, ":")[0], kit.Select(kit.Select("80", "443", u.Scheme == "https"), strings.Split(u.Host, ":"), 1)))
|
||||
@ -99,18 +115,26 @@ func init() {
|
||||
arg = append(arg, "base")
|
||||
}
|
||||
for _, k := range arg {
|
||||
if buf, err := kit.Render(m.Conf(PUBLISH, kit.Keym("contexts", k)), m); m.Assert(err) {
|
||||
if buf, err := kit.Render(m.Conf(PUBLISH, kit.Keym(ice.CONTEXTS, k)), m); m.Assert(err) {
|
||||
m.EchoScript(strings.TrimSpace(string(buf)))
|
||||
}
|
||||
}
|
||||
}},
|
||||
web.DREAM: {Name: "dream name=hi repos", Help: "启动", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(web.DREAM, tcp.START, arg)
|
||||
m.Process(ice.PROCESS_OPEN, kit.MergeURL(m.Option(ice.MSG_USERWEB),
|
||||
kit.SSH_POD, kit.Keys(m.Option(ice.MSG_USERPOD), m.Option(kit.MDB_NAME))))
|
||||
}},
|
||||
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(web.DREAM, mdb.INPUTS, arg)
|
||||
}},
|
||||
mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
p := m.Option(cli.CMD_DIR, m.Conf(PUBLISH, kit.META_PATH))
|
||||
os.Remove(path.Join(p, m.Option(kit.MDB_PATH)))
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Option(nfs.DIR_ROOT, m.Conf(PUBLISH, kit.META_PATH))
|
||||
m.Cmdy(nfs.DIR, kit.Select("", arg, 0), "time size path link")
|
||||
m.Cmdy(nfs.DIR, kit.Select("", arg, 0), "time,size,path,link")
|
||||
m.PushAction(mdb.REMOVE)
|
||||
}},
|
||||
},
|
||||
|
@ -30,7 +30,7 @@ func init() {
|
||||
defer js.Close()
|
||||
|
||||
m.Option(nfs.DIR_ROOT, m.Conf(WEBPACK, kit.META_PATH))
|
||||
m.Option(nfs.DIR_TYPE, nfs.FILE)
|
||||
m.Option(nfs.DIR_TYPE, nfs.CAT)
|
||||
m.Option(nfs.DIR_DEEP, true)
|
||||
|
||||
for _, k := range []string{"lib", "pane", "plugin"} {
|
||||
@ -79,11 +79,11 @@ func init() {
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Option(nfs.DIR_ROOT, m.Conf(PUBLISH, kit.META_PATH))
|
||||
m.Option(nfs.DIR_TYPE, nfs.FILE)
|
||||
m.Option(nfs.DIR_TYPE, nfs.CAT)
|
||||
m.Option(nfs.DIR_DEEP, true)
|
||||
|
||||
m.Cmdy(nfs.DIR, WEBPACK).Table(func(index int, value map[string]string, head []string) {
|
||||
m.PushDownload(path.Join(m.Option(nfs.DIR_ROOT), value[kit.MDB_PATH]))
|
||||
m.PushDownload(kit.MDB_LINK, path.Join(m.Option(nfs.DIR_ROOT), value[kit.MDB_PATH]))
|
||||
})
|
||||
}},
|
||||
},
|
||||
|
@ -24,7 +24,7 @@ func _wiki_list(m *ice.Message, cmd string, arg ...string) bool {
|
||||
}
|
||||
|
||||
// 文件列表
|
||||
m.Option(nfs.DIR_TYPE, nfs.FILE)
|
||||
m.Option(nfs.DIR_TYPE, nfs.CAT)
|
||||
m.Option(nfs.DIR_REG, m.Conf(cmd, "meta.regs"))
|
||||
m.Cmdy(nfs.DIR, kit.Select("./", arg, 0), "time,size,path")
|
||||
return true
|
||||
|
1
exec.go
1
exec.go
@ -52,6 +52,7 @@ func (m *Message) Assert(arg interface{}) bool {
|
||||
panic(errors.New(fmt.Sprintf("error: %v", arg)))
|
||||
}
|
||||
func (m *Message) Sleep(arg string) *Message {
|
||||
m.Debug("sleep %s %s", arg, kit.FileLine(2, 3))
|
||||
time.Sleep(kit.Duration(arg))
|
||||
return m
|
||||
}
|
||||
|
11
misc.go
11
misc.go
@ -117,6 +117,9 @@ func _render(m *Message, cmd string, args ...interface{}) string {
|
||||
|
||||
switch arg := kit.Simple(args...); cmd {
|
||||
case RENDER_DOWNLOAD: // [name] file
|
||||
if arg[0] == "" {
|
||||
return ""
|
||||
}
|
||||
if len(arg) == 1 {
|
||||
arg[0] = kit.MergeURL2(m.Option(MSG_USERWEB), path.Join(kit.Select("", "/share/local",
|
||||
!strings.HasPrefix(arg[0], "/")), arg[0]), kit.SSH_POD, m.Option(MSG_USERPOD))
|
||||
@ -176,8 +179,8 @@ func _render(m *Message, cmd string, args ...interface{}) string {
|
||||
func (m *Message) PushRender(key, view, name string, arg ...string) *Message {
|
||||
return m.Push(key, _render(m, view, name, arg))
|
||||
}
|
||||
func (m *Message) PushDownload(arg ...interface{}) { // [name] file
|
||||
m.Push(kit.MDB_LINK, _render(m, RENDER_DOWNLOAD, arg...))
|
||||
func (m *Message) PushDownload(key string, arg ...interface{}) { // [name] file
|
||||
m.Push(key, _render(m, RENDER_DOWNLOAD, arg...))
|
||||
}
|
||||
func (m *Message) PushAnchor(arg ...interface{}) { // [name] link
|
||||
m.Push(kit.MDB_LINK, _render(m, RENDER_ANCHOR, arg...))
|
||||
@ -226,6 +229,10 @@ func (m *Message) SortStrR(key string) { m.Sort(key, "str_r") }
|
||||
func (m *Message) SortTime(key string) { m.Sort(key, "time") }
|
||||
func (m *Message) SortTimeR(key string) { m.Sort(key, "time_r") }
|
||||
|
||||
func (m *Message) Process(action string, arg ...interface{}) {
|
||||
m.Option(MSG_PROCESS, action)
|
||||
m.Option("_arg", arg...)
|
||||
}
|
||||
func (m *Message) FormatMeta() string { return m.Format("meta") }
|
||||
func (m *Message) RenameAppend(from, to string) {
|
||||
for i, v := range m.meta[MSG_APPEND] {
|
||||
|
@ -30,7 +30,7 @@ func _input_list(m *ice.Message, lib string) {
|
||||
}
|
||||
|
||||
m.Option(nfs.DIR_DEEP, true)
|
||||
m.Option(nfs.DIR_TYPE, nfs.FILE)
|
||||
m.Option(nfs.DIR_TYPE, nfs.CAT)
|
||||
m.Richs(INPUT, "", lib, func(key string, value map[string]interface{}) {
|
||||
m.Cmdy(nfs.DIR, kit.Value(value, "meta.store"), "time size line path")
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user