Ejemplo n.º 1
0
Archivo: main.go Proyecto: shaalx/g
func main() {
	flag.Parse()
	cmd := exc.NewCMD("git status").Debug()
	if gs {
		cmd.Execute()
		return
	}
	if gb {
		cmd.Reset("go build").Execute()
		return
	}
	if gi {
		cmd.Reset("go install").Execute()
		return
	}
	if gt {
		cmd.Reset("go test -v").Execute()
		return
	}
	if len(gm) > 0 {
		_, err := cmd.Reset("git add -A").DoNoTime()
		if nil != err {
			return
		}
		cmd.Reset(fmt.Sprintf("git commit -m %s", gm)).Execute()
		return
	}
	cmd.Reset(fmt.Sprintf("go run %s", gr)).Execute()
}
Ejemplo n.º 2
0
func main() {
	flag.Parse()
	var input, user, repo, branch, input_1 /*,target*/ string
	tips := "[user/]repo[:branch]  > $"

	fmt.Print(tips)
	fmt.Scanf("%s", &input)

	start := time.Now()
	if strings.Contains(input, "/") {
		inputs := strings.Split(input, "/")
		user = inputs[0]
		input_1 = inputs[1]
	} else if len(input) <= 0 {
		exc.NewCMD("git pull").Debug().Execute()
		return
	} else {
		pwd, _ := os.Getwd()
		user = filepath.Base(pwd)
		input_1 = input
	}

	if strings.Contains(input_1, ":") {
		input_1s := strings.Split(input_1, ":")
		repo = input_1s[0]
		branch = input_1s[1]
	} else {
		repo = input_1
		branch = "master"
	}
	fmt.Printf("%s/%s:%s\n", user, repo, branch)
	codeload_uri := ""
	if !read {
		codeload_uri = fmt.Sprintf("git clone --progress --depth 1 [email protected]:%s/%s.git", user, repo)
	} else {
		codeload_uri = fmt.Sprintf("git clone --progress --depth 1 git://github.com/%s/%s", user, repo)
	}
	GOPATH := os.Getenv("GOPATH")
	target := filepath.Join(GOPATH, "src", "github.com", user, repo)
	os.MkdirAll(target, 0777)
	cmd := exc.NewCMD(codeload_uri).Env("GOPATH").Cd("src/github.com/").Cd(user).Wd().Debug().Execute()
	if install {
		cmd.Cd(repo).Wd().Reset("go install").Execute()
	}

	fmt.Printf("cost time:%v\n", time.Now().Sub(start))
}
Ejemplo n.º 3
0
func main() {
	flag.Parse()
	first := "git add -A"
	var git *exc.CMD
	git = exc.NewCMD(first).Wd().Debug()
	var err error
	if status {
		git.Reset("git status").Execute()
		return
	}
	if quit {
		git.Reset(fmt.Sprintf("git push %s %s:%s", remote, branch, remote_branch)).Execute()
		goto TAG
	}
	if len(only_commit) > 0 {
		fmt.Println("only_commit", only_commit)
		only_commit = fmt.Sprintf(`git commit -m %s`, only_commit)
		_ = git.Reset(only_commit).Execute()
		return
	}
	_ = git.Execute()
	if len(commit) > 0 {
		commit = fmt.Sprintf(`git commit -m %s`, commit)
	} else {
		if len(tag) > 0 {
			commit = fmt.Sprintf("git commit -m %s", tag)
		} else {
			commit = `git commit -m auto`
		}
	}
	_ = git.Reset(commit).Execute()
	git.Reset(fmt.Sprintf("git push %s %s:%s", remote, branch, remote_branch)).Execute()

TAG:
	if len(tag) > 0 {
		_, err = git.Reset(fmt.Sprintf("git tag -a %s -m %s", tag, tag)).DoNoTime()
		if checkerr(err) {
			return
		}
		git.Reset(fmt.Sprintf("git push %s --tag %s:%s", remote, tag, tag)).Execute()
		fmt.Println("ignore_dlt_tag:", ignore_dlt_tag)
		if ignore_dlt_tag {
			return
		}

		fmt.Printf("%d seconds later...\n", 25)
		git.Reset(fmt.Sprintf("git tag -d %s", tag)).ExecuteAfter(25)
		git.Reset(fmt.Sprintf("git push %s --tag :%s", remote, tag)).Execute()
	}
}
Ejemplo n.º 4
0
func init() {
	update = make(chan bool, 10)
	hacker, _ = template.New("hacker.html").ParseFiles("hacker.html")
	t, _ = template.New("bookmark.html").ParseFiles("bookmark.html")
	markdown_edit_tpl, _ = template.New("markdown_edit.html").ParseFiles("markdown_edit.html")
	b := readFile("bookmark.md")
	// b := get("http://7xku3c.com1.z0.glb.clouddn.com/bookmark.md")
	v = unmarshal(b)
	cache = lfu2.NewLFUCache(len(v) / 2)
	for i := len(v) - 1; i >= 0; i-- {
		cache.Set(v[i].Title, v[i])
	}
	update <- true
	OA = NewOAGithub("8ba2991113e68b4805c1", "b551e8a640d53904d82f95ae0d84915ba4dc0571", "user", "http://bookmark.daoapp.io/callback")
	command = exc.NewCMD("go version").Debug()
}
Ejemplo n.º 5
0
func main() {
	flag.Parse()
	var input, user, repo, branch, input_1, target string
	tips := "[user/]repo[:branch]  > $"
	fmt.Print(tips)
	fmt.Scanf("%s", &input)

	start := time.Now()
	if strings.Contains(input, "/") {
		inputs := strings.Split(input, "/")
		user = inputs[0]
		input_1 = inputs[1]
	} else {
		pwd, _ := os.Getwd()
		user = filepath.Base(pwd)
		input_1 = input
	}

	if strings.Contains(input_1, ":") {
		input_1s := strings.Split(input_1, ":")
		repo = input_1s[0]
		branch = input_1s[1]
	} else {
		repo = input_1
		branch = "master"
	}
	fmt.Printf("%s/%s:%s\n", user, repo, branch)
	codeload_uri := fmt.Sprintf("https://codeload.github.com/%s/%s/zip/%s", user, repo, branch)
	resp, err := http.Get(codeload_uri)
	if goutils.CheckErr(err) {
		panic(fmt.Sprintf("GET:%s ERROR:%v\n", codeload_uri, err))
	}
	if resp == nil {
		panic("nil")
	}

	GOPATH := os.Getenv("GOPATH")
	target = filepath.Join(GOPATH, "src", "github.com", user, repo)
	unzip.UnzipReader(resp.Body, target)

	// os.MkdirAll(target, 0777)
	cmd := exc.NewCMD(codeload_uri).Env("GOPATH").Cd("src/github.com/").Cd(user).Wd().Debug().Execute()
	if install {
		cmd.Cd(repo).Wd().Reset("go install").Execute()
	}
	fmt.Printf("cost time:%v\n", time.Now().Sub(start))
}
Ejemplo n.º 6
0
func init() {
	var err error
	// if lis, err = rpcsv.RPCServe("88"); err != nil {
	// 	return
	// }
	exc_cmd = exc.NewCMD("ls").Debug()
	// rpc_client = rpcsv.RPCClient("127.0.0.1:88")
	rpc_client = rpcsv.RPCClient("tcphub.t0.daoapp.io:61142")
	if rpc_client == nil {
		// lis.Close()
		panic("rpc_client is nil!")
	}
	tpl, err = template.ParseFiles("theme.thm")
	if goutils.CheckErr(err) {
		panic("theme error")
	}
}
Ejemplo n.º 7
0
func (c *CodeURI) curl() bool {
	uri := c.URI()
	curl_command := fmt.Sprintf("curl %s\n", uri)
	b, err := exc.NewCMD(curl_command).Do()
	if !exc.Checkerr(err) {
		f, err := os.OpenFile(fmt.Sprintf("%s.zip", c.Branch), os.O_WRONLY|os.O_CREATE, 0644)
		defer f.Close()
		if checkerr(err) {
			return false
		}
		src := bytes.NewReader(b)
		_, err = io.Copy(f, src)
		if !checkerr(err) {
			return true
		}
	}
	return false
}
Ejemplo n.º 8
0
func (c *CodeURI) Unzip() bool {
	unzip_command := fmt.Sprintf("unzip %s.zip", c.Branch)
	cmd := exc.NewCMD(unzip_command)
	_, err := cmd.Debug().Do()
	if !exc.Checkerr(err) {
		rename_command := fmt.Sprintf("mv %s %s", c.UnzipName(), c.Repo)
		_, err = os.Stat(c.Repo)
		if nil == err {
			err = os.RemoveAll(c.Repo)
			checkerr(err)
		}
		_, renamed := cmd.Reset(rename_command).Do()
		if !exc.Checkerr(renamed) {
			zipfile := fmt.Sprintf("%s.zip", c.Branch)
			removed := os.Remove(zipfile)
			if !checkerr(removed) {
				return false
			}
			return true
		}
	}
	return false
}
Ejemplo n.º 9
0
// @router /test [post]
func (c *PuzzleController) Test() {
	submit_LOCKER.Lock()
	defer submit_LOCKER.Unlock()
	var model model_util.Model
	model.Id = "1"
	model.Desc = c.GetString("descr")
	model.Title = c.GetString("title")
	model.FuncName = c.GetString("func_name")
	model.ArgsType = c.GetString("args_type")
	model.Content = c.GetString("content")
	model.RetsType = c.GetString("rets_type")
	model.TestCases = c.GetString("test_cases")
	/*if len(model.FuncName) <= 0 {
		c.Abort("403")
		return
	}*/
	fmt.Printf("%#v\n", model)
	path_ := strings.Split(c.Ctx.Request.RemoteAddr, ":")[1]
	if len(path_) < 1 {
		path_ = "goojt"
	}
	beego.Debug("path_:", path_)
	err := model_util.GenerateOjModle(path_, &model)
	if goutils.CheckErr(err) {
		/*c.Ctx.ResponseWriter.Write(goutils.ToByte(err.Error()))
		return*/
	}
	cmd := exc.NewCMD("go test -v")
	ret, err := cmd.Wd().Cd(path_).Debug().Do()
	if goutils.CheckErr(err) {
		/*c.Ctx.ResponseWriter.Write(goutils.ToByte(err.Error()))
		return*/
	}
	c.Ctx.ResponseWriter.Write(ret)
	fmt.Println(goutils.ToString(ret))
	go cmd.Reset(fmt.Sprintf("rm -rf %s", path_)).Cd(defaultpath).ExecuteAfter(1)
}
Ejemplo n.º 10
0
func init() {
	installInfo = make(chan *Info, 50)
	command = exc.NewCMD("go version").Debug()
	wd, _ = os.Getwd()
}
Ejemplo n.º 11
0
Archivo: main.go Proyecto: shaalx/push
func screen() {
	cmd := exc.NewCMD("xwd -root -out screen.xwd").Debug()
	cmd.ExecuteAfter(5)
	cmd.Reset("convert screen.xwd screen.png").Execute()
}
Ejemplo n.º 12
0
	"github.com/everfore/rpcsv"
	"github.com/satori/go.uuid"
	"io/ioutil"
	"net/http"
	"net/rpc"
	"os"
	"path"
	"path/filepath"
	"strings"
)

var (
	forbidden_dir = ".forbidden"
	volumn        = "/usr/static/upload/"
	// volumn = "./static/"
	excm = exc.NewCMD("ls")

	RPC_Client *rpc.Client
	// rpc_tcp_server = "127.0.0.1:8800"
	// os.Getenv("RPCHUB")
	rpc_tcp_server = "rpchub.t0.daoapp.io:61142"
)

func connect() *rpc.Client {
	return rpcsv.RPCClient(rpc_tcp_server)
}

// 是否重新开始循环
func checkNilThenReLoop(clt *rpc.Client, reconnect bool) (bool, *rpc.Client) {
	if clt == nil || reconnect {
		clt = rpcsv.RPCClient(rpc_tcp_server)
Ejemplo n.º 13
0
// @router /oj/:id:int [post]
func (c *ListController) OJ() {
	var id int
	c.Ctx.Input.Bind(&id, ":id")
	if ojCheck(id) <= 0 {
		c.Data["Content"] = template.HTML("<h3>题目还未审核,如有问题,请联系管理员。</h3>")
		c.TplName = "sorry.html"
		return
	}
	fid := c.GetString("fid")
	path_ := c.GetString("rid")
	content := c.GetString("puzzle")
	if strings.Contains(content, `"os`) {
		c.Ctx.ResponseWriter.Write(goutils.ToByte("呵呵"))
		return
	}
	beego.Debug(content, path_, fid)

	// inser into db
	slt := models.Solution{}
	cur := c.SessionController.CurUser()
	if cur != nil {
		slt.User = &models.User{Id: cur.Id} //models.UserById(cur.Id)
	} else {
		slt.User = models.UserByName("Anonymous")
	}
	slt.Content = content
	// slt.Create = *goutils.LocNow("Asia/Shanghai")
	// fmt.Println(slt)
	ffid, _ := c.GetInt("fid")
	slt.Puzzle = &models.Puzzle{Id: ffid}
	n, dberr := models.ORM.Insert(&slt)
	if goutils.CheckErr(dberr) {

	}
	// insert into db

	submit_LOCKER.Lock()
	defer submit_LOCKER.Unlock()
	cmd := exc.NewCMD("go test -v").Cd(defaultpath)

	var puzzle models.Puzzle
	models.ORM.QueryTable((*models.Puzzle)(nil)).Filter("Id", id).One(&puzzle)
	m := Puzzle2Model(&puzzle)

	m.Content = content
	beego.Info(m)
	err := model_util.GenerateOjModle(path_, m)
	goutils.CheckErr(err)
	submitID++
	test_result, err := cmd.Wd().Cd(path_).Debug().Do()
	analyse_result := utils.Analyse(goutils.ToString(test_result))
	fmt.Println(analyse_result)
	goutils.CheckErr(err)
	if n > 0 {
		result := models.AnalyseResultParse(analyse_result)
		m, err := models.ORM.Insert(result)
		if !goutils.CheckErr(err) {
			result.Id = int(m)
		}
		slt.Result = result
		slt.Id = int(n)
		go func() {
			models.ORM.Update(&slt)
		}()
	}

	go cmd.Reset(fmt.Sprintf("rm -rf %s", path_)).Cd(defaultpath).Execute()

	c.Ctx.ResponseWriter.Write(goutils.ToByte(analyse_result.String()))
}