Exemplo n.º 1
0
func Puzzle2Model(puzzle *models.Puzzle) *model_util.Model {
	if nil == puzzle {
		return nil
	}
	m := model_util.Model{}
	m.Id = fmt.Sprintf("%s", puzzle.Id)
	m.ArgsType = puzzle.ArgsType
	m.Content = puzzle.Content
	m.Desc = puzzle.Descr
	m.FuncName = puzzle.FuncName
	m.Online = puzzle.Online
	m.RetsType = puzzle.RetsType
	m.TestCases = puzzle.TestCases
	m.Title = puzzle.Title
	return &m
}
Exemplo n.º 2
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)
}