From 9f92209b895c085544b53006a411a4cbc39fc2e7 Mon Sep 17 00:00:00 2001 From: shaoying Date: Fri, 21 Aug 2020 21:30:33 +0800 Subject: [PATCH] opt tcp.port --- base/cli/python.go | 27 +++++++++++++++++++++++---- base/tcp/tcp.go | 14 +++++++++++++- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/base/cli/python.go b/base/cli/python.go index 00dc0534..2f63d996 100644 --- a/base/cli/python.go +++ b/base/cli/python.go @@ -1,8 +1,12 @@ package cli import ( - "github.com/shylinux/icebergs" - "github.com/shylinux/toolkits" + "path" + "runtime" + "strings" + + ice "github.com/shylinux/icebergs" + kit "github.com/shylinux/toolkits" ) const PYTHON = "python" @@ -11,12 +15,27 @@ func init() { Index.Merge(&ice.Context{ Configs: map[string]*ice.Config{ PYTHON: {Name: "python", Help: "脚本命令", Value: kit.Data( - PYTHON, "python", "pip", "pip", + "windows", "http://mirrors.sohu.com/python/3.5.2/Python-3.5.2.tar.xz", + "darwin", "http://mirrors.sohu.com/python/3.5.2/Python-3.5.2.tar.xz", + "linux", "http://mirrors.sohu.com/python/3.5.2/Python-3.5.2.tar.xz", + "qrcode", `import pyqrcode; print(pyqrcode.create('%s').terminal(module_color='%s', quiet_zone=1))`, + PYTHON, "python", "pip", "pip", )}, }, Commands: map[string]*ice.Command{ - PYTHON: {Name: "python cmd arg...", Help: "脚本命令", Action: map[string]*ice.Action{ + PYTHON: {Name: "python 编译:button 下载:button", Help: "脚本命令", Action: map[string]*ice.Action{ + "download": {Name: "download", Help: "下载", Hand: func(m *ice.Message, arg ...string) { + m.Cmdy("web.code.install", "download", m.Conf(PYTHON, kit.Keys(kit.MDB_META, runtime.GOOS))) + }}, + "compile": {Name: "compile", Help: "编译", Hand: func(m *ice.Message, arg ...string) { + name := path.Base(strings.TrimSuffix(strings.TrimSuffix(m.Conf(PYTHON, kit.Keys(kit.MDB_META, runtime.GOOS)), ".tar.xz"), "zip")) + m.Option(CMD_DIR, path.Join(m.Conf("web.code.install", kit.META_PATH), name)) + m.Cmdy(SYSTEM, "./configure", "--prefix="+kit.Path("usr/local")) + m.Cmdy(SYSTEM, "make", "-j8") + m.Cmdy(SYSTEM, "make", "install") + }}, + "install": {Name: "install arg...", Help: "安装", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(SYSTEM, m.Conf(PYTHON, "meta.pip"), "install", arg) }}, diff --git a/base/tcp/tcp.go b/base/tcp/tcp.go index e6df76ce..70e868ca 100644 --- a/base/tcp/tcp.go +++ b/base/tcp/tcp.go @@ -1,6 +1,9 @@ package tcp import ( + "os" + "path" + ice "github.com/shylinux/icebergs" "github.com/shylinux/icebergs/base/aaa" "github.com/shylinux/icebergs/base/cli" @@ -112,7 +115,16 @@ var Index = &ice.Context{Name: "tcp", Help: "通信模块", m.Echo(_port_get(m, "")) }}, "select": {Name: "select [begin]", Help: "分配端口", Hand: func(m *ice.Message, arg ...string) { - m.Echo(_port_get(m, kit.Select("", arg, 0))) + port, p := kit.Select("", arg, 0), "" + for { + port = _port_get(m, port) + p = path.Join(m.Conf(cli.DAEMON, kit.META_PATH), port) + if _, e := os.Stat(p); e != nil && os.IsNotExist(e) { + break + } + port = kit.Format(kit.Int(port) + 1) + } + m.Echo(port) }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { _port_list(m)