示例#1
0
文件: puzzlec.go 项目: shaalx/gooj
// @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)
}
示例#2
0
文件: judgec.go 项目: shaalx/gooj
// @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()))
}