Show More
Commit Description:
fix bux when pid=0
Commit Description:
fix bux when pid=0
References:
File last commit:
Show/Diff file:
Action:
lib/engine.rb | 190 lines | 4.9 KiB | text/x-ruby | RubyLexer |
jittat
[grader] [MERGED] Merged new-arch-branch changes 74:105 into the trunk...
r23 require 'fileutils'
jittat
added rename_problem script, fixed require error for dir_init...
r78 require File.join(File.dirname(__FILE__),'dir_init')
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22
module Grader
jittat
[grader] [MERGED] Merged new-arch-branch changes 74:105 into the trunk...
r23 #
# A grader engine grades a submission, against anything: a test
# data, or a user submitted test data. It uses two helpers objects:
# room_maker and reporter.
#
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22 class Engine
jittat
[grader] [MERGED] Merged new-arch-branch changes 74:105 into the trunk...
r23
attr_writer :room_maker
attr_writer :reporter
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22
Jittat Fakcharoenphol
added grading report
r92 def initialize(options={})
# default options
if not options.include? :room_maker
options[:room_maker] = Grader::SubmissionRoomMaker.new
end
if not options.include? :reporter
options[:reporter] = Grader::SubmissionReporter.new
end
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22 @config = Grader::Configuration.get_instance
jittat
[grader] [MERGED] Merged new-arch-branch changes 74:105 into the trunk...
r23
Jittat Fakcharoenphol
added grading report
r92 @room_maker = options[:room_maker]
@reporter = options[:reporter]
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22 end
jittat
[grader] [MERGED] Merged new-arch-branch changes 74:105 into the trunk...
r23
# takes a submission, asks room_maker to produce grading directories,
# calls grader scripts, and asks reporter to save the result
def grade(submission)
Jittat Fakcharoenphol
removed calls to 'pwd', other uses of back quotes
r102 current_dir = FileUtils.pwd
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22
jittat
[grader] [MERGED] Merged new-arch-branch changes 74:105 into the trunk...
r23 user = submission.user
problem = submission.problem
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22
handle the case when problem id or submission id is null. Grader will simply skip such request. Add more report on console (for command line grading)
r150 begin
# TODO: will have to create real exception for this
if user==nil or problem == nil
@reporter.report_error(submission,"Grading error: problem with submission")
raise "engine: user or problem is nil"
end
jittat
[grader] hack on language for output-only task...
r50
handle the case when problem id or submission id is null. Grader will simply skip such request. Add more report on console (for command line grading)
r150 # TODO: this is another hack so that output only task can be judged
if submission.language!=nil
language = submission.language.name
lang_ext = submission.language.ext
else
language = 'c'
lang_ext = 'c'
end
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22
handle the case when problem id or submission id is null. Grader will simply skip such request. Add more report on console (for command line grading)
r150 # This is needed because older version of std-scripts/compile
# only look for c++.
if language == 'cpp'
language = 'c++'
end
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22
handle the case when problem id or submission id is null. Grader will simply skip such request. Add more report on console (for command line grading)
r150 # COMMENT: should it be only source.ext?
if problem!=nil
source_name = "#{problem.name}.#{lang_ext}"
else
source_name = "source.#{lang_ext}"
end
jittat
[grader] [MERGED] Merged new-arch-branch changes 74:105 into the trunk...
r23 grading_dir = @room_maker.produce_grading_room(submission)
@room_maker.save_source(submission,source_name)
problem_home = @room_maker.find_problem_home(submission)
# puts "GRADING DIR: #{grading_dir}"
# puts "PROBLEM DIR: #{problem_home}"
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22
jittat
fixed: grader crashes when the problem has no test data...
r83 if !FileTest.exist?(problem_home)
fix logg() in compile, add more logging to engine.rb when the problem cannot be found
r148 puts "PROBLEM DIR: #{problem_home}"
handle the case when problem id or submission id is null. Grader will simply skip such request. Add more report on console (for command line grading)
r150 raise "engine: No test data."
jittat
fixed: grader crashes when the problem has no test data...
r83 end
jittat
MERGED changeset 380:381 from http://theory.cpe.ku.ac.th/grader/web/trunk/judge/scripts...
r71 dinit = DirInit::Manager.new(problem_home)
dinit.setup do
copy_log = copy_script(problem_home)
save_copy_log(problem_home,copy_log)
end
jittat
[grader] [MERGED] Merged new-arch-branch changes 74:105 into the trunk...
r23
call_judge(problem_home,language,grading_dir,source_name)
@reporter.report(submission,"#{grading_dir}/test-result")
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22
jittat
MERGED changeset 380:381 from http://theory.cpe.ku.ac.th/grader/web/trunk/judge/scripts...
r71 dinit.teardown do
copy_log = load_copy_log(problem_home)
clear_copy_log(problem_home)
Jittat Fakcharoenphol
removed commented dir clear scripts
r138 clear_script(copy_log,problem_home)
jittat
MERGED changeset 380:381 from http://theory.cpe.ku.ac.th/grader/web/trunk/judge/scripts...
r71 end
jittat
[grader] [MERGED] Merged new-arch-branch changes 74:105 into the trunk...
r23
rescue RuntimeError => msg
jittat
fixed: grader crashes when the problem has no test data...
r83 @reporter.report_error(submission, msg)
handle the case when problem id or submission id is null. Grader will simply skip such request. Add more report on console (for command line grading)
r150 puts "ERROR: #{msg}"
jittat
[grader] [MERGED] Merged new-arch-branch changes 74:105 into the trunk...
r23
ensure
@room_maker.clean_up(submission)
Dir.chdir(current_dir) # this is really important
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22 end
end
jittat
[grader] [MERGED] Merged new-arch-branch changes 74:105 into the trunk...
r23
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22 protected
def talk(str)
if @config.talkative
puts str
end
end
jittat
[grader] [MERGED] Merged new-arch-branch changes 74:105 into the trunk...
r23 def call_judge(problem_home,language,grading_dir,fname)
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22 ENV['PROBLEM_HOME'] = problem_home
Jittat Fakcharoenphol
removes RUBYOPT env before calling judge scripts
r139 ENV['RUBYOPT'] = ''
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22
jittat
[grader] [MERGED] Merged new-arch-branch changes 74:105 into the trunk...
r23 talk grading_dir
Dir.chdir grading_dir
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22 cmd = "#{problem_home}/script/judge #{language} #{fname}"
talk "CMD: #{cmd}"
system(cmd)
end
def get_std_script_dir
GRADER_ROOT + '/std-script'
end
def copy_script(problem_home)
script_dir = "#{problem_home}/script"
std_script_dir = get_std_script_dir
handle the case when problem id or submission id is null. Grader will simply skip such request. Add more report on console (for command line grading)
r150 raise "engine: std-script directory not found" if !FileTest.exist?(std_script_dir)
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22
scripts = Dir[std_script_dir + '/*']
copied = []
scripts.each do |s|
fname = File.basename(s)
Jittat Fakcharoenphol
locks dir based on temp file, does not copy dir when copying scripts, added proper rescue for ln_s
r103 next if FileTest.directory?(s)
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22 if !FileTest.exist?("#{script_dir}/#{fname}")
copied << fname
Jittat Fakcharoenphol
fixed grader to work with ruby 1.9
r137 FileUtils.cp(s, "#{script_dir}", :preserve => true)
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22 end
end
return copied
end
jittat
MERGED changeset 380:381 from http://theory.cpe.ku.ac.th/grader/web/trunk/judge/scripts...
r71
def copy_log_filename(problem_home)
return File.join(problem_home, '.scripts_copied')
end
def save_copy_log(problem_home, log)
f = File.new(copy_log_filename(problem_home),"w")
log.each do |fname|
f.write("#{fname}\n")
end
f.close
end
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22
jittat
MERGED changeset 380:381 from http://theory.cpe.ku.ac.th/grader/web/trunk/judge/scripts...
r71 def load_copy_log(problem_home)
f = File.new(copy_log_filename(problem_home),"r")
log = []
f.readlines.each do |line|
log << line.strip
end
f.close
log
end
def clear_copy_log(problem_home)
File.delete(copy_log_filename(problem_home))
end
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22 def clear_script(log,problem_home)
log.each do |s|
Jittat Fakcharoenphol
removed many 'system' invokations
r101 FileUtils.rm("#{problem_home}/script/#{s}")
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22 end
end
def mkdir_if_does_not_exist(dirname)
Dir.mkdir(dirname) if !FileTest.exist?(dirname)
end
end
end