Show More
Commit Description:
[grader] added check_wrapper...
Commit Description:
[grader] added check_wrapper git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@111 6386c4cd-e34a-4fa8-8920-d93eb39b512e
File last commit:
Show/Diff file:
Action:
import_problem | 135 lines | 3.8 KiB | text/plain | TextLexer |
jittat
import original files...
r0 #!/usr/bin/ruby
# import_problem:
# * creates a directory for a problem in the current directory,
# * copy testdata in the old format and create standard testcase config file
require 'erb'
jittat
[grader] [MERGED] Merged new-arch-branch changes 74:105 into the trunk...
r23 require 'fileutils'
jittat
import original files...
r0
def input_filename(dir,i)
"#{dir}/input-#{i}.txt"
end
def answer_filename(dir,i)
"#{dir}/answer-#{i}.txt"
end
def copy_testcase(importing_test_dir,dir,i)
system("cp #{importing_test_dir}/#{i}.in #{input_filename(dir,i)}")
system("cp #{importing_test_dir}/#{i}.sol #{answer_filename(dir,i)}")
end
def process_options(options)
jittat
[grader] fix an option bug for import_problem...
r27 i = 4
jittat
import original files...
r0 while i<ARGV.length
if ARGV[i]=='-t'
options[:time_limit] = ARGV[i+1].to_i if ARGV.length>i+1
i += 1
end
if ARGV[i]=='-m'
options[:mem_limit] = ARGV[i+1].to_i if ARGV.length>i+1
i += 1
end
i += 1
end
end
jittat
[grader] [MERGED] Merged new-arch-branch changes 74:105 into the trunk...
r23 SCRIPT_DIR = File.dirname(__FILE__)
jittat
import original files...
r0
# print usage
jittat
[grader] fix an option bug for import_problem...
r27 if (ARGV.length < 4) or (ARGV[3][0,1]=="-")
jittat
[grader] [MERGED] Merged new-arch-branch changes 74:105 into the trunk...
r23 puts <<USAGE
jittat
[grader] update import_problem script, so that it requires check script....
r26 using: import_problem name dir num check [options]
where: name = problem_name [
dir = importing testcase directory
num = number of testcases
check = check script, which can be
integer, text (for standard script),
or a path to a file
options: -t time-limit (in seconds)
-m memory-limit (in megabytes)
What it does:
jittat
add description to import_problem...
r15 * creates a directory for a problem in the current directory,
jittat
[grader] update import_problem script, so that it requires check script....
r26 * copies testdata in the old format and create standard testcase config file
* copies a check script for grading
jittat
[grader] [MERGED] Merged new-arch-branch changes 74:105 into the trunk...
r23 * creates a test_request template in the current directory + '/test_request'
USAGE
jittat
import original files...
r0 exit(127)
end
# processing arguments
problem = ARGV[0]
testcase_dir = ARGV[1]
num_testcases = ARGV[2].to_i
jittat
[grader] update import_problem script, so that it requires check script....
r26 check_script = ARGV[3]
jittat
import original files...
r0 options = {:time_limit => 1, :mem_limit => 16}
process_options(options)
# start working
puts "creating directories"
system("mkdir #{problem}")
system("mkdir #{problem}/script")
system("mkdir #{problem}/test_cases")
jittat
add: grader copies std script...
r11 #system("cp #{GRADER_DIR}/std-script/* #{problem}/script")
jittat
import original files...
r0
puts "copying testcases"
1.upto(num_testcases) do |i|
system("mkdir #{problem}/test_cases/#{i}")
copy_testcase("#{testcase_dir}","#{problem}/test_cases/#{i}",i)
end
# generating all_tests.cfg
puts "generating testcase config file"
jittat
[grader] [MERGED] Merged new-arch-branch changes 74:105 into the trunk...
r23 template = File.open(SCRIPT_DIR + "/templates/all_tests.cfg.erb").read
jittat
import original files...
r0 all_test_cfg = ERB.new(template)
jittat
fix bugs: paths, check compilation error, all_tests.cfg.erb...
r3 cfg_file = File.open("#{problem}/test_cases/all_tests.cfg","w")
jittat
import original files...
r0 cfg_file.puts all_test_cfg.result
cfg_file.close
jittat
[grader] update import_problem script, so that it requires check script....
r26
# copy check script
jittat
[grader] added check_wrapper...
r28 if res = /^wrapper:(.*)$/.match(check_script)
# wrapper script
check_script_fname = res[1]
script_name = File.basename(check_script_fname)
check_wrapper_template = File.open(SCRIPT_DIR + "/templates/check_wrapper")
check_wrapper = ERB.new(template)
check_file = File.open("#{problem}/script/check","w")
check_file.puts check_wrapper
check_file.close
File.chmod(0755,"#{problem}/script/check")
system("cp #{check_script_fname} #{problem}/script/#{script_name}")
jittat
[grader] update import_problem script, so that it requires check script....
r26 else
jittat
[grader] added check_wrapper...
r28 if File.exists?(SCRIPT_DIR + "/templates/check.#{check_script}")
check_script_fname = SCRIPT_DIR + "/templates/check.#{check_script}"
else
check_script_fname = check_script
end
system("cp #{check_script_fname} #{problem}/script/check")
jittat
[grader] update import_problem script, so that it requires check script....
r26 end
jittat
[grader] [MERGED] Merged new-arch-branch changes 74:105 into the trunk...
r23 # generating test_request directory
puts "generating test_request template"
FileUtils.mkdir_p("test_request/#{problem}/script")
FileUtils.mkdir_p("test_request/#{problem}/test_cases/1")
template = File.open(SCRIPT_DIR + "/templates/test_request_all_tests.cfg.erb").read
test_request_all_test_cfg = ERB.new(template)
cfg_file = File.open("test_request/#{problem}/test_cases/all_tests.cfg","w")
cfg_file.puts test_request_all_test_cfg.result
cfg_file.close
system("cp #{SCRIPT_DIR}/templates/check_empty test_request/#{problem}/script/check")
system("cp #{SCRIPT_DIR}/templates/answer-1.txt test_request/#{problem}/test_cases/1")
jittat
import original files...
r0 puts "done"