Show More
Commit Description:
updated runner_spec...
Commit Description:
updated runner_spec
git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@418 6386c4cd-e34a-4fa8-8920-d93eb39b512e
References:
File last commit:
Show/Diff file:
Action:
import_problem
| 164 lines
| 4.7 KiB
| text/plain
| TextLexer
|
|
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' | ||||
|
r23 | require 'fileutils' | ||
|
r63 | require File.join(File.dirname(__FILE__),'lib/import_helper') | ||
|
r0 | |||
def input_filename(dir,i) | ||||
"#{dir}/input-#{i}.txt" | ||||
end | ||||
def answer_filename(dir,i) | ||||
"#{dir}/answer-#{i}.txt" | ||||
end | ||||
|
r63 | def build_testrun_info_from_dir(num_testruns,importing_test_dir) | ||
filenames = Dir["#{importing_test_dir}/*.in"].collect do |filename| | ||||
File.basename((/(.*)\.in/.match(filename))[1]) | ||||
end | ||||
build_testrun_info(num_testruns,filenames) | ||||
end | ||||
def copy_testcase(importing_test_dir,fname,dir,i) | ||||
system("cp #{importing_test_dir}/#{fname}.in #{input_filename(dir,i)}") | ||||
system("cp #{importing_test_dir}/#{fname}.sol #{answer_filename(dir,i)}") | ||||
|
r0 | end | ||
def process_options(options) | ||||
|
r27 | i = 4 | ||
|
r0 | while i<ARGV.length | ||
if ARGV[i]=='-t' | ||||
|
r52 | options[:time_limit] = ARGV[i+1].to_f if ARGV.length>i+1 | ||
|
r0 | 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 | ||||
|
r23 | SCRIPT_DIR = File.dirname(__FILE__) | ||
|
r0 | |||
# print usage | ||||
|
r27 | if (ARGV.length < 4) or (ARGV[3][0,1]=="-") | ||
|
r23 | puts <<USAGE | ||
|
r26 | using: import_problem name dir num check [options] | ||
|
r47 | where: name = problem_name (put '-' (dash) to use dir name) | ||
|
r26 | dir = importing testcase directory | ||
|
r63 | num = number of testruns | ||
|
r26 | check = check script, which can be | ||
|
r29 | 'integer', 'text' (for standard script), | ||
path_to_your_script, or | ||||
'wrapper:(path_to_your_wrapped_script)' | ||||
|
r26 | options: -t time-limit (in seconds) | ||
-m memory-limit (in megabytes) | ||||
What it does: | ||||
|
r15 | * creates a directory for a problem in the current directory, | ||
|
r26 | * copies testdata in the old format and create standard testcase config file | ||
* copies a check script for grading | ||||
|
r23 | * creates a test_request template in the current directory + '/test_request' | ||
|
r29 | |||
For wrapped checked script see comment in templates/check_wrapper for | ||||
information. | ||||
|
r23 | USAGE | ||
|
r0 | exit(127) | ||
end | ||||
# processing arguments | ||||
problem = ARGV[0] | ||||
testcase_dir = ARGV[1] | ||||
|
r47 | problem = File.basename(testcase_dir) if problem=="-" | ||
|
r63 | num_testruns = ARGV[2].to_i | ||
|
r26 | check_script = ARGV[3] | ||
|
r0 | options = {:time_limit => 1, :mem_limit => 16} | ||
process_options(options) | ||||
|
r63 | testrun_info = build_testrun_info_from_dir(num_testruns, testcase_dir) | ||
|
r0 | # start working | ||
puts "creating directories" | ||||
system("mkdir #{problem}") | ||||
system("mkdir #{problem}/script") | ||||
system("mkdir #{problem}/test_cases") | ||||
|
r11 | #system("cp #{GRADER_DIR}/std-script/* #{problem}/script") | ||
|
r0 | |||
puts "copying testcases" | ||||
|
r63 | tr_num = 0 | ||
num_testcases = 0 | ||||
testrun_info.each do |testrun| | ||||
tr_num += 1 | ||||
puts "testrun: #{tr_num}" | ||||
testrun.each do |testcase_info| | ||||
testcase_num, testcase_fname = testcase_info | ||||
puts "copy #{testcase_fname} to #{testcase_num}" | ||||
system("mkdir #{problem}/test_cases/#{testcase_num}") | ||||
copy_testcase("#{testcase_dir}",testcase_fname,"#{problem}/test_cases/#{testcase_num}",testcase_num) | ||||
num_testcases += 1 | ||||
end | ||||
|
r0 | end | ||
# generating all_tests.cfg | ||||
puts "generating testcase config file" | ||||
|
r23 | template = File.open(SCRIPT_DIR + "/templates/all_tests.cfg.erb").read | ||
|
r0 | all_test_cfg = ERB.new(template) | ||
|
r3 | cfg_file = File.open("#{problem}/test_cases/all_tests.cfg","w") | ||
|
r0 | cfg_file.puts all_test_cfg.result | ||
cfg_file.close | ||||
|
r26 | |||
# copy check script | ||||
|
r28 | if res = /^wrapper:(.*)$/.match(check_script) | ||
# wrapper script | ||||
check_script_fname = res[1] | ||||
script_name = File.basename(check_script_fname) | ||||
|
r31 | check_wrapper_template = File.open(SCRIPT_DIR + "/templates/check_wrapper").read | ||
check_wrapper = ERB.new(check_wrapper_template) | ||||
|
r28 | |||
check_file = File.open("#{problem}/script/check","w") | ||||
|
r31 | check_file.puts check_wrapper.result | ||
|
r28 | check_file.close | ||
File.chmod(0755,"#{problem}/script/check") | ||||
system("cp #{check_script_fname} #{problem}/script/#{script_name}") | ||||
|
r26 | else | ||
|
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") | ||||
|
r26 | end | ||
|
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") | ||||
|
r0 | puts "done" | ||