Ejemplo n.º 1
0
func (z *ZJGSUJudger) Submit(user vjudger.UserInterface) error {
	z.compile(user)

	if user.GetResult() != config.JudgeCE {
		user.SetResult(config.JudgeRJ)
		logger.Println("compile success")
		user.UpdateSolution()

		cmd := exec.Command("cp", "-r", dataPath+"/"+strconv.Itoa(user.GetVid()), runPath+"/"+strconv.Itoa(user.GetSid()))
		err := cmd.Run()
		if err != nil {
			log.Println(err)
		}
	} else {
		b, err := ioutil.ReadFile(z.workdir + "/ce.txt")
		if err != nil {
			log.Println(err)
		}

		log.Println(string(b))
		user.SetErrorInfo(string(b))
		logger.Println("compiler error")
		log.Println("compiler error")

		return ErrCompile
	}
	return nil
}
Ejemplo n.º 2
0
func (z *ZJGSUJudger) Run(u vjudger.UserInterface) error {
	defer os.RemoveAll(runPath + "/" + strconv.Itoa(u.GetSid()))
	u.SetResult(config.JudgePD)
	for _, apply := range []func(vjudger.UserInterface) error{z.Init, z.Login, z.Submit, z.GetStatus} {
		if err := apply(u); err != nil {
			logger.Println(err)
			return err
		}
	}
	return nil
}
Ejemplo n.º 3
0
func (z *ZJGSUJudger) compile(user vjudger.UserInterface) {
	cmd := exec.Command("compiler", strconv.Itoa(user.GetLang()), z.workdir)
	err := cmd.Run()
	if err != nil {
		log.Println(err)
	}

	if cmd.ProcessState.String() != "exit status 0" {
		log.Println(cmd.ProcessState.String())
		user.SetResult(config.JudgeCE) //compiler error
	}
}
Ejemplo n.º 4
0
func (z *ZJGSUJudger) GetStatus(user vjudger.UserInterface) error {
	logger.Println("run solution")

	var out bytes.Buffer
	cmd := exec.Command("runner", strconv.Itoa(user.GetLang()), strconv.Itoa(z.time), strconv.Itoa(z.mem), z.workdir)
	cmd.Stdout = &out
	cmd.Run()

	sp := strings.Split(out.String(), " ")
	var err error
	Result, err := strconv.Atoi(sp[0])

	if err != nil {
		logger.Println(err)
		logger.Println(Result)
	}
	user.SetResult(Result)
	Time, _ := strconv.Atoi(sp[1])
	Mem, _ := strconv.Atoi(sp[2])
	Mem = Mem / 1024 //b->Kb
	user.SetResource(Time, Mem, len(user.GetCode()))
	return nil
}