diff --git a/lib/grader_script.rb b/lib/grader_script.rb --- a/lib/grader_script.rb +++ b/lib/grader_script.rb @@ -1,35 +1,58 @@ module GraderScript def self.grader_control_enabled? - if defined? GRADER_SCRIPT_DIR - GRADER_SCRIPT_DIR != '' + if defined? GRADER_ROOT_DIR + GRADER_ROOT_DIR != '' else false end end - def self.stop_grader(pid) + def self.raw_dir + File.join GRADER_ROOT_DIR, "raw" + end + + def self.call_grader(params) if GraderScript.grader_control_enabled? - cmd = "#{GRADER_SCRIPT_DIR}/grader stop #{pid}" + cmd = File.join(GRADER_ROOT_DIR, "scripts/grader") + " " + params system(cmd) end end + def self.stop_grader(pid) + GraderScript.call_grader "stop #{pid}" + end + def self.stop_graders(pids) - if GraderScript.grader_control_enabled? - pid_str = (pids.map { |process| process.pid.to_a }).join ' ' - cmd = "#{GRADER_SCRIPT_DIR}/grader stop " + pid_str - system(cmd) - end + pid_str = (pids.map { |process| process.pid.to_a }).join ' ' + GraderScript.call_grader "stop #{pid_str}" end def self.start_grader(env) + GraderScript.call_grader "#{env} queue &" + GraderScript.call_grader "#{env} test_request &" + end + + def self.call_import_problem(problem_name, + problem_dir, + time_limit=1, + memory_limit=32, + checker_name='text') if GraderScript.grader_control_enabled? - cmd = "#{GRADER_SCRIPT_DIR}/grader #{env} queue &" - system(cmd) - cmd = "#{GRADER_SCRIPT_DIR}/grader #{env} test_request &" - system(cmd) - end + cur_dir = `pwd`.chomp + Dir.chdir(GRADER_ROOT_DIR) + + script_name = File.join(GRADER_ROOT_DIR, "scripts/import_problem") + cmd = "#{script_name} #{problem_name} #{problem_dir} #{checker_name}" + + " -t #{time_limit} -m #{memory_limit}" + + output = `#{cmd}` + + Dir.chdir(cur_dir) + + return output + end + return '' end end